Skip to content

Commit c242836

Browse files
MaciejKaraslucian-tosalsierant
authored
CLOUDP-314920 Telemetry for Custom Roles (#159)
# Summary Adds Telemetry support for Custom Roles. New field `customRoles` can take one of values: - CustomRoleNone = "None" - CustomRoleEmbedded = "Embedded" - CustomRoleReferenced = "Referenced" ## Proof of Work Passing unit tests. ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? --------- Co-authored-by: Lucian Tosa <lucian.tosa@mongodb.com> Co-authored-by: Lucian Tosa <49226451+lucian-tosa@users.noreply.github.com> Co-authored-by: Łukasz Sierant <lukasz.sierant@mongodb.com>
1 parent 2abfb24 commit c242836

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

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: 188 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
},
@@ -227,6 +229,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
227229
"type": string(mdbv1.ReplicaSet),
228230
"isMultiCluster": false,
229231
"externalDomains": ExternalDomainNone,
232+
"customRoles": CustomRoleNone,
230233
"operatorID": testOperatorUUID,
231234
},
232235
{
@@ -236,6 +239,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
236239
"type": string(mdbv1.ReplicaSet),
237240
"isMultiCluster": false,
238241
"externalDomains": ExternalDomainNone,
242+
"customRoles": CustomRoleNone,
239243
"operatorID": testOperatorUUID,
240244
},
241245
{
@@ -245,6 +249,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
245249
"type": string(mdbv1.ReplicaSet),
246250
"isMultiCluster": true,
247251
"externalDomains": ExternalDomainNone,
252+
"customRoles": CustomRoleNone,
248253
"operatorID": testOperatorUUID,
249254
"databaseClusters": float64(0),
250255
},
@@ -255,6 +260,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
255260
"type": string(mdbv1.ReplicaSet),
256261
"isMultiCluster": true,
257262
"externalDomains": ExternalDomainNone,
263+
"customRoles": CustomRoleNone,
258264
"operatorID": testOperatorUUID,
259265
"databaseClusters": float64(0),
260266
},
@@ -408,6 +414,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
408414
"operatorID": testOperatorUUID,
409415
"type": string(mdbv1.ReplicaSet),
410416
"externalDomains": ExternalDomainNone,
417+
"customRoles": CustomRoleNone,
411418
},
412419
{
413420
"deploymentUID": "a31ab7a8-e5bd-480b-afcc-ac2eec9ce348",
@@ -418,6 +425,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
418425
"operatorID": testOperatorUUID,
419426
"type": string(mdbv1.ReplicaSet),
420427
"externalDomains": ExternalDomainNone,
428+
"customRoles": CustomRoleNone,
421429
},
422430
{
423431
"deploymentUID": "2b138678-4e4c-4be4-9877-16e6eaae279b",
@@ -804,6 +812,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
804812
{
805813
"deploymentUID": "2c60ec7b-b233-4d98-97e6-b7c423c19e24",
806814
"externalDomains": ExternalDomainNone,
815+
"customRoles": CustomRoleNone,
807816
"isMultiCluster": false,
808817
"architecture": string(architectures.NonStatic),
809818
"IsRunningEnterpriseImage": false,
@@ -813,6 +822,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
813822
{
814823
"deploymentUID": "c7ccb57f-abd1-4944-8a99-02e5a79acf75",
815824
"externalDomains": ExternalDomainUniform,
825+
"customRoles": CustomRoleNone,
816826
"isMultiCluster": false,
817827
"architecture": string(architectures.NonStatic),
818828
"IsRunningEnterpriseImage": false,
@@ -822,6 +832,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
822832
{
823833
"deploymentUID": "7eed85ce-7a38-43ea-a338-6d959339c146",
824834
"externalDomains": ExternalDomainMixed,
835+
"customRoles": CustomRoleNone,
825836
"isMultiCluster": true,
826837
"databaseClusters": float64(2),
827838
"architecture": string(architectures.NonStatic),
@@ -832,6 +843,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
832843
{
833844
"deploymentUID": "584515da-e797-48af-af7f-6561812c15f4",
834845
"externalDomains": ExternalDomainClusterSpecific,
846+
"customRoles": CustomRoleNone,
835847
"isMultiCluster": true,
836848
"databaseClusters": float64(2),
837849
"architecture": string(architectures.NonStatic),
@@ -842,6 +854,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
842854
{
843855
"deploymentUID": "27b3d7cf-1f8b-434d-a002-ce85f7313507",
844856
"externalDomains": ExternalDomainNone,
857+
"customRoles": CustomRoleNone,
845858
"isMultiCluster": true,
846859
"databaseClusters": float64(3),
847860
"architecture": string(architectures.NonStatic),
@@ -852,6 +865,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
852865
{
853866
"deploymentUID": "b050040e-7b53-4991-bae4-69663a523804",
854867
"externalDomains": ExternalDomainUniform,
868+
"customRoles": CustomRoleNone,
855869
"isMultiCluster": true,
856870
"databaseClusters": float64(3),
857871
"architecture": string(architectures.NonStatic),
@@ -862,6 +876,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
862876
{
863877
"deploymentUID": "54427a32-1799-4a1b-b03f-a50484c09d2c",
864878
"externalDomains": ExternalDomainMixed,
879+
"customRoles": CustomRoleNone,
865880
"isMultiCluster": true,
866881
"databaseClusters": float64(3),
867882
"architecture": string(architectures.NonStatic),
@@ -872,6 +887,7 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
872887
{
873888
"deploymentUID": "fe6b6fad-51f2-4f98-8ddd-54ae24143ea6",
874889
"externalDomains": ExternalDomainClusterSpecific,
890+
"customRoles": CustomRoleNone,
875891
"isMultiCluster": true,
876892
"databaseClusters": float64(3),
877893
"architecture": string(architectures.NonStatic),
@@ -921,6 +937,178 @@ func TestCollectDeploymentsSnapshot(t *testing.T) {
921937
},
922938
},
923939
},
940+
"custom roles test": {
941+
objects: []client.Object{
942+
&mdbv1.MongoDB{
943+
Spec: mdbv1.MongoDbSpec{
944+
DbCommonSpec: mdbv1.DbCommonSpec{
945+
ResourceType: mdbv1.ReplicaSet,
946+
Security: &mdbv1.Security{},
947+
},
948+
}, ObjectMeta: metav1.ObjectMeta{
949+
UID: "be4bacfc-fb41-4e29-b7d1-712460ed908c",
950+
Name: "test-rs-no-roles",
951+
},
952+
},
953+
&mdbv1.MongoDB{
954+
Spec: mdbv1.MongoDbSpec{
955+
DbCommonSpec: mdbv1.DbCommonSpec{
956+
ResourceType: mdbv1.ReplicaSet,
957+
Security: &mdbv1.Security{
958+
Roles: []mdbv1.MongoDBRole{
959+
{
960+
Role: "test-role1",
961+
Db: "admin",
962+
Privileges: []mdbv1.Privilege{
963+
{
964+
Actions: []string{"action1", "action2"},
965+
},
966+
},
967+
},
968+
},
969+
},
970+
},
971+
}, ObjectMeta: metav1.ObjectMeta{
972+
UID: "c20a7cf1-a12d-4cee-a87e-7f61aa2bd878",
973+
Name: "test-rs-embedded-roles",
974+
},
975+
},
976+
&mdbv1.MongoDB{
977+
Spec: mdbv1.MongoDbSpec{
978+
DbCommonSpec: mdbv1.DbCommonSpec{
979+
ResourceType: mdbv1.ReplicaSet,
980+
Security: &mdbv1.Security{
981+
RoleRefs: []mdbv1.MongoDBRoleRef{
982+
{
983+
Name: "test-role",
984+
Kind: "ClusterMongoDBRole",
985+
},
986+
},
987+
},
988+
},
989+
}, ObjectMeta: metav1.ObjectMeta{
990+
UID: "97822e48-fb51-4ba5-9993-26841b44a7a3",
991+
Name: "test-rs-ref-roles",
992+
},
993+
},
994+
&mdbmulti.MongoDBMultiCluster{
995+
Spec: mdbmulti.MongoDBMultiSpec{
996+
DbCommonSpec: mdbv1.DbCommonSpec{
997+
ResourceType: mdbv1.ReplicaSet,
998+
},
999+
}, ObjectMeta: metav1.ObjectMeta{
1000+
UID: "17e352f7-dcd1-4bfa-bc12-a2f4e637477b",
1001+
Name: "test-mrs-no-roles",
1002+
},
1003+
},
1004+
&mdbmulti.MongoDBMultiCluster{
1005+
Spec: mdbmulti.MongoDBMultiSpec{
1006+
DbCommonSpec: mdbv1.DbCommonSpec{
1007+
ResourceType: mdbv1.ReplicaSet,
1008+
Security: &mdbv1.Security{
1009+
Roles: []mdbv1.MongoDBRole{
1010+
{
1011+
Role: "test-role1",
1012+
Db: "admin",
1013+
Privileges: []mdbv1.Privilege{
1014+
{
1015+
Actions: []string{"action1", "action2"},
1016+
},
1017+
},
1018+
},
1019+
},
1020+
},
1021+
},
1022+
}, ObjectMeta: metav1.ObjectMeta{
1023+
UID: "71368077-ea95-4564-acd6-09ec573fdf61",
1024+
Name: "test-mrs-embedded-roles",
1025+
},
1026+
},
1027+
&mdbmulti.MongoDBMultiCluster{
1028+
Spec: mdbmulti.MongoDBMultiSpec{
1029+
DbCommonSpec: mdbv1.DbCommonSpec{
1030+
ResourceType: mdbv1.ReplicaSet,
1031+
Security: &mdbv1.Security{
1032+
RoleRefs: []mdbv1.MongoDBRoleRef{
1033+
{
1034+
Name: "test-role",
1035+
Kind: "ClusterMongoDBRole",
1036+
},
1037+
},
1038+
},
1039+
},
1040+
}, ObjectMeta: metav1.ObjectMeta{
1041+
UID: "a8a28c8a-6226-44fc-a8cd-e66a6942ffbd",
1042+
Name: "test-mrs-ref-roles",
1043+
},
1044+
},
1045+
},
1046+
expectedEventsWithProperties: []map[string]any{
1047+
{
1048+
"deploymentUID": "be4bacfc-fb41-4e29-b7d1-712460ed908c",
1049+
"customRoles": CustomRoleNone,
1050+
"externalDomains": ExternalDomainNone,
1051+
"isMultiCluster": false,
1052+
"architecture": string(architectures.NonStatic),
1053+
"IsRunningEnterpriseImage": false,
1054+
"operatorID": testOperatorUUID,
1055+
"type": string(mdbv1.ReplicaSet),
1056+
},
1057+
{
1058+
"deploymentUID": "c20a7cf1-a12d-4cee-a87e-7f61aa2bd878",
1059+
"customRoles": CustomRoleEmbedded,
1060+
"externalDomains": ExternalDomainNone,
1061+
"isMultiCluster": false,
1062+
"architecture": string(architectures.NonStatic),
1063+
"IsRunningEnterpriseImage": false,
1064+
"operatorID": testOperatorUUID,
1065+
"type": string(mdbv1.ReplicaSet),
1066+
},
1067+
{
1068+
"deploymentUID": "97822e48-fb51-4ba5-9993-26841b44a7a3",
1069+
"customRoles": CustomRoleReferenced,
1070+
"externalDomains": ExternalDomainNone,
1071+
"isMultiCluster": false,
1072+
"architecture": string(architectures.NonStatic),
1073+
"IsRunningEnterpriseImage": false,
1074+
"operatorID": testOperatorUUID,
1075+
"type": string(mdbv1.ReplicaSet),
1076+
},
1077+
{
1078+
"deploymentUID": "17e352f7-dcd1-4bfa-bc12-a2f4e637477b",
1079+
"customRoles": CustomRoleNone,
1080+
"databaseClusters": float64(0),
1081+
"externalDomains": ExternalDomainNone,
1082+
"isMultiCluster": true,
1083+
"architecture": string(architectures.NonStatic),
1084+
"IsRunningEnterpriseImage": false,
1085+
"operatorID": testOperatorUUID,
1086+
"type": string(mdbv1.ReplicaSet),
1087+
},
1088+
{
1089+
"deploymentUID": "71368077-ea95-4564-acd6-09ec573fdf61",
1090+
"customRoles": CustomRoleEmbedded,
1091+
"databaseClusters": float64(0),
1092+
"externalDomains": ExternalDomainNone,
1093+
"isMultiCluster": true,
1094+
"architecture": string(architectures.NonStatic),
1095+
"IsRunningEnterpriseImage": false,
1096+
"operatorID": testOperatorUUID,
1097+
"type": string(mdbv1.ReplicaSet),
1098+
},
1099+
{
1100+
"deploymentUID": "a8a28c8a-6226-44fc-a8cd-e66a6942ffbd",
1101+
"customRoles": CustomRoleReferenced,
1102+
"databaseClusters": float64(0),
1103+
"externalDomains": ExternalDomainNone,
1104+
"isMultiCluster": true,
1105+
"architecture": string(architectures.NonStatic),
1106+
"IsRunningEnterpriseImage": false,
1107+
"operatorID": testOperatorUUID,
1108+
"type": string(mdbv1.ReplicaSet),
1109+
},
1110+
},
1111+
},
9241112
}
9251113

9261114
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)