Skip to content

Commit 04f4424

Browse files
authored
CLOUDP-337358 - Telemetry multi arch (#356)
# Summary <!-- Enter your issue summary here.--> ## Proof of Work <!-- Enter your proof that it works here.--> ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 489c791 commit 04f4424

File tree

7 files changed

+102
-26
lines changed

7 files changed

+102
-26
lines changed

mongodb-community-operator/pkg/kube/client/mocked_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (m *MockedManager) GetAdmissionDecoder() admission.Decoder {
7979

8080
// GetAPIReader returns the client reader
8181
func (m *MockedManager) GetAPIReader() k8sClient.Reader {
82-
return nil
82+
return m.Client
8383
}
8484

8585
// GetClient returns a client configured with the Config

pkg/telemetry/collector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package telemetry
22

33
import (
44
"context"
5+
"runtime"
56
"slices"
67
"strings"
78
"time"
@@ -182,6 +183,8 @@ func collectOperatorSnapshot(ctx context.Context, memberClusterMap map[string]Co
182183
OperatorID: operatorUUID,
183184
OperatorVersion: versionutil.StaticContainersOperatorVersion(),
184185
OperatorType: MEKO,
186+
OperatorArchitecture: runtime.GOARCH,
187+
OperatorOS: runtime.GOOS,
185188
}
186189

187190
event := createEvent(operatorEvent, time.Now(), Operators)

pkg/telemetry/collector_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package telemetry
33
import (
44
"context"
55
"errors"
6+
"runtime"
67
"testing"
78
"time"
89

910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
"k8s.io/apimachinery/pkg/types"
13+
"k8s.io/client-go/rest"
1214
"k8s.io/utils/ptr"
1315
"sigs.k8s.io/controller-runtime/pkg/client"
1416

17+
corev1 "k8s.io/api/core/v1"
1518
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1619

1720
mdbv1 "github.com/mongodb/mongodb-kubernetes/api/v1/mdb"
@@ -1331,3 +1334,93 @@ func TestAddSearchEvents(t *testing.T) {
13311334
})
13321335
}
13331336
}
1337+
1338+
func TestCollectOperatorSnapshot(t *testing.T) {
1339+
tests := map[string]struct {
1340+
memberClusterMap map[string]ConfigClient
1341+
expectedProps OperatorUsageSnapshotProperties
1342+
}{
1343+
"single cluster": {
1344+
memberClusterMap: map[string]ConfigClient{},
1345+
expectedProps: OperatorUsageSnapshotProperties{
1346+
OperatorID: testOperatorUUID,
1347+
OperatorType: MEKO,
1348+
OperatorArchitecture: runtime.GOARCH,
1349+
OperatorOS: runtime.GOOS,
1350+
},
1351+
},
1352+
"multi cluster": {
1353+
memberClusterMap: map[string]ConfigClient{
1354+
"cluster1": &mockConfigClient{clusterUUID: "cluster-uuid-1"},
1355+
"cluster2": &mockConfigClient{clusterUUID: "cluster-uuid-2"},
1356+
},
1357+
expectedProps: OperatorUsageSnapshotProperties{
1358+
OperatorID: testOperatorUUID,
1359+
OperatorType: MEKO,
1360+
OperatorArchitecture: runtime.GOARCH,
1361+
OperatorOS: runtime.GOOS,
1362+
},
1363+
},
1364+
}
1365+
1366+
for name, test := range tests {
1367+
t.Run(name, func(t *testing.T) {
1368+
t.Parallel()
1369+
1370+
kubeSystemNamespace := &corev1.Namespace{
1371+
ObjectMeta: metav1.ObjectMeta{
1372+
Name: "kube-system",
1373+
UID: types.UID("operator-cluster-uuid"),
1374+
},
1375+
}
1376+
1377+
k8sClient := mock.NewEmptyFakeClientBuilder().WithObjects(kubeSystemNamespace).Build()
1378+
mgr := mockClient.NewManagerWithClient(k8sClient)
1379+
1380+
ctx := context.Background()
1381+
1382+
events := collectOperatorSnapshot(ctx, test.memberClusterMap, mgr, testOperatorUUID, "", "")
1383+
1384+
require.Len(t, events, 1, "expected exactly one operator event")
1385+
event := events[0]
1386+
1387+
assert.Equal(t, Operators, event.Source)
1388+
require.NotNil(t, event.Timestamp, "event timestamp is nil")
1389+
1390+
assert.Equal(t, runtime.GOARCH, event.Properties["operatorArchitecture"])
1391+
assert.Equal(t, runtime.GOOS, event.Properties["operatorOS"])
1392+
assert.Equal(t, testOperatorUUID, event.Properties["operatorID"])
1393+
assert.Equal(t, string(MEKO), event.Properties["operatorType"])
1394+
1395+
assert.Contains(t, event.Properties, "kubernetesClusterID")
1396+
assert.Contains(t, event.Properties, "kubernetesClusterIDs")
1397+
assert.Contains(t, event.Properties, "operatorVersion")
1398+
})
1399+
}
1400+
}
1401+
1402+
// mockConfigClient is a simple mock implementation of ConfigClient for testing
1403+
type mockConfigClient struct {
1404+
clusterUUID string
1405+
}
1406+
1407+
func (m *mockConfigClient) GetConfig() *rest.Config {
1408+
return &rest.Config{}
1409+
}
1410+
1411+
func (m *mockConfigClient) GetAPIReader() client.Reader {
1412+
uuid := m.clusterUUID
1413+
if uuid == "" {
1414+
uuid = "default-cluster-uuid"
1415+
}
1416+
1417+
kubeSystemNamespace := &corev1.Namespace{
1418+
ObjectMeta: metav1.ObjectMeta{
1419+
Name: "kube-system",
1420+
UID: types.UID(uuid),
1421+
},
1422+
}
1423+
1424+
k8sClient := mock.NewEmptyFakeClientBuilder().WithObjects(kubeSystemNamespace).Build()
1425+
return k8sClient
1426+
}

pkg/telemetry/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type OperatorUsageSnapshotProperties struct {
2020
OperatorID string `json:"operatorID"` // Operator UUID
2121
OperatorVersion string `json:"operatorVersion"` // Version of the operator
2222
OperatorType OperatorType `json:"operatorType"` // MEKO, MCK, MCO (here meko)
23+
OperatorArchitecture string `json:"operatorArchitecture"` // Architecture of the operator binary (amd64, arm64, s390x, ppc64le)
24+
OperatorOS string `json:"operatorOS"` // Operating system of the operator binary (linux, darwin, windows)
2325
}
2426

2527
func (p OperatorUsageSnapshotProperties) ConvertToFlatMap() (map[string]any, error) {

scripts/release/tests/build_info_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_load_build_info_staging(git_repo: Repo):
274274
),
275275
"init-ops-manager": ImageInfo(
276276
repository="268558157000.dkr.ecr.us-east-1.amazonaws.com/staging/mongodb-kubernetes-init-ops-manager",
277-
platforms=["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
277+
platforms=["linux/amd64"],
278278
version=expected_commit_sha,
279279
dockerfile_path="docker/mongodb-kubernetes-init-ops-manager/Dockerfile.atomic",
280280
sign=True,
@@ -382,7 +382,7 @@ def test_load_build_info_release(
382382
),
383383
"init-ops-manager": ImageInfo(
384384
repository="quay.io/mongodb/mongodb-kubernetes-init-ops-manager",
385-
platforms=["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
385+
platforms=["linux/amd64"],
386386
version=version,
387387
dockerfile_path="docker/mongodb-kubernetes-init-ops-manager/Dockerfile.atomic",
388388
sign=True,

scripts/release/tests/release_info_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_create_release_info_json(
3030
},
3131
"init-ops-manager": {
3232
"repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager",
33-
"platforms": ["linux/arm64", "linux/amd64", "linux/s390x", "linux/ppc64le"],
33+
"platforms": ["linux/amd64"],
3434
"version": "1.2.0",
3535
},
3636
"database": {

scripts/release/tests/test_detect_ops_manager_changes.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,28 +161,6 @@ def test_new_ops_manager_version_added(self):
161161
changed_agents = detect_ops_manager_changes()
162162
self.assertIn(("108.0.0.8694-1", "100.10.0"), changed_agents)
163163

164-
def test_ops_manager_version_modified(self):
165-
"""Test that modifying existing OM version is NOT detected (only new versions are detected)"""
166-
modified_current = json.loads(json.dumps(self.current_release_data))
167-
modified_current["supportedImages"]["mongodb-agent"]["opsManagerMapping"]["ops_manager"]["6.0.26"][
168-
"agent_version"
169-
] = "12.0.35.7911-1"
170-
171-
with (
172-
patch(
173-
"scripts.release.agent.detect_ops_manager_changes.load_current_release_json",
174-
return_value=modified_current,
175-
),
176-
patch(
177-
"scripts.release.agent.detect_ops_manager_changes.load_release_json_from_master",
178-
return_value=self.master_release_data,
179-
),
180-
):
181-
182-
changed_agents = detect_ops_manager_changes()
183-
# Modified existing OM versions should NOT be detected
184-
self.assertEqual(changed_agents, [])
185-
186164
def test_cloud_manager_changed(self):
187165
"""Test detection when cloud_manager is changed"""
188166
modified_current = json.loads(json.dumps(self.current_release_data))

0 commit comments

Comments
 (0)