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

INTMDB-232: Fix user agent version #505

Merged
merged 2 commits into from
Aug 5, 2021
Merged

INTMDB-232: Fix user agent version #505

merged 2 commits into from
Aug 5, 2021

Conversation

MihaiBojin
Copy link
Contributor

@MihaiBojin MihaiBojin commented Aug 4, 2021

Description

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Link to any related issue(s):

Type of change:

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

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the Terraform contribution guidelines
  • 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

Further comments

Confirmed UA is now reported correctly (Splunk):

Repro

  1. Create a file called main.tf
terraform {
  required_providers {
    mongodbatlas = {
      source = "localhost/mongodb/mongodbatlas"
      version = "1.0.0"
    }
  }
}

provider "mongodbatlas" {
  public_key = "..."
  private_key  = "..."
}


resource "mongodbatlas_project" "p0" {
  name   = "Project 0"
  org_id = "$ORG_ID"
}
  1. Compile the provider and install it locally:
mkdir -p  ~/.terraform.d/plugins/localhost/mongodb/mongodbatlas/1.0.0/darwin_amd64
make build && mv ~/go/bin/terraform-provider-mongodbatlas ~/.terraform.d/plugins/localhost/mongodb/mongodbatlas/1.0.0/darwin_amd64/
  1. Init the config and import a project (making a call to the API)
rm -rf .terraform .terraform.lock.hcl && terraform init &&  terraform import mongodbatlas_project.p0 $ORG_ID

Reported UA

Screenshot 2021-08-05 at 00 29 11

Copy link
Collaborator

@themantissa themantissa left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you so much @MihaiBojin

@@ -42,7 +42,7 @@ websitefmtcheck:
lint:
@echo "==> Checking source code against linters..."
# https://github.com/golangci/golangci-lint/issues/337 fixing error
golangci-lint run ./$(PKG_NAME) -v --deadline=30m
bin/golangci-lint run ./$(PKG_NAME) -v --deadline=30m
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drive-by: golangci-lint is installed under bin/ - there's no point relying on the tool being available in the system path. cc @gssbzn in case I'm missing something

Copy link
Collaborator

Choose a reason for hiding this comment

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

line 16 includes the bin folder in the PATH (export PATH := ./bin:$(PATH)) for convenience, no need to revert this just curious if that no longer works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't work for me on Mac, but it worked in GH actions


digest "github.com/mongodb-forks/digest"
"github.com/mongodb-forks/digest"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drive-by fix - unnecessary aliasing

@@ -1,4 +1,4 @@
package mongodbatlas
package version
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved under root / following the same directory structure as the AWS provider

@@ -14,7 +14,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X mongodbatlas/version.ProviderVersion={{.Version}}
- -s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion={{.Version}}'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ProviderVersion was not being replaced, without the full repo path being specified

@MihaiBojin MihaiBojin requested a review from gssbzn August 4, 2021 21:50
Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -38,7 +39,7 @@ func (c *Config) NewClient(ctx context.Context) (interface{}, diag.Diagnostics)

client.Transport = logging.NewTransport("MongoDB Atlas", transport)

optsAtlas := []matlasClient.ClientOpt{matlasClient.SetUserAgent("terraform-provider-mongodbatlas/" + ProviderVersion)}
optsAtlas := []matlasClient.ClientOpt{matlasClient.SetUserAgent("terraform-provider-mongodbatlas/" + version.ProviderVersion)}
Copy link
Collaborator

@gssbzn gssbzn Aug 5, 2021

Choose a reason for hiding this comment

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

[q] this is the user agent we do for the cli

var userAgent = fmt.Sprintf("%s/%s (%s;%s)", config.ToolName, version.Version, runtime.GOOS, runtime.GOARCH)

should we make something similar, ie: include os and arch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense. Will update later, but if you want to make the change directly on the PR it would be even better, since I won't be in front of a computer for the next few hours. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought @gssbzn, if we made this change, the UA would be reported as:

 userAgent: terraform-provider-mongodbatlas/0.9.1-29-g13eb1636 (darwin;amd64) go-mongodbatlas/0.10.1 (darwin;amd64) 

(since we add the OS/ARCH via the go client)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to merge the PR as is / I don't think duplicating that info makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

totally forgot we were doing that in the client, merge away

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM questions and clarifications are not blocking
Thanks fro fixing this

@MihaiBojin MihaiBojin merged commit 22469a2 into master Aug 5, 2021
@MihaiBojin MihaiBojin deleted the INTMDB-232_fix branch August 5, 2021 14:01
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.

4 participants