Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Jun 22, 2024
1 parent 5ac0112 commit 5ca7907
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 3 additions & 4 deletions instrumentation/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ func newCollector(minimumInterval time.Duration) *goCollector {
minimumInterval: minimumInterval,
}
for _, runtimeMetric := range runtimeMetrics {
s := metrics.Sample{Name: runtimeMetric}
g.sampleBuffer = append(g.sampleBuffer, s)
g.sampleMap[runtimeMetric] = &s
g.sampleBuffer = append(g.sampleBuffer, metrics.Sample{Name: runtimeMetric})
g.sampleMap[runtimeMetric] = &g.sampleBuffer[len(g.sampleBuffer)-1]
}
return g
}
Expand All @@ -210,7 +209,7 @@ func (g *goCollector) refresh() {
}

func (g *goCollector) get(name string) int64 {
if s, ok := g.sampleMap[name]; ok {
if s, ok := g.sampleMap[name]; ok && s.Value.Kind() == metrics.KindUint64 {
return int64(s.Value.Uint64())
}
return 0

Check warning on line 215 in instrumentation/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/runtime/runtime.go#L215

Added line #L215 was not covered by tests
Expand Down
14 changes: 14 additions & 0 deletions instrumentation/runtime/test/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,18 @@ func TestRuntimeWithLimit(t *testing.T) {
},
}
metricdatatest.AssertEqual(t, expectedScopeMetric, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())
assertNonZeroValues(t, rm.ScopeMetrics[0])
}

func assertNonZeroValues(t *testing.T, sm metricdata.ScopeMetrics) {
for _, m := range sm.Metrics {
switch a := m.Data.(type) {
case metricdata.Sum[int64]:
for _, dp := range a.DataPoints {
assert.True(t, dp.Value > 0)
}
default:
t.Fatalf("unexpected data type %v", a)
}
}
}

0 comments on commit 5ca7907

Please sign in to comment.