diff --git a/receiver/podmanreceiver/documentation.md b/receiver/podmanreceiver/documentation.md index 59e3703d3005..6e5bb91e9912 100644 --- a/receiver/podmanreceiver/documentation.md +++ b/receiver/podmanreceiver/documentation.md @@ -46,7 +46,7 @@ Total CPU time consumed per CPU-core. | Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | | ---- | ----------- | ---------- | ----------------------- | --------- | -| ns | Sum | Int | Cumulative | true | +| s | Sum | Int | Cumulative | true | #### Attributes @@ -60,7 +60,7 @@ System CPU usage. | Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | | ---- | ----------- | ---------- | ----------------------- | --------- | -| ns | Sum | Int | Cumulative | true | +| s | Sum | Int | Cumulative | true | ### container.cpu.usage.total @@ -68,7 +68,7 @@ Total CPU time consumed. | Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | | ---- | ----------- | ---------- | ----------------------- | --------- | -| ns | Sum | Int | Cumulative | true | +| s | Sum | Int | Cumulative | true | ### container.memory.percent diff --git a/receiver/podmanreceiver/internal/metadata/generated_config.go b/receiver/podmanreceiver/internal/metadata/generated_config.go index 49a9beec9328..7edc12b42acf 100644 --- a/receiver/podmanreceiver/internal/metadata/generated_config.go +++ b/receiver/podmanreceiver/internal/metadata/generated_config.go @@ -15,7 +15,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { if parser == nil { return nil } - err := parser.Unmarshal(ms, confmap.WithErrorUnused()) + err := parser.Unmarshal(ms) if err != nil { return err } @@ -87,7 +87,7 @@ func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error { if parser == nil { return nil } - err := parser.Unmarshal(rac, confmap.WithErrorUnused()) + err := parser.Unmarshal(rac) if err != nil { return err } diff --git a/receiver/podmanreceiver/internal/metadata/generated_metrics.go b/receiver/podmanreceiver/internal/metadata/generated_metrics.go index 57e96230f60d..b2a628971b8b 100644 --- a/receiver/podmanreceiver/internal/metadata/generated_metrics.go +++ b/receiver/podmanreceiver/internal/metadata/generated_metrics.go @@ -172,7 +172,7 @@ type metricContainerCPUUsagePercpu struct { func (m *metricContainerCPUUsagePercpu) init() { m.data.SetName("container.cpu.usage.percpu") m.data.SetDescription("Total CPU time consumed per CPU-core.") - m.data.SetUnit("ns") + m.data.SetUnit("s") m.data.SetEmptySum() m.data.Sum().SetIsMonotonic(true) m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) @@ -225,7 +225,7 @@ type metricContainerCPUUsageSystem struct { func (m *metricContainerCPUUsageSystem) init() { m.data.SetName("container.cpu.usage.system") m.data.SetDescription("System CPU usage.") - m.data.SetUnit("ns") + m.data.SetUnit("s") m.data.SetEmptySum() m.data.Sum().SetIsMonotonic(true) m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) @@ -276,7 +276,7 @@ type metricContainerCPUUsageTotal struct { func (m *metricContainerCPUUsageTotal) init() { m.data.SetName("container.cpu.usage.total") m.data.SetDescription("Total CPU time consumed.") - m.data.SetUnit("ns") + m.data.SetUnit("s") m.data.SetEmptySum() m.data.Sum().SetIsMonotonic(true) m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) diff --git a/receiver/podmanreceiver/internal/metadata/generated_metrics_test.go b/receiver/podmanreceiver/internal/metadata/generated_metrics_test.go index 03156775c24f..0b9a0868d03a 100644 --- a/receiver/podmanreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/podmanreceiver/internal/metadata/generated_metrics_test.go @@ -172,7 +172,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "Total CPU time consumed per CPU-core.", ms.At(i).Description()) - assert.Equal(t, "ns", ms.At(i).Unit()) + assert.Equal(t, "s", 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) @@ -189,7 +189,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "System CPU usage.", ms.At(i).Description()) - assert.Equal(t, "ns", ms.At(i).Unit()) + assert.Equal(t, "s", 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) @@ -203,7 +203,7 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "Total CPU time consumed.", ms.At(i).Description()) - assert.Equal(t, "ns", ms.At(i).Unit()) + assert.Equal(t, "s", 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) diff --git a/receiver/podmanreceiver/metadata.yaml b/receiver/podmanreceiver/metadata.yaml index 62c1995d95f4..a981c3e39798 100644 --- a/receiver/podmanreceiver/metadata.yaml +++ b/receiver/podmanreceiver/metadata.yaml @@ -36,7 +36,7 @@ metrics: container.cpu.usage.system: enabled: true description: "System CPU usage." - unit: ns + unit: s sum: value_type: int monotonic: true @@ -44,7 +44,7 @@ metrics: container.cpu.usage.total: enabled: true description: "Total CPU time consumed." - unit: ns + unit: s sum: value_type: int monotonic: true @@ -52,7 +52,7 @@ metrics: container.cpu.usage.percpu: enabled: true description: "Total CPU time consumed per CPU-core." - unit: ns + unit: s sum: value_type: int monotonic: true diff --git a/receiver/podmanreceiver/receiver.go b/receiver/podmanreceiver/receiver.go index 9eedd7d4e448..85239536077c 100644 --- a/receiver/podmanreceiver/receiver.go +++ b/receiver/podmanreceiver/receiver.go @@ -130,12 +130,12 @@ func (r *metricsReceiver) recordContainerStats(now pcommon.Timestamp, container } func (r *metricsReceiver) recordCPUMetrics(now pcommon.Timestamp, stats *containerStats) { - r.mb.RecordContainerCPUUsageSystemDataPoint(now, int64(stats.CPUSystemNano)) - r.mb.RecordContainerCPUUsageTotalDataPoint(now, int64(stats.CPUNano)) + r.mb.RecordContainerCPUUsageSystemDataPoint(now, int64(toSecondsWithNanosecondPrecision(stats.CPUSystemNano))) + r.mb.RecordContainerCPUUsageTotalDataPoint(now, int64(toSecondsWithNanosecondPrecision(stats.CPUNano))) r.mb.RecordContainerCPUPercentDataPoint(now, stats.CPU) for i, cpu := range stats.PerCPU { - r.mb.RecordContainerCPUUsagePercpuDataPoint(now, int64(cpu), fmt.Sprintf("cpu%d", i)) + r.mb.RecordContainerCPUUsagePercpuDataPoint(now, int64(toSecondsWithNanosecondPrecision(cpu)), fmt.Sprintf("cpu%d", i)) } } @@ -155,3 +155,8 @@ func (r *metricsReceiver) recordIOMetrics(now pcommon.Timestamp, stats *containe r.mb.RecordContainerBlockioIoServiceBytesRecursiveReadDataPoint(now, int64(stats.BlockInput)) r.mb.RecordContainerBlockioIoServiceBytesRecursiveWriteDataPoint(now, int64(stats.BlockOutput)) } + +// nanoseconds to seconds conversion truncating the fractional part +func toSecondsWithNanosecondPrecision(nanoseconds uint64) uint64 { + return nanoseconds / 1e9 +} diff --git a/receiver/podmanreceiver/record_metrics_test.go b/receiver/podmanreceiver/record_metrics_test.go index f575f7f14e47..0e76eeec92cc 100644 --- a/receiver/podmanreceiver/record_metrics_test.go +++ b/receiver/podmanreceiver/record_metrics_test.go @@ -61,15 +61,15 @@ func assertStatsEqualToMetrics(t *testing.T, podmanStats *containerStats, md pme assertMetricEqual(t, m, pmetric.MetricTypeSum, []point{{intVal: podmanStats.BlockInput}}) case "container.cpu.usage.system": - assertMetricEqual(t, m, pmetric.MetricTypeSum, []point{{intVal: podmanStats.CPUSystemNano}}) + assertMetricEqual(t, m, pmetric.MetricTypeSum, []point{{intVal: toSecondsWithNanosecondPrecision(podmanStats.CPUSystemNano)}}) case "container.cpu.usage.total": - assertMetricEqual(t, m, pmetric.MetricTypeSum, []point{{intVal: podmanStats.CPUNano}}) + assertMetricEqual(t, m, pmetric.MetricTypeSum, []point{{intVal: toSecondsWithNanosecondPrecision(podmanStats.CPUNano)}}) case "container.cpu.percent": assertMetricEqual(t, m, pmetric.MetricTypeGauge, []point{{doubleVal: podmanStats.CPU}}) case "container.cpu.usage.percpu": points := make([]point, len(podmanStats.PerCPU)) for i, v := range podmanStats.PerCPU { - points[i] = point{intVal: v, attributes: map[string]string{"core": fmt.Sprintf("cpu%d", i)}} + points[i] = point{intVal: toSecondsWithNanosecondPrecision(v), attributes: map[string]string{"core": fmt.Sprintf("cpu%d", i)}} } assertMetricEqual(t, m, pmetric.MetricTypeSum, points)