Skip to content

Commit cd0e3ef

Browse files
authored
hostmetrics: don't warn on missing metrics (#177)
Don't warn if system.cpu.logical.count is missing, as it's an optional metric. The warning is particularly unhelpful in gateway deployments, where the central operations team has no control over what is being sent to the gateway.
1 parent 5c595aa commit cd0e3ef

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

remappers/hostmetrics/cpu.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package hostmetrics
1919

2020
import (
21-
"errors"
22-
2321
"go.opentelemetry.io/collector/pdata/pcommon"
2422
"go.opentelemetry.io/collector/pdata/pmetric"
2523

@@ -146,7 +144,10 @@ func remapCPUMetrics(
146144
)
147145

148146
if numCores == 0 {
149-
return errors.New("system.cpu.logical.count metric is missing in the hostmetrics")
147+
// system.cpu.logical.count is optional, and if it's not
148+
// present we can't calculate the normalized values.
149+
// This is not an error, so we just return early.
150+
return nil
150151
}
151152

152153
totalNorm := totalPercent / float64(numCores)

remappers/hostmetrics/hostmetrics_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import (
2929
"github.com/stretchr/testify/assert"
3030
"go.opentelemetry.io/collector/pdata/pcommon"
3131
"go.opentelemetry.io/collector/pdata/pmetric"
32+
"go.uber.org/zap"
33+
"go.uber.org/zap/zapcore"
3234
"go.uber.org/zap/zaptest"
35+
"go.uber.org/zap/zaptest/observer"
3336
)
3437

3538
var (
@@ -348,10 +351,16 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
348351
resource := pcommon.NewResource()
349352
resource.Attributes().FromRaw(tc.resourceAttrs)
350353

354+
core, observedLogs := observer.New(zapcore.WarnLevel)
355+
logger := zap.New(core)
356+
351357
actual := pmetric.NewMetricSlice()
352-
r := NewRemapper(zaptest.NewLogger(t), remapOpts...)
358+
r := NewRemapper(logger, remapOpts...)
353359
r.Remap(sm, actual, resource)
354360
assert.Empty(t, cmp.Diff(tc.expected, testutils.MetricSliceToTestMetric(t, actual), cmpopts.EquateApprox(0, 0.001)))
361+
362+
// There should be no warning or error logs.
363+
assert.Zero(t, observedLogs.Len())
355364
})
356365
}
357366
}

0 commit comments

Comments
 (0)