From 1e6a1245840bc2fee8ead0f4e565c6d78473f78f Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Fri, 26 May 2023 17:54:34 +0100 Subject: [PATCH 1/2] adding renamed cpu_utilization metric --- .chloggen/change_cpu_percentage_naming.yaml | 26 ++++++++ receiver/dockerstatsreceiver/README.md | 34 +++++++++++ receiver/dockerstatsreceiver/documentation.md | 20 ++++++- .../internal/metadata/generated_config.go | 10 +++- .../metadata/generated_config_test.go | 2 + .../internal/metadata/generated_metrics.go | 59 ++++++++++++++++++- .../metadata/generated_metrics_test.go | 17 +++++- .../internal/metadata/testdata/config.yaml | 4 ++ receiver/dockerstatsreceiver/metadata.yaml | 8 ++- receiver/dockerstatsreceiver/receiver.go | 1 + .../mock/cgroups_v2/expected_metrics.yaml | 2 +- .../mock/no_pids_stats/expected_metrics.yaml | 2 +- .../mock/pids_stats_max/expected_metrics.yaml | 2 +- .../single_container/expected_metrics.yaml | 2 +- .../mock/two_containers/expected_metrics.yaml | 4 +- 15 files changed, 180 insertions(+), 13 deletions(-) create mode 100755 .chloggen/change_cpu_percentage_naming.yaml diff --git a/.chloggen/change_cpu_percentage_naming.yaml b/.chloggen/change_cpu_percentage_naming.yaml new file mode 100755 index 000000000000..accd9e02162b --- /dev/null +++ b/.chloggen/change_cpu_percentage_naming.yaml @@ -0,0 +1,26 @@ +# 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: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: dockerstatsreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "cpu.container.percent metric will be deprecated in v0.79.0 in favor of container.cpu.utilization" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [21807] + +# (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: | + This starts the process of phasing out incorrect metric name: + - `container.cpu.utilization` + and replacing it with the names adhering to the semantic conventions: + - `container.cpu.percent` + At this stage, the new metric is added, but is disabled by default. + See the "Deprecations" section of the Docker Stats receiver's README for details. diff --git a/receiver/dockerstatsreceiver/README.md b/receiver/dockerstatsreceiver/README.md index a407460f2062..bcc5c77d0610 100644 --- a/receiver/dockerstatsreceiver/README.md +++ b/receiver/dockerstatsreceiver/README.md @@ -70,6 +70,40 @@ receivers: The full list of settings exposed for this receiver are documented [here](./config.go) with detailed sample configurations [here](./testdata/config.yaml). +## Deprecations + +### Transition to cpu utilization metric name aligned with OpenTelemetry specification + +The Docker Stats receiver has been emitting the following cpu memory metric: + +- [container.cpu.percent] for the percentage of CPU used by the container, + +This is in conflict with the OpenTelemetry specification, +which defines [container.cpu.utilization] as the name for this metric. + +To align the emitted metric names with the OpenTelemetry specification, +the following process will be followed to phase out the old metrics: + +- Between `v0.79.0` and `v0.81.0`, the new metric is introduced and the old metric is marked as deprecated. + Only the old metric are emitted by default. +- Between `v0.82.0` and `v0.84.0`, the old metric is disabled and the new one enabled by default. +- In `v0.85.0` and up, the old metric is removed. + +To change the enabled state for the specific metrics, use the standard configuration options that are available for all metrics. + +Here's an example configuration to disable the old metrics and enable the new metrics: + +```yaml +receivers: + docker_stats: + metrics: + container.cpu.percent: + enabled: false + container.cpu.utilization: + enabled: true + +``` + ### Migrating from ScraperV1 to ScraperV2 *Note: These changes are now in effect and ScraperV1 have been removed as of v0.71.* diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index 8ad7004003d7..a1080c09bfa1 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -32,7 +32,9 @@ Number of bytes transferred to/from the disk by the group and descendant groups. ### container.cpu.percent -Percent of CPU used by the container. +Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container. + +Note this metric is being deprecated in v0.79.0 in favor of container.cpu.utilization. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | @@ -62,6 +64,14 @@ Time spent by tasks of the cgroup in user mode (Linux). Time spent by all conta | ---- | ----------- | ---------- | ----------------------- | --------- | | ns | Sum | Int | Cumulative | true | +### container.cpu.utilization + +Percent of CPU used by the container. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Double | + ### container.memory.percent Percentage of memory used. @@ -334,6 +344,14 @@ Note this is the usage for the system, not the container. | ---- | ----------- | ---------- | ----------------------- | --------- | | ns | Sum | Int | Cumulative | true | +### container.cpu.utilization + +Percent of CPU used by the container. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Double | + ### container.memory.active_anon The amount of anonymous memory that has been identified as active by the kernel. diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index 649a1bc971d5..7610fd996d54 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -23,7 +23,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { return nil } -// MetricsConfig provides config for docker_stats metrics. +// MetricsConfig provides config for dockerstatsreceiver metrics. type MetricsConfig struct { ContainerBlockioIoMergedRecursive MetricConfig `mapstructure:"container.blockio.io_merged_recursive"` ContainerBlockioIoQueuedRecursive MetricConfig `mapstructure:"container.blockio.io_queued_recursive"` @@ -42,6 +42,7 @@ type MetricsConfig struct { ContainerCPUUsageSystem MetricConfig `mapstructure:"container.cpu.usage.system"` ContainerCPUUsageTotal MetricConfig `mapstructure:"container.cpu.usage.total"` ContainerCPUUsageUsermode MetricConfig `mapstructure:"container.cpu.usage.usermode"` + ContainerCPUUtilization MetricConfig `mapstructure:"container.cpu.utilization"` ContainerMemoryActiveAnon MetricConfig `mapstructure:"container.memory.active_anon"` ContainerMemoryActiveFile MetricConfig `mapstructure:"container.memory.active_file"` ContainerMemoryCache MetricConfig `mapstructure:"container.memory.cache"` @@ -143,6 +144,9 @@ func DefaultMetricsConfig() MetricsConfig { ContainerCPUUsageUsermode: MetricConfig{ Enabled: true, }, + ContainerCPUUtilization: MetricConfig{ + Enabled: false, + }, ContainerMemoryActiveAnon: MetricConfig{ Enabled: false, }, @@ -289,7 +293,7 @@ type ResourceAttributeConfig struct { Enabled bool `mapstructure:"enabled"` } -// ResourceAttributesConfig provides config for docker_stats resource attributes. +// ResourceAttributesConfig provides config for dockerstatsreceiver resource attributes. type ResourceAttributesConfig struct { ContainerHostname ResourceAttributeConfig `mapstructure:"container.hostname"` ContainerID ResourceAttributeConfig `mapstructure:"container.id"` @@ -318,7 +322,7 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { } } -// MetricsBuilderConfig is a configuration for docker_stats metrics builder. +// MetricsBuilderConfig is a configuration for dockerstatsreceiver metrics builder. type MetricsBuilderConfig struct { Metrics MetricsConfig `mapstructure:"metrics"` ResourceAttributes ResourceAttributesConfig `mapstructure:"resource_attributes"` diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go index 39d283209cd4..fd676b7be8ad 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go @@ -43,6 +43,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerCPUUsageSystem: MetricConfig{Enabled: true}, ContainerCPUUsageTotal: MetricConfig{Enabled: true}, ContainerCPUUsageUsermode: MetricConfig{Enabled: true}, + ContainerCPUUtilization: MetricConfig{Enabled: true}, ContainerMemoryActiveAnon: MetricConfig{Enabled: true}, ContainerMemoryActiveFile: MetricConfig{Enabled: true}, ContainerMemoryCache: MetricConfig{Enabled: true}, @@ -120,6 +121,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerCPUUsageSystem: MetricConfig{Enabled: false}, ContainerCPUUsageTotal: MetricConfig{Enabled: false}, ContainerCPUUsageUsermode: MetricConfig{Enabled: false}, + ContainerCPUUtilization: MetricConfig{Enabled: false}, ContainerMemoryActiveAnon: MetricConfig{Enabled: false}, ContainerMemoryActiveFile: MetricConfig{Enabled: false}, ContainerMemoryCache: MetricConfig{Enabled: false}, diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index 5602c532ce0f..bf749d2c4c26 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -461,7 +461,7 @@ type metricContainerCPUPercent struct { // init fills container.cpu.percent metric with initial data. func (m *metricContainerCPUPercent) init() { m.data.SetName("container.cpu.percent") - m.data.SetDescription("Percent of CPU used by the container.") + m.data.SetDescription("Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.") m.data.SetUnit("1") m.data.SetEmptyGauge() } @@ -911,6 +911,55 @@ func newMetricContainerCPUUsageUsermode(cfg MetricConfig) metricContainerCPUUsag return m } +type metricContainerCPUUtilization struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills container.cpu.utilization metric with initial data. +func (m *metricContainerCPUUtilization) init() { + m.data.SetName("container.cpu.utilization") + m.data.SetDescription("Percent of CPU used by the container.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricContainerCPUUtilization) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetDoubleValue(val) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricContainerCPUUtilization) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricContainerCPUUtilization) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricContainerCPUUtilization(cfg MetricConfig) metricContainerCPUUtilization { + m := metricContainerCPUUtilization{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricContainerMemoryActiveAnon struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -3297,6 +3346,7 @@ type MetricsBuilder struct { metricContainerCPUUsageSystem metricContainerCPUUsageSystem metricContainerCPUUsageTotal metricContainerCPUUsageTotal metricContainerCPUUsageUsermode metricContainerCPUUsageUsermode + metricContainerCPUUtilization metricContainerCPUUtilization metricContainerMemoryActiveAnon metricContainerMemoryActiveAnon metricContainerMemoryActiveFile metricContainerMemoryActiveFile metricContainerMemoryCache metricContainerMemoryCache @@ -3378,6 +3428,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricContainerCPUUsageSystem: newMetricContainerCPUUsageSystem(mbc.Metrics.ContainerCPUUsageSystem), metricContainerCPUUsageTotal: newMetricContainerCPUUsageTotal(mbc.Metrics.ContainerCPUUsageTotal), metricContainerCPUUsageUsermode: newMetricContainerCPUUsageUsermode(mbc.Metrics.ContainerCPUUsageUsermode), + metricContainerCPUUtilization: newMetricContainerCPUUtilization(mbc.Metrics.ContainerCPUUtilization), metricContainerMemoryActiveAnon: newMetricContainerMemoryActiveAnon(mbc.Metrics.ContainerMemoryActiveAnon), metricContainerMemoryActiveFile: newMetricContainerMemoryActiveFile(mbc.Metrics.ContainerMemoryActiveFile), metricContainerMemoryCache: newMetricContainerMemoryCache(mbc.Metrics.ContainerMemoryCache), @@ -3539,6 +3590,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricContainerCPUUsageSystem.emit(ils.Metrics()) mb.metricContainerCPUUsageTotal.emit(ils.Metrics()) mb.metricContainerCPUUsageUsermode.emit(ils.Metrics()) + mb.metricContainerCPUUtilization.emit(ils.Metrics()) mb.metricContainerMemoryActiveAnon.emit(ils.Metrics()) mb.metricContainerMemoryActiveFile.emit(ils.Metrics()) mb.metricContainerMemoryCache.emit(ils.Metrics()) @@ -3690,6 +3742,11 @@ func (mb *MetricsBuilder) RecordContainerCPUUsageUsermodeDataPoint(ts pcommon.Ti mb.metricContainerCPUUsageUsermode.recordDataPoint(mb.startTime, ts, val) } +// RecordContainerCPUUtilizationDataPoint adds a data point to container.cpu.utilization metric. +func (mb *MetricsBuilder) RecordContainerCPUUtilizationDataPoint(ts pcommon.Timestamp, val float64) { + mb.metricContainerCPUUtilization.recordDataPoint(mb.startTime, ts, val) +} + // RecordContainerMemoryActiveAnonDataPoint adds a data point to container.memory.active_anon metric. func (mb *MetricsBuilder) RecordContainerMemoryActiveAnonDataPoint(ts pcommon.Timestamp, val int64) { mb.metricContainerMemoryActiveAnon.recordDataPoint(mb.startTime, ts, val) diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go index c0fd9701acc1..a2a0f61a9c58 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -110,6 +110,9 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordContainerCPUUsageUsermodeDataPoint(ts, 1) + allMetricsCount++ + mb.RecordContainerCPUUtilizationDataPoint(ts, 1) + allMetricsCount++ mb.RecordContainerMemoryActiveAnonDataPoint(ts, 1) @@ -505,7 +508,7 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics["container.cpu.percent"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Percent of CPU used by the container.", ms.At(i).Description()) + assert.Equal(t, "Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.", ms.At(i).Description()) assert.Equal(t, "1", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) @@ -627,6 +630,18 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) + case "container.cpu.utilization": + assert.False(t, validatedMetrics["container.cpu.utilization"], "Found a duplicate in the metrics slice: container.cpu.utilization") + validatedMetrics["container.cpu.utilization"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Percent of CPU used by the container.", ms.At(i).Description()) + assert.Equal(t, "1", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) + assert.Equal(t, float64(1), dp.DoubleValue()) case "container.memory.active_anon": assert.False(t, validatedMetrics["container.memory.active_anon"], "Found a duplicate in the metrics slice: container.memory.active_anon") validatedMetrics["container.memory.active_anon"] = true diff --git a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml index bd96efeb277b..6ed548cf19b3 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml @@ -35,6 +35,8 @@ all_set: enabled: true container.cpu.usage.usermode: enabled: true + container.cpu.utilization: + enabled: true container.memory.active_anon: enabled: true container.memory.active_file: @@ -174,6 +176,8 @@ none_set: enabled: false container.cpu.usage.usermode: enabled: false + container.cpu.utilization: + enabled: false container.memory.active_anon: enabled: false container.memory.active_file: diff --git a/receiver/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index 7d608c47cc2a..ba171b495084 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -121,9 +121,15 @@ metrics: value_type: int monotonic: true aggregation: cumulative + container.cpu.utilization: + enabled: false + description: "Percent of CPU used by the container." + unit: "1" + gauge: + value_type: double container.cpu.percent: enabled: true - description: "Percent of CPU used by the container." + description: "Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container." unit: "1" gauge: value_type: double diff --git a/receiver/dockerstatsreceiver/receiver.go b/receiver/dockerstatsreceiver/receiver.go index 01e22652b577..4d2bbc895e2f 100644 --- a/receiver/dockerstatsreceiver/receiver.go +++ b/receiver/dockerstatsreceiver/receiver.go @@ -248,6 +248,7 @@ func (r *receiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtypes.CPUS r.mb.RecordContainerCPUThrottlingDataThrottledPeriodsDataPoint(now, int64(cpuStats.ThrottlingData.ThrottledPeriods)) r.mb.RecordContainerCPUThrottlingDataPeriodsDataPoint(now, int64(cpuStats.ThrottlingData.Periods)) r.mb.RecordContainerCPUThrottlingDataThrottledTimeDataPoint(now, int64(cpuStats.ThrottlingData.ThrottledTime)) + r.mb.RecordContainerCPUUtilizationDataPoint(now, calculateCPUPercent(prevStats, cpuStats)) r.mb.RecordContainerCPUPercentDataPoint(now, calculateCPUPercent(prevStats, cpuStats)) for coreNum, v := range cpuStats.CPUUsage.PercpuUsage { diff --git a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml index 74a017d03913..660dfb8c3b4c 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml @@ -52,7 +52,7 @@ resourceMetrics: timeUnixNano: "1682426015943175000" isMonotonic: true unit: By - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0.041326615629205886 diff --git a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml index 7be4cf90e2aa..8d85263aaade 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml @@ -195,7 +195,7 @@ resourceMetrics: timeUnixNano: "1683723817613281000" isMonotonic: true unit: '{operations}' - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0.0002888012543185477 diff --git a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml index 3e185cbf66f3..9e392d6f533a 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml @@ -104,7 +104,7 @@ resourceMetrics: timeUnixNano: "1683723781130612000" isMonotonic: true unit: By - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0 diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml index 23ef4823e726..b71e4e465726 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml @@ -201,7 +201,7 @@ resourceMetrics: timeUnixNano: "1661128093795620000" isMonotonic: true unit: '{operations}' - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0.0002888012543185477 diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml index c9f63ebb4838..ba233dc78d29 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml @@ -195,7 +195,7 @@ resourceMetrics: timeUnixNano: "1661128790158163000" isMonotonic: true unit: '{operations}' - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0 @@ -885,7 +885,7 @@ resourceMetrics: timeUnixNano: "1661128790158163000" isMonotonic: true unit: '{operations}' - - description: Percent of CPU used by the container. + - description: 'Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container.' gauge: dataPoints: - asDouble: 0 From 551b12a69c22cd091e76c41270ee681d9b1cdfab Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Wed, 31 May 2023 16:52:33 +0100 Subject: [PATCH 2/2] Add warnings --- receiver/dockerstatsreceiver/documentation.md | 10 ---------- .../internal/metadata/generated_config.go | 6 +++--- .../internal/metadata/generated_metrics.go | 6 ++++++ .../internal/metadata/generated_metrics_test.go | 8 ++++++++ receiver/dockerstatsreceiver/metadata.yaml | 4 ++++ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index a1080c09bfa1..8a6f863e4a2c 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -34,8 +34,6 @@ Number of bytes transferred to/from the disk by the group and descendant groups. Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container. -Note this metric is being deprecated in v0.79.0 in favor of container.cpu.utilization. - | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | | 1 | Gauge | Double | @@ -64,14 +62,6 @@ Time spent by tasks of the cgroup in user mode (Linux). Time spent by all conta | ---- | ----------- | ---------- | ----------------------- | --------- | | ns | Sum | Int | Cumulative | true | -### container.cpu.utilization - -Percent of CPU used by the container. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| 1 | Gauge | Double | - ### container.memory.percent Percentage of memory used. diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index 7610fd996d54..4a2dd713eb50 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -23,7 +23,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { return nil } -// MetricsConfig provides config for dockerstatsreceiver metrics. +// MetricsConfig provides config for docker_stats metrics. type MetricsConfig struct { ContainerBlockioIoMergedRecursive MetricConfig `mapstructure:"container.blockio.io_merged_recursive"` ContainerBlockioIoQueuedRecursive MetricConfig `mapstructure:"container.blockio.io_queued_recursive"` @@ -293,7 +293,7 @@ type ResourceAttributeConfig struct { Enabled bool `mapstructure:"enabled"` } -// ResourceAttributesConfig provides config for dockerstatsreceiver resource attributes. +// ResourceAttributesConfig provides config for docker_stats resource attributes. type ResourceAttributesConfig struct { ContainerHostname ResourceAttributeConfig `mapstructure:"container.hostname"` ContainerID ResourceAttributeConfig `mapstructure:"container.id"` @@ -322,7 +322,7 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { } } -// MetricsBuilderConfig is a configuration for dockerstatsreceiver metrics builder. +// MetricsBuilderConfig is a configuration for docker_stats metrics builder. type MetricsBuilderConfig struct { Metrics MetricsConfig `mapstructure:"metrics"` ResourceAttributes ResourceAttributesConfig `mapstructure:"resource_attributes"` diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index bf749d2c4c26..dd4f00719f82 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -3406,6 +3406,12 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { } func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { + if mbc.Metrics.ContainerCPUPercent.Enabled { + settings.Logger.Warn("[WARNING] `container.cpu.percent` should not be enabled: This metric will be disabled in v0.82.0 and removed in v0.85.0.") + } + if !mbc.Metrics.ContainerCPUUtilization.enabledSetByUser { + settings.Logger.Warn("[WARNING] Please set `enabled` field explicitly for `container.cpu.utilization`: This metric will be enabled by default in v0.82.0.") + } mb := &MetricsBuilder{ startTime: pcommon.NewTimestampFromTime(time.Now()), metricsBuffer: pmetric.NewMetrics(), diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go index a2a0f61a9c58..957d8f66a648 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -49,6 +49,14 @@ func TestMetricsBuilder(t *testing.T) { mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) expectedWarnings := 0 + if test.configSet == testSetDefault || test.configSet == testSetAll { + assert.Equal(t, "[WARNING] `container.cpu.percent` should not be enabled: This metric will be disabled in v0.82.0 and removed in v0.85.0.", observedLogs.All()[expectedWarnings].Message) + expectedWarnings++ + } + if test.configSet == testSetDefault { + assert.Equal(t, "[WARNING] Please set `enabled` field explicitly for `container.cpu.utilization`: This metric will be enabled by default in v0.82.0.", observedLogs.All()[expectedWarnings].Message) + expectedWarnings++ + } assert.Equal(t, expectedWarnings, observedLogs.Len()) defaultMetricsCount := 0 diff --git a/receiver/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index ba171b495084..9929ffce23c5 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -125,12 +125,16 @@ metrics: enabled: false description: "Percent of CPU used by the container." unit: "1" + warnings: + if_enabled_not_set: This metric will be enabled by default in v0.82.0. gauge: value_type: double container.cpu.percent: enabled: true description: "Deprecated: use `container.cpu.utilization` metric instead. Percent of CPU used by the container." unit: "1" + warnings: + if_enabled: This metric will be disabled in v0.82.0 and removed in v0.85.0. gauge: value_type: double