Skip to content

Commit 30cead7

Browse files
committed
CLOUDP-314920 Telemetry for Custom Roles
1 parent 57bf053 commit 30cead7

File tree

5 files changed

+160
-9
lines changed

5 files changed

+160
-9
lines changed

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ require (
1313
github.com/hashicorp/go-retryablehttp v0.7.7
1414
github.com/hashicorp/vault/api v1.16.0
1515
github.com/imdario/mergo v0.3.15
16-
github.com/onsi/ginkgo/v2 v2.17.1
17-
github.com/onsi/gomega v1.32.0
1816
github.com/pkg/errors v0.9.1
1917
github.com/prometheus/client_golang v1.22.0
2018
github.com/r3labs/diff/v3 v3.0.1
@@ -56,15 +54,13 @@ require (
5654
github.com/go-openapi/jsonpointer v0.19.6 // indirect
5755
github.com/go-openapi/jsonreference v0.20.2 // indirect
5856
github.com/go-openapi/swag v0.22.3 // indirect
59-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
6057
github.com/gogo/protobuf v1.3.2 // indirect
6158
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
6259
github.com/golang/protobuf v1.5.4 // indirect
6360
github.com/golang/snappy v0.0.4 // indirect
6461
github.com/google/gnostic-models v0.6.8 // indirect
6562
github.com/google/go-querystring v1.1.0 // indirect
6663
github.com/google/gofuzz v1.2.0 // indirect
67-
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
6864
github.com/gorilla/websocket v1.5.0 // indirect
6965
github.com/hashicorp/errwrap v1.1.0 // indirect
7066
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
1010
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
1111
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1212
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
13-
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
14-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
15-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
1613
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1714
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1815
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -113,7 +110,6 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
113110
github.com/hashicorp/vault/api v1.16.0 h1:nbEYGJiAPGzT9U4oWgaaB0g+Rj8E59QuHKyA5LhwQN4=
114111
github.com/hashicorp/vault/api v1.16.0/go.mod h1:KhuUhzOD8lDSk29AtzNjgAu2kxRA9jL9NAbkFlqvkBA=
115112
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
116-
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
117113
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
118114
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
119115
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -288,7 +284,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
288284
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
289285
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
290286
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
291-
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
292287
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
293288
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
294289
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

pkg/telemetry/collector.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func getMdbEvents(ctx context.Context, operatorClusterClient kubeclient.Client,
227227
Type: string(item.Spec.GetResourceType()),
228228
IsRunningEnterpriseImage: images.IsEnterpriseImage(imageURL),
229229
ExternalDomains: getExternalDomainProperty(item),
230+
CustomRoles: getCustomRoles(item.Spec.Security),
230231
AuthenticationModes: getAuthenticationModes(item.Spec.Security),
231232
AuthenticationAgentMode: getAuthenticationAgentMode(item.Spec.Security),
232233
}
@@ -267,6 +268,7 @@ func addMultiEvents(ctx context.Context, operatorClusterClient kubeclient.Client
267268
Type: string(item.Spec.GetResourceType()),
268269
IsRunningEnterpriseImage: images.IsEnterpriseImage(imageURL),
269270
ExternalDomains: getExternalDomainPropertyForMongoDBMulti(item),
271+
CustomRoles: getCustomRoles(item.Spec.Security),
270272
AuthenticationModes: getAuthenticationModes(item.Spec.Security),
271273
AuthenticationAgentMode: getAuthenticationAgentMode(item.Spec.Security),
272274
}
@@ -531,6 +533,28 @@ func isExternalDomainSpecifiedInClusterSpecList(clusterSpecList mdbv1.ClusterSpe
531533
return clusterSpecList.IsExternalDomainSpecifiedInClusterSpecList()
532534
}
533535

536+
const (
537+
CustomRoleNone = "None"
538+
CustomRoleEmbedded = "Embedded"
539+
CustomRoleReferenced = "Referenced"
540+
)
541+
542+
func getCustomRoles(security *mdbv1.Security) string {
543+
if security == nil {
544+
return CustomRoleNone
545+
}
546+
547+
if len(security.Roles) > 0 {
548+
return CustomRoleEmbedded
549+
}
550+
551+
if len(security.RoleRefs) > 0 {
552+
return CustomRoleReferenced
553+
}
554+
555+
return CustomRoleNone
556+
}
557+
534558
func getAuthenticationModes(security *mdbv1.Security) []string {
535559
if security == nil || security.Authentication == nil {
536560
return nil

pkg/telemetry/collector_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
7070
"type": "ReplicaSet",
7171
"IsRunningEnterpriseImage": false,
7272
"externalDomains": ExternalDomainNone,
73+
"customRoles": CustomRoleNone,
7374
"authenticationModeLDAP": true,
7475
"authenticationModeOIDC": true,
7576
"authenticationModeSCRAM": true,
@@ -109,6 +110,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
109110
"type": "ReplicaSet",
110111
"IsRunningEnterpriseImage": false,
111112
"externalDomains": ExternalDomainNone,
113+
"customRoles": CustomRoleNone,
112114
"authenticationModeSCRAM": true,
113115
"authenticationAgentMode": util.SCRAM,
114116
},
@@ -921,6 +923,139 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
921923
},
922924
},
923925
},
926+
"custom roles test": {
927+
objects: []client.Object{
928+
&mdbv1.MongoDB{
929+
Spec: mdbv1.MongoDbSpec{
930+
DbCommonSpec: mdbv1.DbCommonSpec{
931+
ResourceType: mdbv1.ReplicaSet,
932+
Security: &mdbv1.Security{},
933+
},
934+
}, ObjectMeta: metav1.ObjectMeta{
935+
UID: "be4bacfc-fb41-4e29-b7d1-712460ed908c",
936+
Name: "test-rs-no-roles",
937+
},
938+
},
939+
&mdbv1.MongoDB{
940+
Spec: mdbv1.MongoDbSpec{
941+
DbCommonSpec: mdbv1.DbCommonSpec{
942+
ResourceType: mdbv1.ReplicaSet,
943+
Security: &mdbv1.Security{
944+
Roles: []mdbv1.MongoDBRole{
945+
{
946+
Role: "test-role1",
947+
Db: "admin",
948+
Privileges: []mdbv1.Privilege{
949+
{
950+
Actions: []string{"action1", "action2"},
951+
},
952+
},
953+
},
954+
},
955+
},
956+
},
957+
}, ObjectMeta: metav1.ObjectMeta{
958+
UID: "c20a7cf1-a12d-4cee-a87e-7f61aa2bd878",
959+
Name: "test-rs-embedded-roles",
960+
},
961+
},
962+
&mdbv1.MongoDB{
963+
Spec: mdbv1.MongoDbSpec{
964+
DbCommonSpec: mdbv1.DbCommonSpec{
965+
ResourceType: mdbv1.ReplicaSet,
966+
Security: &mdbv1.Security{
967+
RoleRefs: []mdbv1.MongoDBRoleRef{
968+
{
969+
Name: "test-role",
970+
Kind: "ClusterMongoDBRole",
971+
},
972+
},
973+
},
974+
},
975+
}, ObjectMeta: metav1.ObjectMeta{
976+
UID: "97822e48-fb51-4ba5-9993-26841b44a7a3",
977+
Name: "test-rs-ref-roles",
978+
},
979+
},
980+
&mdbmulti.MongoDBMultiCluster{
981+
Spec: mdbmulti.MongoDBMultiSpec{
982+
DbCommonSpec: mdbv1.DbCommonSpec{
983+
ResourceType: mdbv1.ReplicaSet,
984+
},
985+
}, ObjectMeta: metav1.ObjectMeta{
986+
UID: "17e352f7-dcd1-4bfa-bc12-a2f4e637477b",
987+
Name: "test-mrs-no-roles",
988+
},
989+
},
990+
&mdbmulti.MongoDBMultiCluster{
991+
Spec: mdbmulti.MongoDBMultiSpec{
992+
DbCommonSpec: mdbv1.DbCommonSpec{
993+
ResourceType: mdbv1.ReplicaSet,
994+
Security: &mdbv1.Security{
995+
Roles: []mdbv1.MongoDBRole{
996+
{
997+
Role: "test-role1",
998+
Db: "admin",
999+
Privileges: []mdbv1.Privilege{
1000+
{
1001+
Actions: []string{"action1", "action2"},
1002+
},
1003+
},
1004+
},
1005+
},
1006+
},
1007+
},
1008+
}, ObjectMeta: metav1.ObjectMeta{
1009+
UID: "71368077-ea95-4564-acd6-09ec573fdf61",
1010+
Name: "test-mrs-embedded-roles",
1011+
},
1012+
},
1013+
&mdbmulti.MongoDBMultiCluster{
1014+
Spec: mdbmulti.MongoDBMultiSpec{
1015+
DbCommonSpec: mdbv1.DbCommonSpec{
1016+
ResourceType: mdbv1.ReplicaSet,
1017+
Security: &mdbv1.Security{
1018+
RoleRefs: []mdbv1.MongoDBRoleRef{
1019+
{
1020+
Name: "test-role",
1021+
Kind: "ClusterMongoDBRole",
1022+
},
1023+
},
1024+
},
1025+
},
1026+
}, ObjectMeta: metav1.ObjectMeta{
1027+
UID: "a8a28c8a-6226-44fc-a8cd-e66a6942ffbd",
1028+
Name: "test-mrs-ref-roles",
1029+
},
1030+
},
1031+
},
1032+
expectedEventsWithProperties: []map[string]any{
1033+
{
1034+
"deploymentUID": "be4bacfc-fb41-4e29-b7d1-712460ed908c",
1035+
"customRoles": CustomRoleNone,
1036+
},
1037+
{
1038+
"deploymentUID": "c20a7cf1-a12d-4cee-a87e-7f61aa2bd878",
1039+
"customRoles": CustomRoleEmbedded,
1040+
},
1041+
{
1042+
"deploymentUID": "97822e48-fb51-4ba5-9993-26841b44a7a3",
1043+
"customRoles": CustomRoleReferenced,
1044+
},
1045+
{
1046+
"deploymentUID": "17e352f7-dcd1-4bfa-bc12-a2f4e637477b",
1047+
"customRoles": CustomRoleNone,
1048+
},
1049+
{
1050+
"deploymentUID": "71368077-ea95-4564-acd6-09ec573fdf61",
1051+
"customRoles": CustomRoleEmbedded,
1052+
},
1053+
{
1054+
"deploymentUID": "a8a28c8a-6226-44fc-a8cd-e66a6942ffbd",
1055+
"customRoles": CustomRoleReferenced,
1056+
},
1057+
},
1058+
},
9241059
}
9251060

9261061
for name, test := range tests {

pkg/telemetry/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type DeploymentUsageSnapshotProperties struct {
4949
Type string `json:"type"` // RS, SC, OM, Single
5050
IsRunningEnterpriseImage bool `json:"IsRunningEnterpriseImage"`
5151
ExternalDomains string `json:"externalDomains"` // None, Uniform, ClusterSpecific, Mixed
52+
CustomRoles string `json:"customRoles,omitempty"` // Custom roles used // None, Uniform, ClusterSpecific, Mixed
5253
AuthenticationAgentMode string `json:"authenticationAgentMode,omitempty"` // Agent authentication mode
5354
AuthenticationModes []string `json:"-"` // Deployment authentication modes
5455
}

0 commit comments

Comments
 (0)