From 800a2575f3fc0699f947f736dbf1b225c041b139 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 26 Apr 2022 15:32:06 -0700 Subject: [PATCH] Support hist agg testing --- .../github.com/gocql/gocql/otelgocql/test/gocql_test.go | 6 ++++-- instrumentation/host/host_test.go | 4 ++-- instrumentation/runtime/runtime_test.go | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/otelgocql/test/gocql_test.go b/instrumentation/github.com/gocql/gocql/otelgocql/test/gocql_test.go index 153b8e1f477..c3771f2d24f 100644 --- a/instrumentation/github.com/gocql/gocql/otelgocql/test/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/otelgocql/test/gocql_test.go @@ -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{ @@ -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{ @@ -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, diff --git a/instrumentation/host/host_test.go b/instrumentation/host/host_test.go index 869fde445f9..5a7dae0c939 100644 --- a/instrumentation/host/host_test.go +++ b/instrumentation/host/host_test.go @@ -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") diff --git a/instrumentation/runtime/runtime_test.go b/instrumentation/runtime/runtime_test.go index 684b50c3042..f9694d13e44 100644 --- a/instrumentation/runtime/runtime_test.go +++ b/instrumentation/runtime/runtime_test.go @@ -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)) } } }