From 07d3fb1f211c0379a5cc4347e101a01488d40336 Mon Sep 17 00:00:00 2001 From: Bartosz Slawianowski Date: Mon, 19 Jun 2023 15:10:36 +0200 Subject: [PATCH 1/2] Fix empty namespace name --- ...fix-empty-namespace-in-namespacephase.yaml | 20 +++++++++++++++++++ .../internal/namespace/namespaces.go | 2 +- .../internal/namespace/namespaces_test.go | 5 ++--- .../internal/namespace/testdata/expected.yaml | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .chloggen/k8scluster-fix-empty-namespace-in-namespacephase.yaml diff --git a/.chloggen/k8scluster-fix-empty-namespace-in-namespacephase.yaml b/.chloggen/k8scluster-fix-empty-namespace-in-namespacephase.yaml new file mode 100644 index 000000000000..8cea0c62ab75 --- /dev/null +++ b/.chloggen/k8scluster-fix-empty-namespace-in-namespacephase.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: k8sclusterreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix empty k8s.namespace.name attribute in k8s.namespace.phase metric + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [23452] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/receiver/k8sclusterreceiver/internal/namespace/namespaces.go b/receiver/k8sclusterreceiver/internal/namespace/namespaces.go index 833f4d4f9087..fd7b22b18ee8 100644 --- a/receiver/k8sclusterreceiver/internal/namespace/namespaces.go +++ b/receiver/k8sclusterreceiver/internal/namespace/namespaces.go @@ -18,7 +18,7 @@ func GetMetrics(set receiver.CreateSettings, ns *corev1.Namespace) pmetric.Metri mb := imetadata.NewMetricsBuilder(imetadata.DefaultMetricsBuilderConfig(), set) ts := pcommon.NewTimestampFromTime(time.Now()) mb.RecordK8sNamespacePhaseDataPoint(ts, int64(namespacePhaseValues[ns.Status.Phase])) - return mb.Emit(imetadata.WithK8sNamespaceUID(string(ns.UID)), imetadata.WithK8sNamespaceName(ns.Namespace), imetadata.WithOpencensusResourcetype("k8s")) + return mb.Emit(imetadata.WithK8sNamespaceUID(string(ns.UID)), imetadata.WithK8sNamespaceName(ns.Name), imetadata.WithOpencensusResourcetype("k8s")) } var namespacePhaseValues = map[corev1.NamespacePhase]int32{ diff --git a/receiver/k8sclusterreceiver/internal/namespace/namespaces_test.go b/receiver/k8sclusterreceiver/internal/namespace/namespaces_test.go index 7c839aa756e9..b01b1380eede 100644 --- a/receiver/k8sclusterreceiver/internal/namespace/namespaces_test.go +++ b/receiver/k8sclusterreceiver/internal/namespace/namespaces_test.go @@ -36,9 +36,8 @@ func TestNamespaceMetrics(t *testing.T) { func newNamespace(id string) *corev1.Namespace { return &corev1.Namespace{ ObjectMeta: v1.ObjectMeta{ - Name: "test-namespace-" + id, - Namespace: "test-namespace", - UID: types.UID("test-namespace-" + id + "-uid"), + Name: "test-namespace-" + id, + UID: types.UID("test-namespace-" + id + "-uid"), Labels: map[string]string{ "foo": "bar", "foo1": "", diff --git a/receiver/k8sclusterreceiver/internal/namespace/testdata/expected.yaml b/receiver/k8sclusterreceiver/internal/namespace/testdata/expected.yaml index 088d622a2ea6..5956e840ce49 100644 --- a/receiver/k8sclusterreceiver/internal/namespace/testdata/expected.yaml +++ b/receiver/k8sclusterreceiver/internal/namespace/testdata/expected.yaml @@ -3,7 +3,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: test-namespace + stringValue: test-namespace-1 - key: k8s.namespace.uid value: stringValue: test-namespace-1-uid @@ -21,4 +21,4 @@ resourceMetrics: unit: "1" scope: name: otelcol/k8sclusterreceiver - version: latest \ No newline at end of file + version: latest From 975790c3c9af25ce718a1b695a7ec1a25f0be516 Mon Sep 17 00:00:00 2001 From: Bartosz Slawianowski Date: Mon, 19 Jun 2023 18:30:09 +0200 Subject: [PATCH 2/2] Add missing namespace names in E2E test --- receiver/k8sclusterreceiver/testdata/e2e/expected.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml index d89fd2fc9ad8..be1e0dbfe305 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml @@ -3,7 +3,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: "" + stringValue: kube-system - key: k8s.namespace.uid value: stringValue: 3604b135-20f2-404b-9c1a-175ef649793e @@ -27,7 +27,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: "" + stringValue: local-path-storage - key: k8s.namespace.uid value: stringValue: 414da07d-33d0-4043-ae7c-d6b264d134e5 @@ -51,7 +51,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: "" + stringValue: kube-public - key: k8s.namespace.uid value: stringValue: 7516afba-1597-49e3-8569-9732b7b94865 @@ -75,7 +75,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: "" + stringValue: kube-node-lease - key: k8s.namespace.uid value: stringValue: 8dd32894-d0ff-4cff-bd75-b818c20fc72b @@ -99,7 +99,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: "" + stringValue: default - key: k8s.namespace.uid value: stringValue: caa467a2-d3e8-4e66-8b76-a155464bac79