Skip to content

Commit e3dff43

Browse files
committed
Use logical CPU count for num processors
1 parent bb98a58 commit e3dff43

9 files changed

Lines changed: 59 additions & 11 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
change_type: breaking
2+
component: exporter/signalfx
3+
note: "Translate `cpu.num_processors` from `system.cpu.logical.count`."
4+
issues: [49296]
5+
subtext: |
6+
The exporter no longer derives `cpu.num_processors` by counting per-core `system.cpu.time` series.
7+
Enable `system.cpu.logical.count` in the host_metrics receiver CPU scraper to emit `cpu.num_processors` with the default SignalFx translations.
8+
change_logs: [user]

exporter/signalfxexporter/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The following configuration options can also be configured:
112112
filesystem is not `/`. Example: if the root filesystem is mounted under `/hostfs`, set
113113
`root_path` to `/hostfs`.
114114
Note: all components using `root_path` must have the same value; this currently applies
115-
to hostmetrics receiver and signalfx exporter.
115+
to host_metrics receiver and signalfx exporter.
116116
- `exclude_properties`: A list of property filters to limit dimension update content.
117117
Property filters can contain any number of the following fields, supporting (negated)
118118
string literals, re2 `/regex/`, and [glob](https://github.com/gobwas/glob) syntax values:
@@ -208,7 +208,7 @@ exporters:
208208
209209
The default translation rules defined in [`translation/default_translation_rules.yaml`](./internal/translation/default_translation_rules.yaml) are used by the SignalFx exporter
210210
to help ensure compatibility with custom charts and dashboards when using the OpenTelemetry Collector.
211-
The default rules will create the following aggregated metrics from the [`hostmetrics` receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md):
211+
The default rules will create the following aggregated metrics from the [`host_metrics` receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/README.md):
212212
213213
* cpu.idle
214214
* cpu.interrupt
@@ -237,6 +237,9 @@ The default rules will create the following aggregated metrics from the [`hostme
237237
* vmpage_io.swap.in
238238
* vmpage_io.swap.out
239239
240+
`cpu.num_processors` is copied from `system.cpu.logical.count`, which must be enabled in the host_metrics receiver
241+
CPU scraper.
242+
240243
## Example Config
241244
242245
```yaml

exporter/signalfxexporter/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func TestUnmarshalExcludeMetrics(t *testing.T) {
501501
{
502502
name: "empty config",
503503
cfg: &Config{},
504-
excludeMetricsLen: 11,
504+
excludeMetricsLen: 12,
505505
},
506506
{
507507
name: "existing exclude config",
@@ -512,7 +512,7 @@ func TestUnmarshalExcludeMetrics(t *testing.T) {
512512
},
513513
},
514514
},
515-
excludeMetricsLen: 12,
515+
excludeMetricsLen: 13,
516516
},
517517
{
518518
name: "existing empty exclude config",

exporter/signalfxexporter/exporter_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,12 @@ func TestDefaultSystemCPUTimeExcludedAndTranslated(t *testing.T) {
16471647
dp.Attributes().PutStr("state", state)
16481648
}
16491649
}
1650+
cpuCount := sm.Metrics().AppendEmpty()
1651+
cpuCount.SetName("system.cpu.logical.count")
1652+
cpuCountSum := cpuCount.SetEmptySum()
1653+
cpuCountSum.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
1654+
cpuCountSum.DataPoints().AppendEmpty().SetIntValue(32)
1655+
16501656
dps := converter.MetricsToSignalFxV2(md)
16511657
found := map[string]int64{}
16521658
for _, dp := range dps {

exporter/signalfxexporter/factory_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,19 @@ func testGetTranslator(t *testing.T) *translation.MetricTranslator {
533533
return tr
534534
}
535535

536+
func appendLogicalCPUCountDataPoint(dps []*sfxpb.DataPoint, value int64) []*sfxpb.DataPoint {
537+
metricType := sfxpb.MetricType_GAUGE
538+
timestamp := int64(1597439222299)
539+
return append(dps, &sfxpb.DataPoint{
540+
Metric: "system.cpu.logical.count",
541+
Timestamp: timestamp,
542+
MetricType: &metricType,
543+
Value: sfxpb.Datum{
544+
IntValue: &value,
545+
},
546+
})
547+
}
548+
536549
func TestDefaultCPUTranslations(t *testing.T) {
537550
var pts1 []*sfxpb.DataPoint
538551
err := testReadJSON("testdata/json/system.cpu.time.1.json", &pts1)
@@ -541,6 +554,7 @@ func TestDefaultCPUTranslations(t *testing.T) {
541554
var pts2 []*sfxpb.DataPoint
542555
err = testReadJSON("testdata/json/system.cpu.time.2.json", &pts2)
543556
require.NoError(t, err)
557+
pts2 = appendLogicalCPUCountDataPoint(pts2, 8)
544558

545559
tr := testGetTranslator(t)
546560
log := zap.NewNop()
@@ -566,6 +580,7 @@ func TestDefaultCPUTranslations(t *testing.T) {
566580

567581
cpuNumProcessors := m["cpu.num_processors"]
568582
require.Len(t, cpuNumProcessors, 1)
583+
require.Equal(t, 8, int(*cpuNumProcessors[0].Value.IntValue))
569584

570585
cpuIdle := m["cpu.idle"]
571586
require.Len(t, cpuIdle, 1)

exporter/signalfxexporter/internal/translation/default_metrics.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exclude_metrics:
2525
# Metrics in OpenTelemetry Convention.
2626

2727
# CPU Metrics.
28+
- metric_name: system.cpu.logical.count
2829
- metric_name: system.cpu.time
2930
dimensions:
3031
state: [idle, interrupt, nice, softirq, steal, system, user, wait]

exporter/signalfxexporter/internal/translation/default_translation_rules.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,10 @@ translation_rules:
8888
sf_temp.cpu.softirq: int
8989
sf_temp.cpu.nice: int
9090

91-
# compute cpu.num_processors
91+
# convert cpu.num_processors metric
9292
- action: copy_metrics
9393
mapping:
94-
sf_temp.cpu.idle: sf_temp.cpu.num_processors
95-
- action: aggregate_metric
96-
metric_name: sf_temp.cpu.num_processors
97-
aggregation_method: count
98-
without_dimensions:
99-
- cpu
94+
system.cpu.logical.count: sf_temp.cpu.num_processors
10095

10196
- action: aggregate_metric
10297
metric_name: sf_temp.cpu.idle

exporter/signalfxexporter/testdata/hostmetrics_system_cpu_time_1.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ resourceMetrics:
9090
timeUnixNano: "1136214245000000000"
9191
isMonotonic: true
9292
unit: s
93+
- description: Number of available logical CPUs.
94+
name: system.cpu.logical.count
95+
sum:
96+
aggregationTemporality: 2
97+
dataPoints:
98+
- asInt: "2"
99+
startTimeUnixNano: "1662132756000000000"
100+
timeUnixNano: "1136214245000000000"
101+
isMonotonic: false
102+
unit: "{cpu}"
93103
scope:
94104
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper
95105
version: latest

exporter/signalfxexporter/testdata/hostmetrics_system_cpu_time_2.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ resourceMetrics:
9090
timeUnixNano: "1136214250000000000"
9191
isMonotonic: true
9292
unit: s
93+
- description: Number of available logical CPUs.
94+
name: system.cpu.logical.count
95+
sum:
96+
aggregationTemporality: 2
97+
dataPoints:
98+
- asInt: "2"
99+
startTimeUnixNano: "1662132756000000000"
100+
timeUnixNano: "1136214250000000000"
101+
isMonotonic: false
102+
unit: "{cpu}"
93103
scope:
94104
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper
95105
version: latest

0 commit comments

Comments
 (0)