Skip to content

Commit

Permalink
Support hist agg testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Apr 26, 2022
1 parent dba38ee commit 800a257
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Expand Up @@ -112,6 +112,7 @@ func TestQuery(t *testing.T) {
}

// Check metrics
require.NoError(t, metricExporter.Collect(context.Background()))
actual := obtainTestRecords(metricExporter.GetRecords())
require.Len(t, actual, 3)
expected := []testRecord{
Expand Down Expand Up @@ -223,6 +224,7 @@ func TestBatch(t *testing.T) {
}

// Check metrics
require.NoError(t, metricExporter.Collect(context.Background()))
actual := obtainTestRecords(metricExporter.GetRecords())
require.Len(t, actual, 2)
expected := []testRecord{
Expand Down Expand Up @@ -377,12 +379,12 @@ func obtainTestRecords(mers []metrictest.ExportRecord) []testRecord {
for _, mer := range mers {
var n number.Number
switch mer.AggregationKind {
case aggregation.SumKind:
case aggregation.SumKind, aggregation.HistogramKind:
n = mer.Sum
case aggregation.LastValueKind:
n = mer.LastValue
default:
panic(fmt.Sprintf("unsupported aggregation type: %T", mer.AggregationKind))
panic(fmt.Sprintf("unsupported aggregation type: %v", mer.AggregationKind))
}
records = append(
records,
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/host/host_test.go
Expand Up @@ -53,12 +53,12 @@ func getMetric(exp *metrictest.Exporter, name string, lbl attribute.KeyValue) fl
continue
}
switch r.AggregationKind {
case aggregation.SumKind:
case aggregation.SumKind, aggregation.HistogramKind:
return r.Sum.CoerceToFloat64(r.NumberKind)
case aggregation.LastValueKind:
return r.LastValue.CoerceToFloat64(r.NumberKind)
default:
panic(fmt.Sprintf("invalid aggregation type: %T", r.AggregationKind))
panic(fmt.Sprintf("invalid aggregation type: %v", r.AggregationKind))
}
}
panic("Could not locate a metric in test output")
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/runtime/runtime_test.go
Expand Up @@ -41,12 +41,12 @@ func getGCCount(exp *metrictest.Exporter) int {
for _, r := range exp.GetRecords() {
if r.InstrumentName == "process.runtime.go.gc.count" {
switch r.AggregationKind {
case aggregation.SumKind:
case aggregation.SumKind, aggregation.HistogramKind:
return int(r.Sum.CoerceToInt64(r.NumberKind))
case aggregation.LastValueKind:
return int(r.LastValue.CoerceToInt64(r.NumberKind))
default:
panic(fmt.Sprintf("invalid aggregation type: %T", r.AggregationKind))
panic(fmt.Sprintf("invalid aggregation type: %v", r.AggregationKind))
}
}
}
Expand Down

0 comments on commit 800a257

Please sign in to comment.