Skip to content

Commit

Permalink
Return metric SDK testing using metrictest (#2224)
Browse files Browse the repository at this point in the history
* Return metric SDK testing using metrictest

* Fix lint issues

* Support hist agg testing

* Revert dependabot fix

Instead fix in own PR:
#2225
  • Loading branch information
MrAlias committed Apr 27, 2022
1 parent 8b86920 commit 93b5a37
Show file tree
Hide file tree
Showing 19 changed files with 565 additions and 493 deletions.
Expand Up @@ -29,8 +29,8 @@ import (
"go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego/internal"
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/nonrecording"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/metric/metrictest"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestStatic(t *testing.T) {
defer replaceBeego()
sr := tracetest.NewSpanRecorder()
tracerProvider := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
meterProvider := nonrecording.NewNoopMeterProvider()
meterProvider, metricExporter := metrictest.NewTestMeterProvider()
file, err := ioutil.TempFile("", "static-*.html")
require.NoError(t, err)
defer os.Remove(file.Name())
Expand Down Expand Up @@ -220,8 +220,7 @@ func TestStatic(t *testing.T) {
spans := sr.Ended()
require.Len(t, spans, 1)
assertSpan(t, spans[0], tc)
// TODO: Replace with in memory exporter https://github.com/open-telemetry/opentelemetry-go/issues/2722
// assertMetrics(t, meterProvider.MeasurementBatches, tc)
assertMetrics(t, metricExporter.GetRecords(), tc)
}

func TestRender(t *testing.T) {
Expand Down Expand Up @@ -288,7 +287,7 @@ func TestRender(t *testing.T) {
func runTest(t *testing.T, tc *testCase, url string) {
sr := tracetest.NewSpanRecorder()
tracerProvider := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
meterProvider := nonrecording.NewNoopMeterProvider()
meterProvider, metricExporter := metrictest.NewTestMeterProvider()
addTestRoutes(t)
defer replaceBeego()

Expand Down Expand Up @@ -327,8 +326,7 @@ func runTest(t *testing.T, tc *testCase, url string) {
} else {
require.Len(t, spans, 0)
}
// TODO: Replace with in memory exporter https://github.com/open-telemetry/opentelemetry-go/issues/2722
// assertMetrics(t, meterProvider.MeasurementBatches, tc)
assertMetrics(t, metricExporter.GetRecords(), tc)
}

func defaultAttributes() []attribute.KeyValue {
Expand All @@ -347,14 +345,13 @@ func assertSpan(t *testing.T, span trace.ReadOnlySpan, tc *testCase) {
}
}

// TODO: Replace with in memory exporter https://github.com/open-telemetry/opentelemetry-go/issues/2722
// func assertMetrics(t *testing.T, batches []metrictest.Batch, tc *testCase) {
// for _, batch := range batches {
// for _, att := range tc.expectedAttributes {
// require.Contains(t, batch.Labels, att)
// }
// }
// }
func assertMetrics(t *testing.T, records []metrictest.ExportRecord, tc *testCase) {
for _, record := range records {
for _, att := range tc.expectedAttributes {
require.Contains(t, record.Attributes, att)
}
}
}

// ------------------------------------------ Test Cases

Expand Down
Expand Up @@ -8,8 +8,8 @@ require (
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego v0.31.0
go.opentelemetry.io/contrib/propagators/b3 v1.6.0
go.opentelemetry.io/otel v1.6.3
go.opentelemetry.io/otel/metric v0.29.0
go.opentelemetry.io/otel/sdk v1.6.3
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2
)

replace (
Expand Down
Expand Up @@ -11,6 +11,8 @@ github.com/astaxie/beego v1.12.3 h1:SAQkdD2ePye+v8Gn1r4X6IKZM1wd28EyUOVQ3PDSOOQ=
github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -153,6 +155,8 @@ go.opentelemetry.io/otel/metric v0.29.0 h1:7unM/I13Dbc1VHw8lTPQ7zfNIgkhcb8BZhujX
go.opentelemetry.io/otel/metric v0.29.0/go.mod h1:HahKFp1OC1RNTsuO/HNMBHHJR+dmHZ7wLARRgGDwjLQ=
go.opentelemetry.io/otel/sdk v1.6.3 h1:prSHYdwCQOX5DrsEzxowH3nLhoAzEBdZhvrR79scfLs=
go.opentelemetry.io/otel/sdk v1.6.3/go.mod h1:A4iWF7HTXa+GWL/AaqESz28VuSBIcZ+0CV+IzJ5NMiQ=
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2 h1:w97SUMLzaACqAmuyNR6S+1N2o90Y3Kcvz6S8xp8uysM=
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2/go.mod h1:IFkFNKI8Gq8zBdqOKdODCL9+LInBZLXaGpqSIKphNuU=
go.opentelemetry.io/otel/trace v1.6.3 h1:IqN4L+5b0mPNjdXIiZ90Ni4Bl5BRkDQywePLWemd9bc=
go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
Expand Up @@ -9,6 +9,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql/otelgocql v0.31.0
go.opentelemetry.io/otel v1.6.3
go.opentelemetry.io/otel/sdk v1.6.3
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2
go.opentelemetry.io/otel/trace v1.6.3
)

Expand Down
4 changes: 4 additions & 0 deletions instrumentation/github.com/gocql/gocql/otelgocql/test/go.sum
@@ -1,3 +1,5 @@
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand Down Expand Up @@ -37,6 +39,8 @@ go.opentelemetry.io/otel/metric v0.29.0 h1:7unM/I13Dbc1VHw8lTPQ7zfNIgkhcb8BZhujX
go.opentelemetry.io/otel/metric v0.29.0/go.mod h1:HahKFp1OC1RNTsuO/HNMBHHJR+dmHZ7wLARRgGDwjLQ=
go.opentelemetry.io/otel/sdk v1.6.3 h1:prSHYdwCQOX5DrsEzxowH3nLhoAzEBdZhvrR79scfLs=
go.opentelemetry.io/otel/sdk v1.6.3/go.mod h1:A4iWF7HTXa+GWL/AaqESz28VuSBIcZ+0CV+IzJ5NMiQ=
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2 h1:w97SUMLzaACqAmuyNR6S+1N2o90Y3Kcvz6S8xp8uysM=
go.opentelemetry.io/otel/sdk/metric v0.29.1-0.20220425151224-b8e4241a32f2/go.mod h1:IFkFNKI8Gq8zBdqOKdODCL9+LInBZLXaGpqSIKphNuU=
go.opentelemetry.io/otel/trace v1.6.3 h1:IqN4L+5b0mPNjdXIiZ90Ni4Bl5BRkDQywePLWemd9bc=
go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw=
Expand Down

0 comments on commit 93b5a37

Please sign in to comment.