Attribute Terraform API requests the CLI (#1598)

## Changes
This PR adds cli to the user agent sent downstream to the databricks
terraform provider when invoked via DABs.
 
## Tests
Unit tests. Based on the comment here
(10fe02075f/bundle/config/mutator/verify_cli_version_test.go (L113))
we don't need to set the version to make the test assertion work
correctly. This is likely because we use `go test` to run the tests
while the CLI is compiled and the version is set via `goreleaser`.
This commit is contained in:
shreyas-goenka 2024-07-18 15:08:09 +05:30 committed by GitHub
parent 6d710a411a
commit c6c2692368
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/internal/tf/schema"
"github.com/databricks/cli/internal/build"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/log"
@ -219,8 +220,10 @@ func setProxyEnvVars(ctx context.Context, environ map[string]string, b *bundle.B
}
func setUserAgentExtraEnvVar(environ map[string]string, b *bundle.Bundle) error {
var products []string
// Add "cli" to the user agent in set by the Databricks Terraform provider.
// This will allow us to attribute downstream requests made by the Databricks
// Terraform provider to the CLI.
products := []string{fmt.Sprintf("cli/%s", build.GetInfo().Version)}
if experimental := b.Config.Experimental; experimental != nil {
if experimental.PyDABs.Enabled {
products = append(products, "databricks-pydabs/0.0.0")

View File

@ -262,10 +262,9 @@ func TestSetUserAgentExtraEnvVar(t *testing.T) {
env := make(map[string]string, 0)
err := setUserAgentExtraEnvVar(env, b)
require.NoError(t, err)
assert.Equal(t, map[string]string{
"DATABRICKS_USER_AGENT_EXTRA": "databricks-pydabs/0.0.0",
"DATABRICKS_USER_AGENT_EXTRA": "cli/0.0.0-dev databricks-pydabs/0.0.0",
}, env)
}