From 7a1061d300e8fa990849bfcb2d4a2863ceebc44c Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 27 Jun 2023 11:58:42 -0700 Subject: [PATCH] [chore] fix pod and container metadata to include parent and units (#23795) **Description:** Add parent information to pod and container metadata. **Link to tracking Issue:** Fixes #23793 --- .../internal/container/documentation.md | 18 ++++++++++-------- .../internal/metadata/generated_metrics.go | 16 ++++++++-------- .../metadata/generated_metrics_test.go | 16 ++++++++-------- .../internal/container/metadata.yaml | 10 ++++++++++ .../internal/pod/documentation.md | 2 ++ .../internal/pod/metadata.yaml | 2 ++ .../internal/pod/testdata/expected.yaml | 2 ++ .../testdata/e2e/expected.yaml | 19 +++++++++++++++++++ 8 files changed, 61 insertions(+), 24 deletions(-) diff --git a/receiver/k8sclusterreceiver/internal/container/documentation.md b/receiver/k8sclusterreceiver/internal/container/documentation.md index e158ff92f3e3..b0994c761c88 100644 --- a/receiver/k8sclusterreceiver/internal/container/documentation.md +++ b/receiver/k8sclusterreceiver/internal/container/documentation.md @@ -2,6 +2,8 @@ # k8s/container +**Parent Component:** k8s_cluster + ## Default Metrics The following metrics are emitted by default. Each of them can be disabled by applying the following configuration: @@ -18,7 +20,7 @@ Maximum resource limit set for the container. See https://kubernetes.io/docs/ref | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Double | +| {cpu} | Gauge | Double | ### k8s.container.cpu_request @@ -26,7 +28,7 @@ Resource requested for the container. See https://kubernetes.io/docs/reference/g | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Double | +| {cpu} | Gauge | Double | ### k8s.container.ephemeralstorage_limit @@ -34,7 +36,7 @@ Maximum resource limit set for the container. See https://kubernetes.io/docs/ref | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ### k8s.container.ephemeralstorage_request @@ -42,7 +44,7 @@ Resource requested for the container. See https://kubernetes.io/docs/reference/g | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ### k8s.container.memory_limit @@ -50,7 +52,7 @@ Maximum resource limit set for the container. See https://kubernetes.io/docs/ref | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ### k8s.container.memory_request @@ -58,7 +60,7 @@ Resource requested for the container. See https://kubernetes.io/docs/reference/g | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ### k8s.container.ready @@ -82,7 +84,7 @@ Maximum resource limit set for the container. See https://kubernetes.io/docs/ref | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ### k8s.container.storage_request @@ -90,7 +92,7 @@ Resource requested for the container. See https://kubernetes.io/docs/reference/g | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| | Gauge | Int | +| By | Gauge | Int | ## Resource Attributes diff --git a/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics.go b/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics.go index 7be82830ee02..5f83bdbf6a28 100644 --- a/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics.go +++ b/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics.go @@ -22,7 +22,7 @@ type metricK8sContainerCPULimit struct { func (m *metricK8sContainerCPULimit) init() { m.data.SetName("k8s.container.cpu_limit") m.data.SetDescription("Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("{cpu}") m.data.SetEmptyGauge() } @@ -71,7 +71,7 @@ type metricK8sContainerCPURequest struct { func (m *metricK8sContainerCPURequest) init() { m.data.SetName("k8s.container.cpu_request") m.data.SetDescription("Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("{cpu}") m.data.SetEmptyGauge() } @@ -120,7 +120,7 @@ type metricK8sContainerEphemeralstorageLimit struct { func (m *metricK8sContainerEphemeralstorageLimit) init() { m.data.SetName("k8s.container.ephemeralstorage_limit") m.data.SetDescription("Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } @@ -169,7 +169,7 @@ type metricK8sContainerEphemeralstorageRequest struct { func (m *metricK8sContainerEphemeralstorageRequest) init() { m.data.SetName("k8s.container.ephemeralstorage_request") m.data.SetDescription("Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } @@ -218,7 +218,7 @@ type metricK8sContainerMemoryLimit struct { func (m *metricK8sContainerMemoryLimit) init() { m.data.SetName("k8s.container.memory_limit") m.data.SetDescription("Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } @@ -267,7 +267,7 @@ type metricK8sContainerMemoryRequest struct { func (m *metricK8sContainerMemoryRequest) init() { m.data.SetName("k8s.container.memory_request") m.data.SetDescription("Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } @@ -414,7 +414,7 @@ type metricK8sContainerStorageLimit struct { func (m *metricK8sContainerStorageLimit) init() { m.data.SetName("k8s.container.storage_limit") m.data.SetDescription("Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } @@ -463,7 +463,7 @@ type metricK8sContainerStorageRequest struct { func (m *metricK8sContainerStorageRequest) init() { m.data.SetName("k8s.container.storage_request") m.data.SetDescription("Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details") - m.data.SetUnit("") + m.data.SetUnit("By") m.data.SetEmptyGauge() } diff --git a/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics_test.go b/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics_test.go index 1112031c81d8..bd7418e1225a 100644 --- a/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics_test.go +++ b/receiver/k8sclusterreceiver/internal/container/internal/metadata/generated_metrics_test.go @@ -188,7 +188,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "{cpu}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -200,7 +200,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "{cpu}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -212,7 +212,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -224,7 +224,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -236,7 +236,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -248,7 +248,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -284,7 +284,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) @@ -296,7 +296,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) + assert.Equal(t, "By", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) diff --git a/receiver/k8sclusterreceiver/internal/container/metadata.yaml b/receiver/k8sclusterreceiver/internal/container/metadata.yaml index c818e51b63a2..c50b4b81f7a9 100644 --- a/receiver/k8sclusterreceiver/internal/container/metadata.yaml +++ b/receiver/k8sclusterreceiver/internal/container/metadata.yaml @@ -2,6 +2,8 @@ type: k8s/container sem_conv_version: 1.18.0 +parent: k8s_cluster + resource_attributes: container.id: description: The container id. @@ -52,41 +54,49 @@ metrics: k8s.container.cpu_request: enabled: true description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "{cpu}" gauge: value_type: double k8s.container.cpu_limit: enabled: true description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "{cpu}" gauge: value_type: double k8s.container.memory_request: enabled: true description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.memory_limit: enabled: true description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.storage_request: enabled: true description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.storage_limit: enabled: true description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.ephemeralstorage_request: enabled: true description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.ephemeralstorage_limit: enabled: true description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + unit: "By" gauge: value_type: int k8s.container.restarts: diff --git a/receiver/k8sclusterreceiver/internal/pod/documentation.md b/receiver/k8sclusterreceiver/internal/pod/documentation.md index 36b16d19bfc2..09afa7c3cea4 100644 --- a/receiver/k8sclusterreceiver/internal/pod/documentation.md +++ b/receiver/k8sclusterreceiver/internal/pod/documentation.md @@ -2,6 +2,8 @@ # k8s/pod +**Parent Component:** k8s_cluster + ## Default Metrics The following metrics are emitted by default. Each of them can be disabled by applying the following configuration: diff --git a/receiver/k8sclusterreceiver/internal/pod/metadata.yaml b/receiver/k8sclusterreceiver/internal/pod/metadata.yaml index 5de46d6246a7..a4c3c0802c13 100644 --- a/receiver/k8sclusterreceiver/internal/pod/metadata.yaml +++ b/receiver/k8sclusterreceiver/internal/pod/metadata.yaml @@ -2,6 +2,8 @@ type: k8s/pod sem_conv_version: 1.18.0 +parent: k8s_cluster + resource_attributes: k8s.namespace.name: description: The k8s namespace name. diff --git a/receiver/k8sclusterreceiver/internal/pod/testdata/expected.yaml b/receiver/k8sclusterreceiver/internal/pod/testdata/expected.yaml index 96b350d4d4c1..867335f49063 100644 --- a/receiver/k8sclusterreceiver/internal/pod/testdata/expected.yaml +++ b/receiver/k8sclusterreceiver/internal/pod/testdata/expected.yaml @@ -77,11 +77,13 @@ resourceMetrics: dataPoints: - asDouble: 10 name: k8s.container.cpu_request + unit: "{cpu}" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asDouble: 20 name: k8s.container.cpu_limit + unit: "{cpu}" scope: name: otelcol/k8sclusterreceiver version: latest \ No newline at end of file diff --git a/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml index 9c5b5a19c8bc..0d804d8e2e1e 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml @@ -780,12 +780,14 @@ resourceMetrics: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "104857600" timeUnixNano: "1686772769034865545" name: k8s.container.memory_request + unit: "By" scope: name: otelcol/k8sclusterreceiver version: latest @@ -841,24 +843,28 @@ resourceMetrics: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "52428800" timeUnixNano: "1686772769034865545" name: k8s.container.memory_request + unit: "By" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_limit + unit: "{cpu}" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "52428800" timeUnixNano: "1686772769034865545" name: k8s.container.memory_limit + unit: "By" scope: name: otelcol/k8sclusterreceiver version: latest @@ -914,6 +920,7 @@ resourceMetrics: - asDouble: 0.25 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" scope: name: otelcol/k8sclusterreceiver version: latest @@ -969,6 +976,7 @@ resourceMetrics: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" scope: name: otelcol/k8sclusterreceiver version: latest @@ -1024,6 +1032,7 @@ resourceMetrics: - asDouble: 0.2 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" scope: name: otelcol/k8sclusterreceiver version: latest @@ -1128,18 +1137,21 @@ resourceMetrics: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "73400320" timeUnixNano: "1686772769034865545" name: k8s.container.memory_request + unit: "By" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "178257920" timeUnixNano: "1686772769034865545" name: k8s.container.memory_limit + unit: "By" scope: name: otelcol/k8sclusterreceiver version: latest @@ -1195,24 +1207,28 @@ resourceMetrics: - asInt: "268435456" timeUnixNano: "1686772769034865545" name: k8s.container.memory_request + unit: "By" - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asDouble: 0.128 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asDouble: 0.128 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_limit + unit: "{cpu}" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "268435456" timeUnixNano: "1686772769034865545" name: k8s.container.memory_limit + unit: "By" scope: name: otelcol/k8sclusterreceiver version: latest @@ -1317,18 +1333,21 @@ resourceMetrics: - asDouble: 0.1 timeUnixNano: "1686772769034865545" name: k8s.container.cpu_request + unit: "{cpu}" - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "73400320" timeUnixNano: "1686772769034865545" name: k8s.container.memory_request + unit: "By" - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details gauge: dataPoints: - asInt: "178257920" timeUnixNano: "1686772769034865545" name: k8s.container.memory_limit + unit: "By" scope: name: otelcol/k8sclusterreceiver version: latest