Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the way user agent string gets assigned. #587

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,16 @@ func withRequestLogging() autorest.SendDecorator {
}

func setUserAgent(client *autorest.Client) {
version := terraform.VersionString()
client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version)
tfVersion := fmt.Sprintf("HashiCorp-Terraform-v%s", terraform.VersionString())

// append the CloudShell version to the user agent
// if the user agent already has a value append the Terraform user agent string
if curUserAgent := client.UserAgent; curUserAgent != "" {
client.UserAgent = fmt.Sprintf("%s;%s", curUserAgent, tfVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this function is called in multiple places - have you tested this behaviour and checked the outputs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have, you can see the results here. It works as expected without any duplicate strings added. However, I question why it gets called 164 times when provisioning a single object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool - AFAIK that's due to us setting the user agent for each API Client (such as a SQLDBClient/CosmosDBClient/AppServiceClient etc) that we instantiate when the Provider Plugin's initialised

} else {
client.UserAgent = tfVersion
}

// append the CloudShell version to the user agent if it exists
if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" {
client.UserAgent = fmt.Sprintf("%s;%s", client.UserAgent, azureAgent)
}
Expand Down