Skip to content

Commit

Permalink
CLOUDP-252933: Add telemetry indicator for university users (#3021)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo committed Jun 19, 2024
1 parent 594c4fe commit e442bcc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const (
ContainerizedHostNameEnv = "MONGODB_ATLAS_IS_CONTAINERIZED"
GitHubActionsHostNameEnv = "GITHUB_ACTIONS"
AtlasActionHostNameEnv = "ATLAS_GITHUB_ACTION"
CLIUserTypeEnv = "CLI_USER_TYPE" // CLIUserTypeEnv is used to separate MongoDB University users from default users
DefaultUser = "default" // Users that do NOT use ATLAS CLI with MongoDB University
UniversityUser = "university" // Users that uses ATLAS CLI with MongoDB University
NativeHostName = "native"
DockerContainerHostName = "container"
GitHubActionsHostName = "all_github_actions"
Expand All @@ -74,6 +77,7 @@ const (
var (
HostName = getConfigHostnameFromEnvs()
UserAgent = fmt.Sprintf("%s/%s (%s;%s;%s)", AtlasCLI, version.Version, runtime.GOOS, runtime.GOARCH, HostName)
CLIUserType = newCLIUserTypeFromEnvs()
defaultProfile = newProfile()
)

Expand Down Expand Up @@ -196,6 +200,15 @@ func getConfigHostnameFromEnvs() string {
return configHostName
}

// newCLIUserTypeFromEnvs patches the user type information based on set env vars.
func newCLIUserTypeFromEnvs() string {
if value, ok := os.LookupEnv(CLIUserTypeEnv); ok {
return value
}

return DefaultUser
}

func envIsTrue(env string) bool {
return IsTrue(os.Getenv(env))
}
Expand Down
6 changes: 6 additions & 0 deletions internal/telemetry/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ func withProjectID(cmd CmdFlags, c ProjectIDGetter) EventOpt {
}
}

func withCLIUserType() EventOpt {
return func(event Event) {
event.Properties["cli_user_type"] = config.CLIUserType
}
}

type OrgIDGetter interface {
OrgID() string
}
Expand Down
12 changes: 12 additions & 0 deletions internal/telemetry/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ func TestWithService(t *testing.T) {
a.Equal(url, e.Properties["ops_manager_url"])
}

func TestWithCLIUserType(t *testing.T) {
config.CLIUserType = config.DefaultUser
a := assert.New(t)
e := newEvent(withCLIUserType())
a.Equal(config.DefaultUser, e.Properties["cli_user_type"])

config.CLIUserType = config.UniversityUser
e = newEvent(withCLIUserType())
a.Equal(config.UniversityUser, e.Properties["cli_user_type"])
}

func TestWithProjectID(t *testing.T) {
cmd := &cobra.Command{
Use: "test-command",
Expand Down Expand Up @@ -397,6 +408,7 @@ func (c configMock) PublicAPIKey() string {
func (c configMock) PrivateAPIKey() string {
return c.privateKey
}

func (c configMock) AccessToken() string {
return c.accessToken
}
1 change: 1 addition & 0 deletions internal/telemetry/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (t *tracker) defaultCommandOptions() []EventOpt {
withUserAgent(),
withAnonymousID(),
withCI(),
withCLIUserType(),
withSkipUpdateCheck(config.Default()),
}
}
Expand Down

0 comments on commit e442bcc

Please sign in to comment.