Skip to content

Commit e442bcc

Browse files
CLOUDP-252933: Add telemetry indicator for university users (#3021)
1 parent 594c4fe commit e442bcc

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

internal/config/profile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ const (
6565
ContainerizedHostNameEnv = "MONGODB_ATLAS_IS_CONTAINERIZED"
6666
GitHubActionsHostNameEnv = "GITHUB_ACTIONS"
6767
AtlasActionHostNameEnv = "ATLAS_GITHUB_ACTION"
68+
CLIUserTypeEnv = "CLI_USER_TYPE" // CLIUserTypeEnv is used to separate MongoDB University users from default users
69+
DefaultUser = "default" // Users that do NOT use ATLAS CLI with MongoDB University
70+
UniversityUser = "university" // Users that uses ATLAS CLI with MongoDB University
6871
NativeHostName = "native"
6972
DockerContainerHostName = "container"
7073
GitHubActionsHostName = "all_github_actions"
@@ -74,6 +77,7 @@ const (
7477
var (
7578
HostName = getConfigHostnameFromEnvs()
7679
UserAgent = fmt.Sprintf("%s/%s (%s;%s;%s)", AtlasCLI, version.Version, runtime.GOOS, runtime.GOARCH, HostName)
80+
CLIUserType = newCLIUserTypeFromEnvs()
7781
defaultProfile = newProfile()
7882
)
7983

@@ -196,6 +200,15 @@ func getConfigHostnameFromEnvs() string {
196200
return configHostName
197201
}
198202

203+
// newCLIUserTypeFromEnvs patches the user type information based on set env vars.
204+
func newCLIUserTypeFromEnvs() string {
205+
if value, ok := os.LookupEnv(CLIUserTypeEnv); ok {
206+
return value
207+
}
208+
209+
return DefaultUser
210+
}
211+
199212
func envIsTrue(env string) bool {
200213
return IsTrue(os.Getenv(env))
201214
}

internal/telemetry/event.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ func withProjectID(cmd CmdFlags, c ProjectIDGetter) EventOpt {
259259
}
260260
}
261261

262+
func withCLIUserType() EventOpt {
263+
return func(event Event) {
264+
event.Properties["cli_user_type"] = config.CLIUserType
265+
}
266+
}
267+
262268
type OrgIDGetter interface {
263269
OrgID() string
264270
}

internal/telemetry/event_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ func TestWithService(t *testing.T) {
163163
a.Equal(url, e.Properties["ops_manager_url"])
164164
}
165165

166+
func TestWithCLIUserType(t *testing.T) {
167+
config.CLIUserType = config.DefaultUser
168+
a := assert.New(t)
169+
e := newEvent(withCLIUserType())
170+
a.Equal(config.DefaultUser, e.Properties["cli_user_type"])
171+
172+
config.CLIUserType = config.UniversityUser
173+
e = newEvent(withCLIUserType())
174+
a.Equal(config.UniversityUser, e.Properties["cli_user_type"])
175+
}
176+
166177
func TestWithProjectID(t *testing.T) {
167178
cmd := &cobra.Command{
168179
Use: "test-command",
@@ -397,6 +408,7 @@ func (c configMock) PublicAPIKey() string {
397408
func (c configMock) PrivateAPIKey() string {
398409
return c.privateKey
399410
}
411+
400412
func (c configMock) AccessToken() string {
401413
return c.accessToken
402414
}

internal/telemetry/tracker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func (t *tracker) defaultCommandOptions() []EventOpt {
101101
withUserAgent(),
102102
withAnonymousID(),
103103
withCI(),
104+
withCLIUserType(),
104105
withSkipUpdateCheck(config.Default()),
105106
}
106107
}

0 commit comments

Comments
 (0)