From 3375d41a5092f1d485fb261ef098afdebfa42668 Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Wed, 28 Feb 2024 12:29:49 +0100 Subject: [PATCH 1/6] feat(dockerstats): add online cpu and memory failcnt metrics --- .chloggen/dockerstats-onlinecpus-failcnt.yaml | 27 ++++ receiver/dockerstatsreceiver/documentation.md | 16 +++ .../generated_component_test.go | 8 +- .../internal/metadata/generated_config.go | 8 ++ .../metadata/generated_config_test.go | 4 + .../internal/metadata/generated_metrics.go | 118 +++++++++++++++++- .../metadata/generated_metrics_test.go | 33 +++++ .../internal/metadata/generated_status.go | 7 +- .../internal/metadata/testdata/config.yaml | 8 ++ receiver/dockerstatsreceiver/metadata.yaml | 14 +++ receiver/dockerstatsreceiver/receiver.go | 3 + 11 files changed, 236 insertions(+), 10 deletions(-) create mode 100644 .chloggen/dockerstats-onlinecpus-failcnt.yaml diff --git a/.chloggen/dockerstats-onlinecpus-failcnt.yaml b/.chloggen/dockerstats-onlinecpus-failcnt.yaml new file mode 100644 index 000000000000..b8b9c15839b9 --- /dev/null +++ b/.chloggen/dockerstats-onlinecpus-failcnt.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# 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: add metrics for online CPU count and memory fails count + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [31366] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index abfa0fd6bc10..ef05c81ee703 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -62,6 +62,14 @@ Percent of CPU used by the container. | ---- | ----------- | ---------- | | 1 | Gauge | Double | +### container.memory.fails + +Number of times the memory limit was hit. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| {fails} | Sum | Int | Cumulative | true | + ### container.memory.file Amount of memory used to cache filesystem data, including tmpfs and shared memory (Only available with cgroups v2). @@ -306,6 +314,14 @@ This metric is only reported if the container has limits set with -cpus, -cpuset | ---- | ----------- | ---------- | | {cpus} | Gauge | Double | +### container.cpu.online + +Number of online CPUs. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {CPUs} | Gauge | Int | + ### container.cpu.shares CPU shares set for the container. diff --git a/receiver/dockerstatsreceiver/generated_component_test.go b/receiver/dockerstatsreceiver/generated_component_test.go index 666112438614..d2364759494f 100644 --- a/receiver/dockerstatsreceiver/generated_component_test.go +++ b/receiver/dockerstatsreceiver/generated_component_test.go @@ -17,14 +17,10 @@ import ( "go.opentelemetry.io/collector/confmap/confmaptest" ) -// assertNoErrorHost implements a component.Host that asserts that there were no errors. -type assertNoErrorHost struct { - component.Host - *testing.T +func TestCheckConfigStruct(t *testing.T) { + componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig()) } -var _ component.Host = (*assertNoErrorHost)(nil) - func TestComponentLifecycle(t *testing.T) { factory := NewFactory() diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index 50e8e315bb3d..d0c96be5e1bd 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -34,6 +34,7 @@ type MetricsConfig struct { ContainerBlockioIoWaitTimeRecursive MetricConfig `mapstructure:"container.blockio.io_wait_time_recursive"` ContainerBlockioSectorsRecursive MetricConfig `mapstructure:"container.blockio.sectors_recursive"` ContainerCPULimit MetricConfig `mapstructure:"container.cpu.limit"` + ContainerCPUOnline MetricConfig `mapstructure:"container.cpu.online"` ContainerCPUShares MetricConfig `mapstructure:"container.cpu.shares"` ContainerCPUThrottlingDataPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.periods"` ContainerCPUThrottlingDataThrottledPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.throttled_periods"` @@ -49,6 +50,7 @@ type MetricsConfig struct { ContainerMemoryAnon MetricConfig `mapstructure:"container.memory.anon"` ContainerMemoryCache MetricConfig `mapstructure:"container.memory.cache"` ContainerMemoryDirty MetricConfig `mapstructure:"container.memory.dirty"` + ContainerMemoryFails MetricConfig `mapstructure:"container.memory.fails"` ContainerMemoryFile MetricConfig `mapstructure:"container.memory.file"` ContainerMemoryHierarchicalMemoryLimit MetricConfig `mapstructure:"container.memory.hierarchical_memory_limit"` ContainerMemoryHierarchicalMemswLimit MetricConfig `mapstructure:"container.memory.hierarchical_memsw_limit"` @@ -125,6 +127,9 @@ func DefaultMetricsConfig() MetricsConfig { ContainerCPULimit: MetricConfig{ Enabled: false, }, + ContainerCPUOnline: MetricConfig{ + Enabled: false, + }, ContainerCPUShares: MetricConfig{ Enabled: false, }, @@ -170,6 +175,9 @@ func DefaultMetricsConfig() MetricsConfig { ContainerMemoryDirty: MetricConfig{ Enabled: false, }, + ContainerMemoryFails: MetricConfig{ + Enabled: true, + }, ContainerMemoryFile: MetricConfig{ Enabled: true, }, diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go index c44f0a576287..38551f55e281 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go @@ -35,6 +35,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerBlockioIoWaitTimeRecursive: MetricConfig{Enabled: true}, ContainerBlockioSectorsRecursive: MetricConfig{Enabled: true}, ContainerCPULimit: MetricConfig{Enabled: true}, + ContainerCPUOnline: MetricConfig{Enabled: true}, ContainerCPUShares: MetricConfig{Enabled: true}, ContainerCPUThrottlingDataPeriods: MetricConfig{Enabled: true}, ContainerCPUThrottlingDataThrottledPeriods: MetricConfig{Enabled: true}, @@ -50,6 +51,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerMemoryAnon: MetricConfig{Enabled: true}, ContainerMemoryCache: MetricConfig{Enabled: true}, ContainerMemoryDirty: MetricConfig{Enabled: true}, + ContainerMemoryFails: MetricConfig{Enabled: true}, ContainerMemoryFile: MetricConfig{Enabled: true}, ContainerMemoryHierarchicalMemoryLimit: MetricConfig{Enabled: true}, ContainerMemoryHierarchicalMemswLimit: MetricConfig{Enabled: true}, @@ -120,6 +122,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerBlockioIoWaitTimeRecursive: MetricConfig{Enabled: false}, ContainerBlockioSectorsRecursive: MetricConfig{Enabled: false}, ContainerCPULimit: MetricConfig{Enabled: false}, + ContainerCPUOnline: MetricConfig{Enabled: false}, ContainerCPUShares: MetricConfig{Enabled: false}, ContainerCPUThrottlingDataPeriods: MetricConfig{Enabled: false}, ContainerCPUThrottlingDataThrottledPeriods: MetricConfig{Enabled: false}, @@ -135,6 +138,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerMemoryAnon: MetricConfig{Enabled: false}, ContainerMemoryCache: MetricConfig{Enabled: false}, ContainerMemoryDirty: MetricConfig{Enabled: false}, + ContainerMemoryFails: MetricConfig{Enabled: false}, ContainerMemoryFile: MetricConfig{Enabled: false}, ContainerMemoryHierarchicalMemoryLimit: MetricConfig{Enabled: false}, ContainerMemoryHierarchicalMemswLimit: MetricConfig{Enabled: false}, diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index c2c39c061aee..863b7c536d9b 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -501,6 +501,55 @@ func newMetricContainerCPULimit(cfg MetricConfig) metricContainerCPULimit { return m } +type metricContainerCPUOnline 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.online metric with initial data. +func (m *metricContainerCPUOnline) init() { + m.data.SetName("container.cpu.online") + m.data.SetDescription("Number of online CPUs.") + m.data.SetUnit("{CPUs}") + m.data.SetEmptyGauge() +} + +func (m *metricContainerCPUOnline) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricContainerCPUOnline) 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 *metricContainerCPUOnline) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricContainerCPUOnline(cfg MetricConfig) metricContainerCPUOnline { + m := metricContainerCPUOnline{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricContainerCPUShares struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -1264,6 +1313,57 @@ func newMetricContainerMemoryDirty(cfg MetricConfig) metricContainerMemoryDirty return m } +type metricContainerMemoryFails 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.memory.fails metric with initial data. +func (m *metricContainerMemoryFails) init() { + m.data.SetName("container.memory.fails") + m.data.SetDescription("Number of times the memory limit was hit.") + m.data.SetUnit("{fails}") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) +} + +func (m *metricContainerMemoryFails) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricContainerMemoryFails) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricContainerMemoryFails) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricContainerMemoryFails(cfg MetricConfig) metricContainerMemoryFails { + m := metricContainerMemoryFails{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricContainerMemoryFile struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -3588,6 +3688,7 @@ type MetricsBuilder struct { metricContainerBlockioIoWaitTimeRecursive metricContainerBlockioIoWaitTimeRecursive metricContainerBlockioSectorsRecursive metricContainerBlockioSectorsRecursive metricContainerCPULimit metricContainerCPULimit + metricContainerCPUOnline metricContainerCPUOnline metricContainerCPUShares metricContainerCPUShares metricContainerCPUThrottlingDataPeriods metricContainerCPUThrottlingDataPeriods metricContainerCPUThrottlingDataThrottledPeriods metricContainerCPUThrottlingDataThrottledPeriods @@ -3603,6 +3704,7 @@ type MetricsBuilder struct { metricContainerMemoryAnon metricContainerMemoryAnon metricContainerMemoryCache metricContainerMemoryCache metricContainerMemoryDirty metricContainerMemoryDirty + metricContainerMemoryFails metricContainerMemoryFails metricContainerMemoryFile metricContainerMemoryFile metricContainerMemoryHierarchicalMemoryLimit metricContainerMemoryHierarchicalMemoryLimit metricContainerMemoryHierarchicalMemswLimit metricContainerMemoryHierarchicalMemswLimit @@ -3675,6 +3777,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricContainerBlockioIoWaitTimeRecursive: newMetricContainerBlockioIoWaitTimeRecursive(mbc.Metrics.ContainerBlockioIoWaitTimeRecursive), metricContainerBlockioSectorsRecursive: newMetricContainerBlockioSectorsRecursive(mbc.Metrics.ContainerBlockioSectorsRecursive), metricContainerCPULimit: newMetricContainerCPULimit(mbc.Metrics.ContainerCPULimit), + metricContainerCPUOnline: newMetricContainerCPUOnline(mbc.Metrics.ContainerCPUOnline), metricContainerCPUShares: newMetricContainerCPUShares(mbc.Metrics.ContainerCPUShares), metricContainerCPUThrottlingDataPeriods: newMetricContainerCPUThrottlingDataPeriods(mbc.Metrics.ContainerCPUThrottlingDataPeriods), metricContainerCPUThrottlingDataThrottledPeriods: newMetricContainerCPUThrottlingDataThrottledPeriods(mbc.Metrics.ContainerCPUThrottlingDataThrottledPeriods), @@ -3690,6 +3793,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricContainerMemoryAnon: newMetricContainerMemoryAnon(mbc.Metrics.ContainerMemoryAnon), metricContainerMemoryCache: newMetricContainerMemoryCache(mbc.Metrics.ContainerMemoryCache), metricContainerMemoryDirty: newMetricContainerMemoryDirty(mbc.Metrics.ContainerMemoryDirty), + metricContainerMemoryFails: newMetricContainerMemoryFails(mbc.Metrics.ContainerMemoryFails), metricContainerMemoryFile: newMetricContainerMemoryFile(mbc.Metrics.ContainerMemoryFile), metricContainerMemoryHierarchicalMemoryLimit: newMetricContainerMemoryHierarchicalMemoryLimit(mbc.Metrics.ContainerMemoryHierarchicalMemoryLimit), metricContainerMemoryHierarchicalMemswLimit: newMetricContainerMemoryHierarchicalMemswLimit(mbc.Metrics.ContainerMemoryHierarchicalMemswLimit), @@ -3794,7 +3898,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) ils := rm.ScopeMetrics().AppendEmpty() - ils.Scope().SetName("otelcol/dockerstatsreceiver") + ils.Scope().SetName("go.opentelemetry.io/collector/receiver/dockerstatsreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricContainerBlockioIoMergedRecursive.emit(ils.Metrics()) @@ -3806,6 +3910,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricContainerBlockioIoWaitTimeRecursive.emit(ils.Metrics()) mb.metricContainerBlockioSectorsRecursive.emit(ils.Metrics()) mb.metricContainerCPULimit.emit(ils.Metrics()) + mb.metricContainerCPUOnline.emit(ils.Metrics()) mb.metricContainerCPUShares.emit(ils.Metrics()) mb.metricContainerCPUThrottlingDataPeriods.emit(ils.Metrics()) mb.metricContainerCPUThrottlingDataThrottledPeriods.emit(ils.Metrics()) @@ -3821,6 +3926,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricContainerMemoryAnon.emit(ils.Metrics()) mb.metricContainerMemoryCache.emit(ils.Metrics()) mb.metricContainerMemoryDirty.emit(ils.Metrics()) + mb.metricContainerMemoryFails.emit(ils.Metrics()) mb.metricContainerMemoryFile.emit(ils.Metrics()) mb.metricContainerMemoryHierarchicalMemoryLimit.emit(ils.Metrics()) mb.metricContainerMemoryHierarchicalMemswLimit.emit(ils.Metrics()) @@ -3931,6 +4037,11 @@ func (mb *MetricsBuilder) RecordContainerCPULimitDataPoint(ts pcommon.Timestamp, mb.metricContainerCPULimit.recordDataPoint(mb.startTime, ts, val) } +// RecordContainerCPUOnlineDataPoint adds a data point to container.cpu.online metric. +func (mb *MetricsBuilder) RecordContainerCPUOnlineDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricContainerCPUOnline.recordDataPoint(mb.startTime, ts, val) +} + // RecordContainerCPUSharesDataPoint adds a data point to container.cpu.shares metric. func (mb *MetricsBuilder) RecordContainerCPUSharesDataPoint(ts pcommon.Timestamp, val int64) { mb.metricContainerCPUShares.recordDataPoint(mb.startTime, ts, val) @@ -4006,6 +4117,11 @@ func (mb *MetricsBuilder) RecordContainerMemoryDirtyDataPoint(ts pcommon.Timesta mb.metricContainerMemoryDirty.recordDataPoint(mb.startTime, ts, val) } +// RecordContainerMemoryFailsDataPoint adds a data point to container.memory.fails metric. +func (mb *MetricsBuilder) RecordContainerMemoryFailsDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricContainerMemoryFails.recordDataPoint(mb.startTime, ts, val) +} + // RecordContainerMemoryFileDataPoint adds a data point to container.memory.file metric. func (mb *MetricsBuilder) RecordContainerMemoryFileDataPoint(ts pcommon.Timestamp, val int64) { mb.metricContainerMemoryFile.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 e52c3f062d2f..7f9b51feeb7a 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -83,6 +83,9 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordContainerCPULimitDataPoint(ts, 1) + allMetricsCount++ + mb.RecordContainerCPUOnlineDataPoint(ts, 1) + allMetricsCount++ mb.RecordContainerCPUSharesDataPoint(ts, 1) @@ -132,6 +135,10 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordContainerMemoryDirtyDataPoint(ts, 1) + defaultMetricsCount++ + allMetricsCount++ + mb.RecordContainerMemoryFailsDataPoint(ts, 1) + defaultMetricsCount++ allMetricsCount++ mb.RecordContainerMemoryFileDataPoint(ts, 1) @@ -502,6 +509,18 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) assert.Equal(t, float64(1), dp.DoubleValue()) + case "container.cpu.online": + assert.False(t, validatedMetrics["container.cpu.online"], "Found a duplicate in the metrics slice: container.cpu.online") + validatedMetrics["container.cpu.online"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Number of online CPUs.", ms.At(i).Description()) + assert.Equal(t, "{CPUs}", 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.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) case "container.cpu.shares": assert.False(t, validatedMetrics["container.cpu.shares"], "Found a duplicate in the metrics slice: container.cpu.shares") validatedMetrics["container.cpu.shares"] = true @@ -711,6 +730,20 @@ 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.memory.fails": + assert.False(t, validatedMetrics["container.memory.fails"], "Found a duplicate in the metrics slice: container.memory.fails") + validatedMetrics["container.memory.fails"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of times the memory limit was hit.", ms.At(i).Description()) + assert.Equal(t, "{fails}", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) case "container.memory.file": assert.False(t, validatedMetrics["container.memory.file"], "Found a duplicate in the metrics slice: container.memory.file") validatedMetrics["container.memory.file"] = true diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_status.go b/receiver/dockerstatsreceiver/internal/metadata/generated_status.go index 537150dc6fe0..1a006b09d808 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_status.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_status.go @@ -9,7 +9,8 @@ import ( ) var ( - Type = component.MustNewType("docker_stats") + Type = component.MustNewType("docker_stats") + scopeName = "go.opentelemetry.io/collector/receiver/dockerstatsreceiver" ) const ( @@ -17,9 +18,9 @@ const ( ) func Meter(settings component.TelemetrySettings) metric.Meter { - return settings.MeterProvider.Meter("otelcol/dockerstatsreceiver") + return settings.MeterProvider.Meter(scopeName) } func Tracer(settings component.TelemetrySettings) trace.Tracer { - return settings.TracerProvider.Tracer("otelcol/dockerstatsreceiver") + return settings.TracerProvider.Tracer(scopeName) } diff --git a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml index 91acbeaa86aa..e588552d9903 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml @@ -19,6 +19,8 @@ all_set: enabled: true container.cpu.limit: enabled: true + container.cpu.online: + enabled: true container.cpu.shares: enabled: true container.cpu.throttling_data.periods: @@ -49,6 +51,8 @@ all_set: enabled: true container.memory.dirty: enabled: true + container.memory.fails: + enabled: true container.memory.file: enabled: true container.memory.hierarchical_memory_limit: @@ -174,6 +178,8 @@ none_set: enabled: false container.cpu.limit: enabled: false + container.cpu.online: + enabled: false container.cpu.shares: enabled: false container.cpu.throttling_data.periods: @@ -204,6 +210,8 @@ none_set: enabled: false container.memory.dirty: enabled: false + container.memory.fails: + enabled: false container.memory.file: enabled: false container.memory.hierarchical_memory_limit: diff --git a/receiver/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index 2d04712a35b4..9d1d17a845c6 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -150,6 +150,12 @@ metrics: unit: "1" gauge: value_type: int + container.cpu.online: + enabled: false + description: "Number of online CPUs." + unit: "{CPUs}" + gauge: + value_type: int # Memory @@ -463,6 +469,14 @@ metrics: value_type: int aggregation_temporality: cumulative monotonic: false + container.memory.fails: + enabled: true + description: "Number of times the memory limit was hit." + unit: "{fails}" + sum: + value_type: int + aggregation_temporality: cumulative + monotonic: true # BlockIO (cgroup v1) and IO (cgroup v2) controllers diff --git a/receiver/dockerstatsreceiver/receiver.go b/receiver/dockerstatsreceiver/receiver.go index 5581ed1021a4..7935229f6c88 100644 --- a/receiver/dockerstatsreceiver/receiver.go +++ b/receiver/dockerstatsreceiver/receiver.go @@ -162,6 +162,8 @@ func (r *metricsReceiver) recordMemoryMetrics(now pcommon.Timestamp, memoryStats r.mb.RecordContainerMemoryUsageMaxDataPoint(now, int64(memoryStats.MaxUsage)) + r.mb.RecordContainerMemoryFailsDataPoint(now, int64(memoryStats.Failcnt)) + recorders := map[string]func(pcommon.Timestamp, int64){ "cache": r.mb.RecordContainerMemoryCacheDataPoint, "total_cache": r.mb.RecordContainerMemoryTotalCacheDataPoint, @@ -256,6 +258,7 @@ func (r *metricsReceiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtyp 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.RecordContainerCPUOnlineDataPoint(now, int64(cpuStats.OnlineCPUs)) for coreNum, v := range cpuStats.CPUUsage.PercpuUsage { r.mb.RecordContainerCPUUsagePercpuDataPoint(now, int64(v), fmt.Sprintf("cpu%s", strconv.Itoa(coreNum))) From 391b78261670e745bbc4f29157f4dfb962f4bf51 Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Wed, 28 Feb 2024 13:25:47 +0100 Subject: [PATCH 2/6] run go generate --- receiver/dockerstatsreceiver/generated_component_test.go | 8 ++++++-- .../internal/metadata/generated_metrics.go | 2 +- .../internal/metadata/generated_status.go | 7 +++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/receiver/dockerstatsreceiver/generated_component_test.go b/receiver/dockerstatsreceiver/generated_component_test.go index d2364759494f..666112438614 100644 --- a/receiver/dockerstatsreceiver/generated_component_test.go +++ b/receiver/dockerstatsreceiver/generated_component_test.go @@ -17,10 +17,14 @@ import ( "go.opentelemetry.io/collector/confmap/confmaptest" ) -func TestCheckConfigStruct(t *testing.T) { - componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig()) +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T } +var _ component.Host = (*assertNoErrorHost)(nil) + func TestComponentLifecycle(t *testing.T) { factory := NewFactory() diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index 863b7c536d9b..845dae1d5b14 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -3898,7 +3898,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) ils := rm.ScopeMetrics().AppendEmpty() - ils.Scope().SetName("go.opentelemetry.io/collector/receiver/dockerstatsreceiver") + ils.Scope().SetName("otelcol/dockerstatsreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricContainerBlockioIoMergedRecursive.emit(ils.Metrics()) diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_status.go b/receiver/dockerstatsreceiver/internal/metadata/generated_status.go index 1a006b09d808..537150dc6fe0 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_status.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_status.go @@ -9,8 +9,7 @@ import ( ) var ( - Type = component.MustNewType("docker_stats") - scopeName = "go.opentelemetry.io/collector/receiver/dockerstatsreceiver" + Type = component.MustNewType("docker_stats") ) const ( @@ -18,9 +17,9 @@ const ( ) func Meter(settings component.TelemetrySettings) metric.Meter { - return settings.MeterProvider.Meter(scopeName) + return settings.MeterProvider.Meter("otelcol/dockerstatsreceiver") } func Tracer(settings component.TelemetrySettings) trace.Tracer { - return settings.TracerProvider.Tracer(scopeName) + return settings.TracerProvider.Tracer("otelcol/dockerstatsreceiver") } From d10a3bd8eac0fb5fa9016fe20cb0bdde01f970d2 Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Fri, 1 Mar 2024 11:02:37 +0100 Subject: [PATCH 3/6] fix scrapev2 tests --- receiver/dockerstatsreceiver/documentation.md | 18 +++++----- .../internal/metadata/generated_config.go | 2 +- .../internal/metadata/generated_metrics.go | 2 +- .../metadata/generated_metrics_test.go | 3 +- receiver/dockerstatsreceiver/metadata.yaml | 4 +-- receiver/dockerstatsreceiver/receiver_test.go | 2 ++ .../mock/cgroups_v2/expected_metrics.yaml | 18 ++++++++++ .../mock/cpu_limit/expected_metrics.yaml | 18 ++++++++++ .../testdata/mock/cpu_limit/stats.json | 1 + .../mock/no_pids_stats/expected_metrics.yaml | 18 ++++++++++ .../testdata/mock/no_pids_stats/stats.json | 1 + .../mock/pids_stats_max/expected_metrics.yaml | 18 ++++++++++ .../testdata/mock/pids_stats_max/stats.json | 1 + .../single_container/expected_metrics.yaml | 18 ++++++++++ .../testdata/mock/single_container/stats.json | 1 + .../expected_metrics.yaml | 18 ++++++++++ .../stats.json | 1 + .../mock/two_containers/expected_metrics.yaml | 36 +++++++++++++++++++ .../testdata/mock/two_containers/stats1.json | 1 + .../testdata/mock/two_containers/stats2.json | 1 + 20 files changed, 167 insertions(+), 15 deletions(-) diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index ef05c81ee703..4bd9c0c4f688 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -62,14 +62,6 @@ Percent of CPU used by the container. | ---- | ----------- | ---------- | | 1 | Gauge | Double | -### container.memory.fails - -Number of times the memory limit was hit. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| {fails} | Sum | Int | Cumulative | true | - ### container.memory.file Amount of memory used to cache filesystem data, including tmpfs and shared memory (Only available with cgroups v2). @@ -320,7 +312,7 @@ Number of online CPUs. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| {CPUs} | Gauge | Int | +| {cpus} | Gauge | Int | ### container.cpu.shares @@ -422,6 +414,14 @@ Bytes that are waiting to get written back to the disk, from this cgroup (Only a | ---- | ----------- | ---------- | ----------------------- | --------- | | By | Sum | Int | Cumulative | false | +### container.memory.fails + +Number of times the memory limit was hit. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| {fails} | Sum | Int | Cumulative | true | + ### container.memory.hierarchical_memory_limit The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index d0c96be5e1bd..6b718f10473a 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -176,7 +176,7 @@ func DefaultMetricsConfig() MetricsConfig { Enabled: false, }, ContainerMemoryFails: MetricConfig{ - Enabled: true, + Enabled: false, }, ContainerMemoryFile: MetricConfig{ Enabled: true, diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index 845dae1d5b14..992749962590 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -511,7 +511,7 @@ type metricContainerCPUOnline struct { func (m *metricContainerCPUOnline) init() { m.data.SetName("container.cpu.online") m.data.SetDescription("Number of online CPUs.") - m.data.SetUnit("{CPUs}") + m.data.SetUnit("{cpus}") m.data.SetEmptyGauge() } diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go index 7f9b51feeb7a..78f1f7c8f9d0 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -135,7 +135,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordContainerMemoryDirtyDataPoint(ts, 1) - defaultMetricsCount++ allMetricsCount++ mb.RecordContainerMemoryFailsDataPoint(ts, 1) @@ -515,7 +514,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, "Number of online CPUs.", ms.At(i).Description()) - assert.Equal(t, "{CPUs}", ms.At(i).Unit()) + assert.Equal(t, "{cpus}", 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/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index 9d1d17a845c6..3f51ef2244d4 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -153,7 +153,7 @@ metrics: container.cpu.online: enabled: false description: "Number of online CPUs." - unit: "{CPUs}" + unit: "{cpus}" gauge: value_type: int @@ -470,7 +470,7 @@ metrics: aggregation_temporality: cumulative monotonic: false container.memory.fails: - enabled: true + enabled: false description: "Number of times the memory limit was hit." unit: "{fails}" sum: diff --git a/receiver/dockerstatsreceiver/receiver_test.go b/receiver/dockerstatsreceiver/receiver_test.go index 26d973647e4f..304f80316a48 100644 --- a/receiver/dockerstatsreceiver/receiver_test.go +++ b/receiver/dockerstatsreceiver/receiver_test.go @@ -53,6 +53,7 @@ var ( ContainerCPUUsageSystem: metricEnabled, ContainerCPUUsageTotal: metricEnabled, ContainerCPUUsageUsermode: metricEnabled, + ContainerCPUOnline: metricEnabled, ContainerMemoryActiveAnon: metricEnabled, ContainerMemoryActiveFile: metricEnabled, ContainerMemoryCache: metricEnabled, @@ -89,6 +90,7 @@ var ( ContainerMemoryUsageMax: metricEnabled, ContainerMemoryUsageTotal: metricEnabled, ContainerMemoryWriteback: metricEnabled, + ContainerMemoryFails: metricEnabled, ContainerNetworkIoUsageRxBytes: metricEnabled, ContainerNetworkIoUsageRxDropped: metricEnabled, ContainerNetworkIoUsageRxErrors: metricEnabled, diff --git a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml index 756751d84ee6..8b1851710dc6 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml @@ -52,6 +52,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: By + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 2 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -165,6 +173,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: Amount of memory used to cache filesystem data, including tmpfs and shared memory (Only available with cgroups v2). name: container.memory.file sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml index 08d6c88004dd..8a0032d6114b 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml @@ -112,6 +112,14 @@ resourceMetrics: timeUnixNano: "2000000" name: container.cpu.limit unit: '{cpus}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 2 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -225,6 +233,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: Amount of memory used to cache filesystem data, including tmpfs and shared memory (Only available with cgroups v2). name: container.memory.file sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/stats.json b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/stats.json index 68509e8f1058..dc51d90f0cfb 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/stats.json +++ b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/stats.json @@ -83,6 +83,7 @@ } }, "memory_stats": { + "failcnt": 4, "usage": 2240512, "stats": { "active_anon": 4096, 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 838e67b56f3b..27031d6896b9 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml @@ -195,6 +195,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 8 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -380,6 +388,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). name: container.memory.hierarchical_memory_limit sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/stats.json b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/stats.json index 4ec5a2c0df5d..269c0238f6e0 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/stats.json +++ b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/stats.json @@ -109,6 +109,7 @@ }, "id": "10b703fb312b25e8368ab5a3bce3a1610d1cee5d71a94920f1a7adbc5b0cb326", "memory_stats": { + "failcnt": 4, "limit": 10449559552, "max_usage": 3932160, "stats": { 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 59f5e428e8d1..b1e2f000c567 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml @@ -104,6 +104,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: By + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 2 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -217,6 +225,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: Amount of memory used to cache filesystem data, including tmpfs and shared memory (Only available with cgroups v2). name: container.memory.file sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/stats.json b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/stats.json index 1fa9e89505d0..90daf395f0aa 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/stats.json +++ b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/stats.json @@ -83,6 +83,7 @@ } }, "memory_stats": { + "failcnt": 4, "usage": 2240512, "stats": { "active_anon": 4096, diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml index bcbb45b86230..ca8eadf502f6 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml @@ -201,6 +201,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 8 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -385,6 +393,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). name: container.memory.hierarchical_memory_limit sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container/stats.json b/receiver/dockerstatsreceiver/testdata/mock/single_container/stats.json index f0b5d6110ab1..33d8145d0cf8 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container/stats.json +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container/stats.json @@ -109,6 +109,7 @@ }, "id": "10b703fb312b25e8368ab5a3bce3a1610d1cee5d71a94920f1a7adbc5b0cb326", "memory_stats": { + "failcnt": 4, "limit": 10449559552, "max_usage": 3932160, "stats": { diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml index 4784753987e7..7ba7e05c9c3b 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml @@ -201,6 +201,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 8 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -386,6 +394,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). name: container.memory.hierarchical_memory_limit sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/stats.json b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/stats.json index 61a10904c65f..3cd6f3b32ac8 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/stats.json +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/stats.json @@ -109,6 +109,7 @@ }, "id": "73364842ef014441cac89fed05df19463b1230db25a31252cdf82e754f1ec581", "memory_stats": { + "failcnt": 4, "limit": 10449559552, "max_usage": 3932160, "stats": { diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml index c3a0788872fc..cf914cf56851 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml @@ -195,6 +195,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 1 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -330,6 +338,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). name: container.memory.hierarchical_memory_limit sum: @@ -962,6 +980,14 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' + - description: 'Number of online CPUs.' + gauge: + dataPoints: + - asInt: 1 + startTimeUnixNano: "1687762436124732000" + timeUnixNano: "1687762436137493000" + name: container.cpu.online + unit: "{cpus}" - description: CPU shares set for the container. gauge: dataPoints: @@ -1097,6 +1123,16 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: By + - description: 'Number of times the memory limit was hit.' + name: container.memory.fails + sum: + isMonotonic: true + aggregationTemporality: 2 + dataPoints: + - asInt: "4" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: "{fails}" - description: The maximum amount of physical memory that can be used by the processes of this control group (Only available with cgroups v1). name: container.memory.hierarchical_memory_limit sum: diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats1.json b/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats1.json index 9ca148e05517..6cd042489777 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats1.json +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats1.json @@ -102,6 +102,7 @@ }, "id": "89d28931fd8b95c8806343a532e9e76bf0a0b76ee8f19452b8f75dee1ebcebb7", "memory_stats": { + "failcnt": 4, "limit": 2074079232, "max_usage": 6201344, "stats": { diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats2.json b/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats2.json index 2df1f9dc7a60..f0565da48162 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats2.json +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/stats2.json @@ -102,6 +102,7 @@ }, "id": "a359c0fc87c546b42d2ad32db7c978627f1d89b49cb3827a7b19ba97a1febcce", "memory_stats": { + "failcnt": 4, "limit": 2074079232, "max_usage": 6172672, "stats": { From 700018a31659ab6f218cd57d3039245245b2000b Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Thu, 7 Mar 2024 13:53:51 +0100 Subject: [PATCH 4/6] rename online to logical_count --- receiver/dockerstatsreceiver/documentation.md | 4 +-- .../internal/metadata/generated_config.go | 4 +-- .../metadata/generated_config_test.go | 4 +-- .../internal/metadata/generated_metrics.go | 32 +++++++++---------- .../metadata/generated_metrics_test.go | 10 +++--- .../internal/metadata/testdata/config.yaml | 4 +-- receiver/dockerstatsreceiver/metadata.yaml | 4 +-- receiver/dockerstatsreceiver/receiver.go | 2 +- receiver/dockerstatsreceiver/receiver_test.go | 2 +- .../mock/cgroups_v2/expected_metrics.yaml | 4 +-- .../mock/cpu_limit/expected_metrics.yaml | 4 +-- .../mock/no_pids_stats/expected_metrics.yaml | 4 +-- .../mock/pids_stats_max/expected_metrics.yaml | 4 +-- .../single_container/expected_metrics.yaml | 4 +-- .../expected_metrics.yaml | 4 +-- .../mock/two_containers/expected_metrics.yaml | 4 +-- 16 files changed, 47 insertions(+), 47 deletions(-) diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index 4bd9c0c4f688..2a548ce1eb08 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -306,9 +306,9 @@ This metric is only reported if the container has limits set with -cpus, -cpuset | ---- | ----------- | ---------- | | {cpus} | Gauge | Double | -### container.cpu.online +### container.cpu.logical_count -Number of online CPUs. +Number of cores available to the container. | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index 6b718f10473a..0f5d7c39d5a9 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -34,7 +34,7 @@ type MetricsConfig struct { ContainerBlockioIoWaitTimeRecursive MetricConfig `mapstructure:"container.blockio.io_wait_time_recursive"` ContainerBlockioSectorsRecursive MetricConfig `mapstructure:"container.blockio.sectors_recursive"` ContainerCPULimit MetricConfig `mapstructure:"container.cpu.limit"` - ContainerCPUOnline MetricConfig `mapstructure:"container.cpu.online"` + ContainerCPULogicalCount MetricConfig `mapstructure:"container.cpu.logical_count"` ContainerCPUShares MetricConfig `mapstructure:"container.cpu.shares"` ContainerCPUThrottlingDataPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.periods"` ContainerCPUThrottlingDataThrottledPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.throttled_periods"` @@ -127,7 +127,7 @@ func DefaultMetricsConfig() MetricsConfig { ContainerCPULimit: MetricConfig{ Enabled: false, }, - ContainerCPUOnline: MetricConfig{ + ContainerCPULogicalCount: MetricConfig{ Enabled: false, }, ContainerCPUShares: MetricConfig{ diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go index 38551f55e281..645dd16efd1a 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config_test.go @@ -35,7 +35,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerBlockioIoWaitTimeRecursive: MetricConfig{Enabled: true}, ContainerBlockioSectorsRecursive: MetricConfig{Enabled: true}, ContainerCPULimit: MetricConfig{Enabled: true}, - ContainerCPUOnline: MetricConfig{Enabled: true}, + ContainerCPULogicalCount: MetricConfig{Enabled: true}, ContainerCPUShares: MetricConfig{Enabled: true}, ContainerCPUThrottlingDataPeriods: MetricConfig{Enabled: true}, ContainerCPUThrottlingDataThrottledPeriods: MetricConfig{Enabled: true}, @@ -122,7 +122,7 @@ func TestMetricsBuilderConfig(t *testing.T) { ContainerBlockioIoWaitTimeRecursive: MetricConfig{Enabled: false}, ContainerBlockioSectorsRecursive: MetricConfig{Enabled: false}, ContainerCPULimit: MetricConfig{Enabled: false}, - ContainerCPUOnline: MetricConfig{Enabled: false}, + ContainerCPULogicalCount: MetricConfig{Enabled: false}, ContainerCPUShares: MetricConfig{Enabled: false}, ContainerCPUThrottlingDataPeriods: MetricConfig{Enabled: false}, ContainerCPUThrottlingDataThrottledPeriods: MetricConfig{Enabled: false}, diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index 992749962590..cd0841f6ca23 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -501,21 +501,21 @@ func newMetricContainerCPULimit(cfg MetricConfig) metricContainerCPULimit { return m } -type metricContainerCPUOnline struct { +type metricContainerCPULogicalCount 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.online metric with initial data. -func (m *metricContainerCPUOnline) init() { - m.data.SetName("container.cpu.online") - m.data.SetDescription("Number of online CPUs.") +// init fills container.cpu.logical_count metric with initial data. +func (m *metricContainerCPULogicalCount) init() { + m.data.SetName("container.cpu.logical_count") + m.data.SetDescription("Number of cores available to the container.") m.data.SetUnit("{cpus}") m.data.SetEmptyGauge() } -func (m *metricContainerCPUOnline) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { +func (m *metricContainerCPULogicalCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { if !m.config.Enabled { return } @@ -526,14 +526,14 @@ func (m *metricContainerCPUOnline) recordDataPoint(start pcommon.Timestamp, ts p } // updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricContainerCPUOnline) updateCapacity() { +func (m *metricContainerCPULogicalCount) 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 *metricContainerCPUOnline) emit(metrics pmetric.MetricSlice) { +func (m *metricContainerCPULogicalCount) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) @@ -541,8 +541,8 @@ func (m *metricContainerCPUOnline) emit(metrics pmetric.MetricSlice) { } } -func newMetricContainerCPUOnline(cfg MetricConfig) metricContainerCPUOnline { - m := metricContainerCPUOnline{config: cfg} +func newMetricContainerCPULogicalCount(cfg MetricConfig) metricContainerCPULogicalCount { + m := metricContainerCPULogicalCount{config: cfg} if cfg.Enabled { m.data = pmetric.NewMetric() m.init() @@ -3688,7 +3688,7 @@ type MetricsBuilder struct { metricContainerBlockioIoWaitTimeRecursive metricContainerBlockioIoWaitTimeRecursive metricContainerBlockioSectorsRecursive metricContainerBlockioSectorsRecursive metricContainerCPULimit metricContainerCPULimit - metricContainerCPUOnline metricContainerCPUOnline + metricContainerCPULogicalCount metricContainerCPULogicalCount metricContainerCPUShares metricContainerCPUShares metricContainerCPUThrottlingDataPeriods metricContainerCPUThrottlingDataPeriods metricContainerCPUThrottlingDataThrottledPeriods metricContainerCPUThrottlingDataThrottledPeriods @@ -3777,7 +3777,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricContainerBlockioIoWaitTimeRecursive: newMetricContainerBlockioIoWaitTimeRecursive(mbc.Metrics.ContainerBlockioIoWaitTimeRecursive), metricContainerBlockioSectorsRecursive: newMetricContainerBlockioSectorsRecursive(mbc.Metrics.ContainerBlockioSectorsRecursive), metricContainerCPULimit: newMetricContainerCPULimit(mbc.Metrics.ContainerCPULimit), - metricContainerCPUOnline: newMetricContainerCPUOnline(mbc.Metrics.ContainerCPUOnline), + metricContainerCPULogicalCount: newMetricContainerCPULogicalCount(mbc.Metrics.ContainerCPULogicalCount), metricContainerCPUShares: newMetricContainerCPUShares(mbc.Metrics.ContainerCPUShares), metricContainerCPUThrottlingDataPeriods: newMetricContainerCPUThrottlingDataPeriods(mbc.Metrics.ContainerCPUThrottlingDataPeriods), metricContainerCPUThrottlingDataThrottledPeriods: newMetricContainerCPUThrottlingDataThrottledPeriods(mbc.Metrics.ContainerCPUThrottlingDataThrottledPeriods), @@ -3910,7 +3910,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricContainerBlockioIoWaitTimeRecursive.emit(ils.Metrics()) mb.metricContainerBlockioSectorsRecursive.emit(ils.Metrics()) mb.metricContainerCPULimit.emit(ils.Metrics()) - mb.metricContainerCPUOnline.emit(ils.Metrics()) + mb.metricContainerCPULogicalCount.emit(ils.Metrics()) mb.metricContainerCPUShares.emit(ils.Metrics()) mb.metricContainerCPUThrottlingDataPeriods.emit(ils.Metrics()) mb.metricContainerCPUThrottlingDataThrottledPeriods.emit(ils.Metrics()) @@ -4037,9 +4037,9 @@ func (mb *MetricsBuilder) RecordContainerCPULimitDataPoint(ts pcommon.Timestamp, mb.metricContainerCPULimit.recordDataPoint(mb.startTime, ts, val) } -// RecordContainerCPUOnlineDataPoint adds a data point to container.cpu.online metric. -func (mb *MetricsBuilder) RecordContainerCPUOnlineDataPoint(ts pcommon.Timestamp, val int64) { - mb.metricContainerCPUOnline.recordDataPoint(mb.startTime, ts, val) +// RecordContainerCPULogicalCountDataPoint adds a data point to container.cpu.logical_count metric. +func (mb *MetricsBuilder) RecordContainerCPULogicalCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricContainerCPULogicalCount.recordDataPoint(mb.startTime, ts, val) } // RecordContainerCPUSharesDataPoint adds a data point to container.cpu.shares metric. diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go index 78f1f7c8f9d0..e0e57157b7fc 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -84,7 +84,7 @@ func TestMetricsBuilder(t *testing.T) { mb.RecordContainerCPULimitDataPoint(ts, 1) allMetricsCount++ - mb.RecordContainerCPUOnlineDataPoint(ts, 1) + mb.RecordContainerCPULogicalCountDataPoint(ts, 1) allMetricsCount++ mb.RecordContainerCPUSharesDataPoint(ts, 1) @@ -508,12 +508,12 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) assert.Equal(t, float64(1), dp.DoubleValue()) - case "container.cpu.online": - assert.False(t, validatedMetrics["container.cpu.online"], "Found a duplicate in the metrics slice: container.cpu.online") - validatedMetrics["container.cpu.online"] = true + case "container.cpu.logical_count": + assert.False(t, validatedMetrics["container.cpu.logical_count"], "Found a duplicate in the metrics slice: container.cpu.logical_count") + validatedMetrics["container.cpu.logical_count"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Number of online CPUs.", ms.At(i).Description()) + assert.Equal(t, "Number of cores available to the container.", ms.At(i).Description()) assert.Equal(t, "{cpus}", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) diff --git a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml index e588552d9903..bdb0e1d06720 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml @@ -19,7 +19,7 @@ all_set: enabled: true container.cpu.limit: enabled: true - container.cpu.online: + container.cpu.logical_count: enabled: true container.cpu.shares: enabled: true @@ -178,7 +178,7 @@ none_set: enabled: false container.cpu.limit: enabled: false - container.cpu.online: + container.cpu.logical_count: enabled: false container.cpu.shares: enabled: false diff --git a/receiver/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index 6e7cb6b6e6d9..67afb8673bc6 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -151,9 +151,9 @@ metrics: unit: "1" gauge: value_type: int - container.cpu.online: + container.cpu.logical_count: enabled: false - description: "Number of online CPUs." + description: "Number of cores available to the container." unit: "{cpus}" gauge: value_type: int diff --git a/receiver/dockerstatsreceiver/receiver.go b/receiver/dockerstatsreceiver/receiver.go index 7935229f6c88..1b0705f9cb67 100644 --- a/receiver/dockerstatsreceiver/receiver.go +++ b/receiver/dockerstatsreceiver/receiver.go @@ -258,7 +258,7 @@ func (r *metricsReceiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtyp 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.RecordContainerCPUOnlineDataPoint(now, int64(cpuStats.OnlineCPUs)) + r.mb.RecordContainerCPULogicalCountDataPoint(now, int64(cpuStats.OnlineCPUs)) for coreNum, v := range cpuStats.CPUUsage.PercpuUsage { r.mb.RecordContainerCPUUsagePercpuDataPoint(now, int64(v), fmt.Sprintf("cpu%s", strconv.Itoa(coreNum))) diff --git a/receiver/dockerstatsreceiver/receiver_test.go b/receiver/dockerstatsreceiver/receiver_test.go index 304f80316a48..3b3d97857af0 100644 --- a/receiver/dockerstatsreceiver/receiver_test.go +++ b/receiver/dockerstatsreceiver/receiver_test.go @@ -53,7 +53,7 @@ var ( ContainerCPUUsageSystem: metricEnabled, ContainerCPUUsageTotal: metricEnabled, ContainerCPUUsageUsermode: metricEnabled, - ContainerCPUOnline: metricEnabled, + ContainerCPULogicalCount: metricEnabled, ContainerMemoryActiveAnon: metricEnabled, ContainerMemoryActiveFile: metricEnabled, ContainerMemoryCache: metricEnabled, diff --git a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml index 8b1851710dc6..ed8b11ae67fa 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml @@ -52,13 +52,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: By - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml index 8a0032d6114b..c8993cc60740 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml @@ -112,13 +112,13 @@ resourceMetrics: timeUnixNano: "2000000" name: container.cpu.limit unit: '{cpus}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: 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 27031d6896b9..2d2b2012b861 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml @@ -195,13 +195,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: 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 b1e2f000c567..a49f19f1a981 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml @@ -104,13 +104,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: By - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml index ca8eadf502f6..bc63e4adefd5 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml @@ -201,13 +201,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml index 7ba7e05c9c3b..3c53049c89fd 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml @@ -201,13 +201,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml index cf914cf56851..695d98d8d88e 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml @@ -980,13 +980,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 1 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: From 50f47cdd2663963dadca20dc82c7e5e4136db1e2 Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Thu, 7 Mar 2024 15:02:12 +0100 Subject: [PATCH 5/6] fix test --- .../testdata/mock/two_containers/expected_metrics.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml index 695d98d8d88e..833c36139edc 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml @@ -195,13 +195,13 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: '{operations}' - - description: 'Number of online CPUs.' + - description: 'Number of cores available to the container.' gauge: dataPoints: - asInt: 1 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.online + name: container.cpu.logical_count unit: "{cpus}" - description: CPU shares set for the container. gauge: From e58ab497c43e04cdf0225a21ff467530a1fad35c Mon Sep 17 00:00:00 2001 From: Adam Boguszewski Date: Fri, 8 Mar 2024 10:11:53 +0100 Subject: [PATCH 6/6] rename logical_count -> logical.count --- receiver/dockerstatsreceiver/documentation.md | 2 +- .../internal/metadata/generated_config.go | 2 +- .../internal/metadata/generated_metrics.go | 6 +++--- .../internal/metadata/generated_metrics_test.go | 6 +++--- .../internal/metadata/testdata/config.yaml | 4 ++-- receiver/dockerstatsreceiver/metadata.yaml | 2 +- .../testdata/mock/cgroups_v2/expected_metrics.yaml | 2 +- .../testdata/mock/cpu_limit/expected_metrics.yaml | 2 +- .../testdata/mock/no_pids_stats/expected_metrics.yaml | 2 +- .../testdata/mock/pids_stats_max/expected_metrics.yaml | 2 +- .../testdata/mock/single_container/expected_metrics.yaml | 2 +- .../expected_metrics.yaml | 2 +- .../testdata/mock/two_containers/expected_metrics.yaml | 4 ++-- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/receiver/dockerstatsreceiver/documentation.md b/receiver/dockerstatsreceiver/documentation.md index 2a548ce1eb08..3840f9f6a072 100644 --- a/receiver/dockerstatsreceiver/documentation.md +++ b/receiver/dockerstatsreceiver/documentation.md @@ -306,7 +306,7 @@ This metric is only reported if the container has limits set with -cpus, -cpuset | ---- | ----------- | ---------- | | {cpus} | Gauge | Double | -### container.cpu.logical_count +### container.cpu.logical.count Number of cores available to the container. diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go index 0f5d7c39d5a9..94ce4b4db8bc 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_config.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_config.go @@ -34,7 +34,7 @@ type MetricsConfig struct { ContainerBlockioIoWaitTimeRecursive MetricConfig `mapstructure:"container.blockio.io_wait_time_recursive"` ContainerBlockioSectorsRecursive MetricConfig `mapstructure:"container.blockio.sectors_recursive"` ContainerCPULimit MetricConfig `mapstructure:"container.cpu.limit"` - ContainerCPULogicalCount MetricConfig `mapstructure:"container.cpu.logical_count"` + ContainerCPULogicalCount MetricConfig `mapstructure:"container.cpu.logical.count"` ContainerCPUShares MetricConfig `mapstructure:"container.cpu.shares"` ContainerCPUThrottlingDataPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.periods"` ContainerCPUThrottlingDataThrottledPeriods MetricConfig `mapstructure:"container.cpu.throttling_data.throttled_periods"` diff --git a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go index cd0841f6ca23..547d5410715a 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics.go @@ -507,9 +507,9 @@ type metricContainerCPULogicalCount struct { capacity int // max observed number of data points added to the metric. } -// init fills container.cpu.logical_count metric with initial data. +// init fills container.cpu.logical.count metric with initial data. func (m *metricContainerCPULogicalCount) init() { - m.data.SetName("container.cpu.logical_count") + m.data.SetName("container.cpu.logical.count") m.data.SetDescription("Number of cores available to the container.") m.data.SetUnit("{cpus}") m.data.SetEmptyGauge() @@ -4037,7 +4037,7 @@ func (mb *MetricsBuilder) RecordContainerCPULimitDataPoint(ts pcommon.Timestamp, mb.metricContainerCPULimit.recordDataPoint(mb.startTime, ts, val) } -// RecordContainerCPULogicalCountDataPoint adds a data point to container.cpu.logical_count metric. +// RecordContainerCPULogicalCountDataPoint adds a data point to container.cpu.logical.count metric. func (mb *MetricsBuilder) RecordContainerCPULogicalCountDataPoint(ts pcommon.Timestamp, val int64) { mb.metricContainerCPULogicalCount.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 e0e57157b7fc..addd9e9bdb11 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/dockerstatsreceiver/internal/metadata/generated_metrics_test.go @@ -508,9 +508,9 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) assert.Equal(t, float64(1), dp.DoubleValue()) - case "container.cpu.logical_count": - assert.False(t, validatedMetrics["container.cpu.logical_count"], "Found a duplicate in the metrics slice: container.cpu.logical_count") - validatedMetrics["container.cpu.logical_count"] = true + case "container.cpu.logical.count": + assert.False(t, validatedMetrics["container.cpu.logical.count"], "Found a duplicate in the metrics slice: container.cpu.logical.count") + validatedMetrics["container.cpu.logical.count"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) assert.Equal(t, "Number of cores available to the container.", ms.At(i).Description()) diff --git a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml index bdb0e1d06720..1c5dc2133db9 100644 --- a/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/dockerstatsreceiver/internal/metadata/testdata/config.yaml @@ -19,7 +19,7 @@ all_set: enabled: true container.cpu.limit: enabled: true - container.cpu.logical_count: + container.cpu.logical.count: enabled: true container.cpu.shares: enabled: true @@ -178,7 +178,7 @@ none_set: enabled: false container.cpu.limit: enabled: false - container.cpu.logical_count: + container.cpu.logical.count: enabled: false container.cpu.shares: enabled: false diff --git a/receiver/dockerstatsreceiver/metadata.yaml b/receiver/dockerstatsreceiver/metadata.yaml index 67afb8673bc6..38ecbaa628cc 100644 --- a/receiver/dockerstatsreceiver/metadata.yaml +++ b/receiver/dockerstatsreceiver/metadata.yaml @@ -151,7 +151,7 @@ metrics: unit: "1" gauge: value_type: int - container.cpu.logical_count: + container.cpu.logical.count: enabled: false description: "Number of cores available to the container." unit: "{cpus}" diff --git a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml index ed8b11ae67fa..0692645fe3bd 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cgroups_v2/expected_metrics.yaml @@ -58,7 +58,7 @@ resourceMetrics: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml index c8993cc60740..b546a2e2df85 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/cpu_limit/expected_metrics.yaml @@ -118,7 +118,7 @@ resourceMetrics: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: 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 2d2b2012b861..77ae12c06cca 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/no_pids_stats/expected_metrics.yaml @@ -201,7 +201,7 @@ resourceMetrics: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: 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 a49f19f1a981..efbaf5ff0508 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/pids_stats_max/expected_metrics.yaml @@ -110,7 +110,7 @@ resourceMetrics: - asInt: 2 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml index bc63e4adefd5..f4b4fe5ecf36 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container/expected_metrics.yaml @@ -207,7 +207,7 @@ resourceMetrics: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml index 3c53049c89fd..634773c41d6a 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/single_container_with_optional_resource_attributes/expected_metrics.yaml @@ -207,7 +207,7 @@ resourceMetrics: - asInt: 8 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: diff --git a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml index 833c36139edc..759dda74e978 100644 --- a/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml +++ b/receiver/dockerstatsreceiver/testdata/mock/two_containers/expected_metrics.yaml @@ -201,7 +201,7 @@ resourceMetrics: - asInt: 1 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: @@ -986,7 +986,7 @@ resourceMetrics: - asInt: 1 startTimeUnixNano: "1687762436124732000" timeUnixNano: "1687762436137493000" - name: container.cpu.logical_count + name: container.cpu.logical.count unit: "{cpus}" - description: CPU shares set for the container. gauge: