-
Notifications
You must be signed in to change notification settings - Fork 179
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
chore: Improves user agent in the provider to include Terraform CLI version #2085
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some follow up doubts
internal/provider/provider.go
Outdated
@@ -231,6 +231,7 @@ func (p *MongodbtlasProvider) Configure(ctx context.Context, req provider.Config | |||
PrivateKey: data.PrivateKey.ValueString(), | |||
BaseURL: data.BaseURL.ValueString(), | |||
RealmBaseURL: data.RealmBaseURL.ValueString(), | |||
UserAgent: config.TerraformVersionUserAgentInfo(req.TerraformVersion), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] Could both the provider version and the terraform version be defined in a single place so it is easy to see the complete user agent format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be but I have kept it separate. Ideally user agent should be taken care of when creating new client (like we already do today) but in this case I had to set the new Terraform version user agent in the Provider because that's only where it's available.
Defining both in single place would mean we take provider version out of the client creation which I don't think we should do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, one option could be to define a property TerraformVersion in the Config struct (instead of UserAgent), and then when creating a new client define the user agent with both the terraform and provider versions available. Let me know if you feel this makes it clearer or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing after spending some time reviewing this. Having TerraformVersion
would help a lot in terms of readability. In fact during client creation you can "compose" the user agent in-place without even having to have a special append function IMO.
Also this solution would help to handle logs / problems: e.g. if TerraformVersion
is empty during the client creation phase then we should handle it with a warning probably since it's something that needs attention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added TerraformVersion in the Config struct, let me know what you think
Co-authored-by: Agustin Bettati <[email protected]>
internal/config/client.go
Outdated
) | ||
|
||
const ( | ||
toolName = "terraform-provider-mongodbatlas" | ||
) | ||
|
||
var ( | ||
userAgent = fmt.Sprintf("%s/%s", toolName, version.ProviderVersion) | ||
userAgentProviderVersion = fmt.Sprintf("%s/%s", toolName, version.ProviderVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be useful to add some tests in the PR?
This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just to confirm the conclusion with analytics team was to have the provider version first and then the terraform version?
This was Gus's suggestion, yes. I have updated the testing example in the PR accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job!
Description
Improves user agent in the provider to include Terraform CLI version
Link to any related issue(s): CLOUDP-237005
Type of change:
Required Checklist:
Further comments
TF Plugin Framework based resource API call logs:
TF Plugin SDK based resource API call logs: