From 07d3fb1f211c0379a5cc4347e101a01488d40336 Mon Sep 17 00:00:00 2001 From: Bartosz Slawianowski Date: Mon, 19 Jun 2023 15:10:36 +0200 Subject: [PATCH] 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