diff --git a/receiver/k8sclusterreceiver/documentation.md b/receiver/k8sclusterreceiver/documentation.md index e0b9aa3c8d33..e5d33cde60fe 100644 --- a/receiver/k8sclusterreceiver/documentation.md +++ b/receiver/k8sclusterreceiver/documentation.md @@ -434,6 +434,7 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 | k8s.namespace.name | The k8s namespace name. | Any Str | true | | k8s.namespace.uid | The k8s namespace uid. | Any Str | true | | k8s.node.name | The k8s node name. | Any Str | true | +| k8s.node.start_time | The start time of the Node. | Any Str | true | | k8s.node.uid | The k8s node uid. | Any Str | true | | k8s.pod.name | The k8s pod name. | Any Str | true | | k8s.pod.uid | The k8s pod uid. | Any Str | true | diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go index 7d01f445e462..3cf2d79e43e9 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go @@ -233,6 +233,7 @@ type ResourceAttributesConfig struct { K8sNamespaceName ResourceAttributeConfig `mapstructure:"k8s.namespace.name"` K8sNamespaceUID ResourceAttributeConfig `mapstructure:"k8s.namespace.uid"` K8sNodeName ResourceAttributeConfig `mapstructure:"k8s.node.name"` + K8sNodeStartTime ResourceAttributeConfig `mapstructure:"k8s.node.start_time"` K8sNodeUID ResourceAttributeConfig `mapstructure:"k8s.node.uid"` K8sPodName ResourceAttributeConfig `mapstructure:"k8s.pod.name"` K8sPodUID ResourceAttributeConfig `mapstructure:"k8s.pod.uid"` @@ -311,6 +312,9 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sNodeName: ResourceAttributeConfig{ Enabled: true, }, + K8sNodeStartTime: ResourceAttributeConfig{ + Enabled: true, + }, K8sNodeUID: ResourceAttributeConfig{ Enabled: true, }, diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go index 068d5ac373b5..a04fba5c0ce7 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go @@ -90,6 +90,7 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, K8sNodeUID: ResourceAttributeConfig{Enabled: true}, K8sPodName: ResourceAttributeConfig{Enabled: true}, K8sPodUID: ResourceAttributeConfig{Enabled: true}, @@ -181,6 +182,7 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, K8sNodeUID: ResourceAttributeConfig{Enabled: false}, K8sPodName: ResourceAttributeConfig{Enabled: false}, K8sPodUID: ResourceAttributeConfig{Enabled: false}, @@ -255,6 +257,7 @@ func TestResourceAttributesConfig(t *testing.T) { K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, K8sNodeUID: ResourceAttributeConfig{Enabled: true}, K8sPodName: ResourceAttributeConfig{Enabled: true}, K8sPodUID: ResourceAttributeConfig{Enabled: true}, @@ -298,6 +301,7 @@ func TestResourceAttributesConfig(t *testing.T) { K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, K8sNodeUID: ResourceAttributeConfig{Enabled: false}, K8sPodName: ResourceAttributeConfig{Enabled: false}, K8sPodUID: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go index b1d8c8f40bb6..cbbe1b375e92 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go @@ -248,6 +248,7 @@ func TestMetricsBuilder(t *testing.T) { rb.SetK8sNamespaceName("k8s.namespace.name-val") rb.SetK8sNamespaceUID("k8s.namespace.uid-val") rb.SetK8sNodeName("k8s.node.name-val") + rb.SetK8sNodeStartTime("k8s.node.start_time-val") rb.SetK8sNodeUID("k8s.node.uid-val") rb.SetK8sPodName("k8s.pod.name-val") rb.SetK8sPodUID("k8s.pod.uid-val") diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go index b66824f7a68a..61110fb7b2cb 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go @@ -147,6 +147,13 @@ func (rb *ResourceBuilder) SetK8sNodeName(val string) { } } +// SetK8sNodeStartTime sets provided value as "k8s.node.start_time" attribute. +func (rb *ResourceBuilder) SetK8sNodeStartTime(val string) { + if rb.config.K8sNodeStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.node.start_time", val) + } +} + // SetK8sNodeUID sets provided value as "k8s.node.uid" attribute. func (rb *ResourceBuilder) SetK8sNodeUID(val string) { if rb.config.K8sNodeUID.Enabled { diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go index 1432cb5e44f2..3e4d1edfe5d8 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go @@ -31,6 +31,7 @@ func TestResourceBuilder(t *testing.T) { rb.SetK8sNamespaceName("k8s.namespace.name-val") rb.SetK8sNamespaceUID("k8s.namespace.uid-val") rb.SetK8sNodeName("k8s.node.name-val") + rb.SetK8sNodeStartTime("k8s.node.start_time-val") rb.SetK8sNodeUID("k8s.node.uid-val") rb.SetK8sPodName("k8s.pod.name-val") rb.SetK8sPodUID("k8s.pod.uid-val") @@ -57,9 +58,9 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 38, res.Attributes().Len()) + assert.Equal(t, 39, res.Attributes().Len()) case "all_set": - assert.Equal(t, 38, res.Attributes().Len()) + assert.Equal(t, 39, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -157,6 +158,11 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.node.name-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.node.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.node.start_time-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.node.uid") assert.True(t, ok) if ok { diff --git a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml index aa5fa7edc671..246f61df05d2 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml @@ -126,6 +126,8 @@ all_set: enabled: true k8s.node.name: enabled: true + k8s.node.start_time: + enabled: true k8s.node.uid: enabled: true k8s.pod.name: @@ -293,6 +295,8 @@ none_set: enabled: false k8s.node.name: enabled: false + k8s.node.start_time: + enabled: false k8s.node.uid: enabled: false k8s.pod.name: diff --git a/receiver/k8sclusterreceiver/internal/node/nodes.go b/receiver/k8sclusterreceiver/internal/node/nodes.go index 77b2981647ca..3f4202fc565e 100644 --- a/receiver/k8sclusterreceiver/internal/node/nodes.go +++ b/receiver/k8sclusterreceiver/internal/node/nodes.go @@ -91,6 +91,7 @@ func CustomMetrics(set receiver.CreateSettings, rb *metadata.ResourceBuilder, no rb.SetK8sNodeUID(string(node.UID)) rb.SetK8sNodeName(node.Name) + rb.SetK8sNodeStartTime(node.GetCreationTimestamp().String()) rb.SetOpencensusResourcetype("k8s") rb.Emit().MoveTo(rm.Resource()) return rm diff --git a/receiver/k8sclusterreceiver/metadata.yaml b/receiver/k8sclusterreceiver/metadata.yaml index 27e64a0f0833..6fa059c47afe 100644 --- a/receiver/k8sclusterreceiver/metadata.yaml +++ b/receiver/k8sclusterreceiver/metadata.yaml @@ -70,6 +70,11 @@ resource_attributes: type: string enabled: true + k8s.node.start_time: + description: "The start time of the Node." + enabled: true + type: string + container.id: description: The container id. type: string diff --git a/receiver/kubeletstatsreceiver/documentation.md b/receiver/kubeletstatsreceiver/documentation.md index 5cec54d9d530..d8568719bf44 100644 --- a/receiver/kubeletstatsreceiver/documentation.md +++ b/receiver/kubeletstatsreceiver/documentation.md @@ -424,7 +424,8 @@ The time since the pod started | k8s.container.name | Container name used by container runtime | Any Str | true | | k8s.namespace.name | The name of the namespace that the pod is running in | Any Str | true | | k8s.node.name | The name of the Node | Any Str | true | -| k8s.node.uid | The UID of the Node | Any Str | false | +| k8s.node.start_time | The start time of the Node. | Any Str | true | +| k8s.node.uid | The UID of the Node | Any Str | true | | k8s.persistentvolumeclaim.name | The name of the Persistent Volume Claim | Any Str | true | | k8s.pod.name | The name of the Pod | Any Str | true | | k8s.pod.uid | The UID of the Pod | Any Str | true | diff --git a/receiver/kubeletstatsreceiver/internal/kubelet/accumulator.go b/receiver/kubeletstatsreceiver/internal/kubelet/accumulator.go index 24a670825bdc..efb6acb122d2 100644 --- a/receiver/kubeletstatsreceiver/internal/kubelet/accumulator.go +++ b/receiver/kubeletstatsreceiver/internal/kubelet/accumulator.go @@ -66,8 +66,8 @@ func (a *metricDataAccumulator) nodeStats(s stats.NodeStats) { // todo s.Runtime.ImageFs rb := a.mbs.NodeMetricsBuilder.NewResourceBuilder() rb.SetK8sNodeName(s.NodeName) - rb.SetK8sNodeName(s.NodeName) rb.SetK8sNodeUID(a.getNodeUID(s.NodeName)) + rb.SetK8sNodeStartTime(s.StartTime.Time.String()) a.m = append(a.m, a.mbs.NodeMetricsBuilder.Emit( metadata.WithStartTimeOverride(pcommon.NewTimestampFromTime(s.StartTime.Time)), metadata.WithResource(rb.Emit()), diff --git a/receiver/kubeletstatsreceiver/internal/metadata/generated_config.go b/receiver/kubeletstatsreceiver/internal/metadata/generated_config.go index 64bebf1c52f1..8ac4b50ce02a 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/kubeletstatsreceiver/internal/metadata/generated_config.go @@ -229,6 +229,7 @@ type ResourceAttributesConfig struct { K8sContainerName ResourceAttributeConfig `mapstructure:"k8s.container.name"` K8sNamespaceName ResourceAttributeConfig `mapstructure:"k8s.namespace.name"` K8sNodeName ResourceAttributeConfig `mapstructure:"k8s.node.name"` + K8sNodeStartTime ResourceAttributeConfig `mapstructure:"k8s.node.start_time"` K8sNodeUID ResourceAttributeConfig `mapstructure:"k8s.node.uid"` K8sPersistentvolumeclaimName ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.name"` K8sPodName ResourceAttributeConfig `mapstructure:"k8s.pod.name"` @@ -272,8 +273,11 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sNodeName: ResourceAttributeConfig{ Enabled: true, }, + K8sNodeStartTime: ResourceAttributeConfig{ + Enabled: true, + }, K8sNodeUID: ResourceAttributeConfig{ - Enabled: false, + Enabled: true, }, K8sPersistentvolumeclaimName: ResourceAttributeConfig{ Enabled: true, diff --git a/receiver/kubeletstatsreceiver/internal/metadata/generated_config_test.go b/receiver/kubeletstatsreceiver/internal/metadata/generated_config_test.go index 4d7a1776cc3b..b7d06ab338f4 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/generated_config_test.go +++ b/receiver/kubeletstatsreceiver/internal/metadata/generated_config_test.go @@ -83,6 +83,7 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sContainerName: ResourceAttributeConfig{Enabled: true}, K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, K8sNodeUID: ResourceAttributeConfig{Enabled: true}, K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, K8sPodName: ResourceAttributeConfig{Enabled: true}, @@ -156,6 +157,7 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sContainerName: ResourceAttributeConfig{Enabled: false}, K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, K8sNodeUID: ResourceAttributeConfig{Enabled: false}, K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: false}, K8sPodName: ResourceAttributeConfig{Enabled: false}, @@ -211,6 +213,7 @@ func TestResourceAttributesConfig(t *testing.T) { K8sContainerName: ResourceAttributeConfig{Enabled: true}, K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, K8sNodeUID: ResourceAttributeConfig{Enabled: true}, K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, K8sPodName: ResourceAttributeConfig{Enabled: true}, @@ -235,6 +238,7 @@ func TestResourceAttributesConfig(t *testing.T) { K8sContainerName: ResourceAttributeConfig{Enabled: false}, K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, K8sNodeUID: ResourceAttributeConfig{Enabled: false}, K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: false}, K8sPodName: ResourceAttributeConfig{Enabled: false}, diff --git a/receiver/kubeletstatsreceiver/internal/metadata/generated_metrics_test.go b/receiver/kubeletstatsreceiver/internal/metadata/generated_metrics_test.go index f6f1bbe145a8..8cb04a401cfc 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/kubeletstatsreceiver/internal/metadata/generated_metrics_test.go @@ -242,6 +242,7 @@ func TestMetricsBuilder(t *testing.T) { rb.SetK8sContainerName("k8s.container.name-val") rb.SetK8sNamespaceName("k8s.namespace.name-val") rb.SetK8sNodeName("k8s.node.name-val") + rb.SetK8sNodeStartTime("k8s.node.start_time-val") rb.SetK8sNodeUID("k8s.node.uid-val") rb.SetK8sPersistentvolumeclaimName("k8s.persistentvolumeclaim.name-val") rb.SetK8sPodName("k8s.pod.name-val") diff --git a/receiver/kubeletstatsreceiver/internal/metadata/generated_resource.go b/receiver/kubeletstatsreceiver/internal/metadata/generated_resource.go index 61c85123d21c..f69549a5f99e 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/generated_resource.go +++ b/receiver/kubeletstatsreceiver/internal/metadata/generated_resource.go @@ -91,6 +91,13 @@ func (rb *ResourceBuilder) SetK8sNodeName(val string) { } } +// SetK8sNodeStartTime sets provided value as "k8s.node.start_time" attribute. +func (rb *ResourceBuilder) SetK8sNodeStartTime(val string) { + if rb.config.K8sNodeStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.node.start_time", val) + } +} + // SetK8sNodeUID sets provided value as "k8s.node.uid" attribute. func (rb *ResourceBuilder) SetK8sNodeUID(val string) { if rb.config.K8sNodeUID.Enabled { diff --git a/receiver/kubeletstatsreceiver/internal/metadata/generated_resource_test.go b/receiver/kubeletstatsreceiver/internal/metadata/generated_resource_test.go index f1b3263c8eac..58b680e0f139 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/kubeletstatsreceiver/internal/metadata/generated_resource_test.go @@ -23,6 +23,7 @@ func TestResourceBuilder(t *testing.T) { rb.SetK8sContainerName("k8s.container.name-val") rb.SetK8sNamespaceName("k8s.namespace.name-val") rb.SetK8sNodeName("k8s.node.name-val") + rb.SetK8sNodeStartTime("k8s.node.start_time-val") rb.SetK8sNodeUID("k8s.node.uid-val") rb.SetK8sPersistentvolumeclaimName("k8s.persistentvolumeclaim.name-val") rb.SetK8sPodName("k8s.pod.name-val") @@ -38,9 +39,9 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 18, res.Attributes().Len()) + assert.Equal(t, 20, res.Attributes().Len()) case "all_set": - assert.Equal(t, 19, res.Attributes().Len()) + assert.Equal(t, 20, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -98,8 +99,13 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.node.name-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.node.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.node.start_time-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.node.uid") - assert.Equal(t, test == "all_set", ok) + assert.True(t, ok) if ok { assert.EqualValues(t, "k8s.node.uid-val", val.Str()) } diff --git a/receiver/kubeletstatsreceiver/internal/metadata/testdata/config.yaml b/receiver/kubeletstatsreceiver/internal/metadata/testdata/config.yaml index 3650948b2e1b..0139a4fb32ff 100644 --- a/receiver/kubeletstatsreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/kubeletstatsreceiver/internal/metadata/testdata/config.yaml @@ -112,6 +112,8 @@ all_set: enabled: true k8s.node.name: enabled: true + k8s.node.start_time: + enabled: true k8s.node.uid: enabled: true k8s.persistentvolumeclaim.name: @@ -185,7 +187,7 @@ none_set: k8s.node.uptime: enabled: false k8s.pod.cpu.time: - enabled: true + enabled: false k8s.pod.cpu.utilization: enabled: false k8s.pod.filesystem.available: @@ -243,6 +245,8 @@ none_set: enabled: false k8s.node.name: enabled: false + k8s.node.start_time: + enabled: false k8s.node.uid: enabled: false k8s.persistentvolumeclaim.name: diff --git a/receiver/kubeletstatsreceiver/metadata.yaml b/receiver/kubeletstatsreceiver/metadata.yaml index d134a29cace9..bc009c848a06 100644 --- a/receiver/kubeletstatsreceiver/metadata.yaml +++ b/receiver/kubeletstatsreceiver/metadata.yaml @@ -17,6 +17,10 @@ resource_attributes: description: "The name of the Node" enabled: true type: string + k8s.node.start_time: + description: "The start time of the Node." + enabled: true + type: string k8s.pod.uid: description: "The UID of the Pod" enabled: true