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

chore: Improves user agent in the provider to include Terraform CLI version #2085

Merged
merged 8 commits into from
Apr 5, 2024

Conversation

maastha
Copy link
Collaborator

@maastha maastha commented Mar 26, 2024

Description

Improves user agent in the provider to include Terraform CLI version

Link to any related issue(s): CLOUDP-237005

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

TF Plugin Framework based resource API call logs:

2024/04/05 15:17:50 
GET /api/atlas/v2/groups/6602bedbc32461337d92e2a5/settings HTTP/1.1
Host: cloud-dev.mongodb.com
User-Agent: terraform-provider-mongodbatlas/devel Terraform/1.7.0-rc1
Accept: application/vnd.atlas.2023-01-01+json
Accept-Encoding: gzip

TF Plugin SDK based resource API call logs:

2024/04/05 15:17:52 
POST /api/atlas/v2/groups/6602d0208210bb7b10f5f8a8/clusters HTTP/1.1
Host: cloud-dev.mongodb.com
User-Agent: terraform-provider-mongodbatlas/devel Terraform/1.7.0-rc1
Content-Length: 302
Accept: application/vnd.atlas.2023-02-01+json

@maastha maastha marked this pull request as ready for review March 26, 2024 15:15
@maastha maastha requested a review from a team as a code owner March 26, 2024 15:15
internal/config/client.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

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

Great work! LGTM

Copy link
Member

@AgustinBettati AgustinBettati left a 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_sdk2.go Outdated Show resolved Hide resolved
internal/provider/provider_sdk2.go Outdated Show resolved Hide resolved
@@ -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),
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

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

internal/config/client.go Outdated Show resolved Hide resolved
)

const (
toolName = "terraform-provider-mongodbatlas"
)

var (
userAgent = fmt.Sprintf("%s/%s", toolName, version.ProviderVersion)
userAgentProviderVersion = fmt.Sprintf("%s/%s", toolName, version.ProviderVersion)
Copy link
Member

@lantoli lantoli Mar 26, 2024

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?

Copy link
Contributor

github-actions bot commented Apr 1, 2024

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!

@github-actions github-actions bot added the stale label Apr 1, 2024
@oarbusi oarbusi removed the stale label Apr 2, 2024
internal/config/client.go Outdated Show resolved Hide resolved
Copy link
Member

@AgustinBettati AgustinBettati left a 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?

@maastha
Copy link
Collaborator Author

maastha commented Apr 5, 2024

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.

Copy link
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

Awesome job!

@maastha maastha merged commit ac9b66b into master Apr 5, 2024
48 checks passed
@maastha maastha deleted the CLOUDP-237005-enrich-user-agent branch April 5, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants