Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/k8scluster] Fix empty k8s.namespace.name in k8s.namespace.phase metrics #23453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/k8scluster-fix-empty-namespace-in-namespacephase.yaml
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +21,4 @@ resourceMetrics:
unit: "1"
scope:
name: otelcol/k8sclusterreceiver
version: latest
version: latest
10 changes: 5 additions & 5 deletions receiver/k8sclusterreceiver/testdata/e2e/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down