Skip to content

Commit

Permalink
Fix empty namespace name
Browse files Browse the repository at this point in the history
  • Loading branch information
eplightning committed Jun 19, 2023
1 parent 5fff104 commit 07d3fb1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
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

0 comments on commit 07d3fb1

Please sign in to comment.