Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelgrpc: Use metricdatatest #4483

Closed
pellared opened this issue Oct 26, 2023 · 0 comments · Fixed by #4499
Closed

otelgrpc: Use metricdatatest #4483

pellared opened this issue Oct 26, 2023 · 0 comments · Fixed by #4499
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed instrumentation: otelgrpc

Comments

@pellared
Copy link
Member

I suggest using metricdatatest instead.

	want := metricdata.ScopeMetrics{
		Scope: instrumentation.Scope{
			Name:      "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc",
			SchemaURL: "https://opentelemetry.io/schemas/1.17.0",
			Version:   otelgrpc.Version(),
		},
		Metrics: []metricdata.Metrics{
			{
				Name:        "rpc.server.duration",
				Description: "Measures the duration of inbound RPC.",
				Unit:        "ms",
				Data: metricdata.Histogram[int64]{
					Temporality: metricdata.CumulativeTemporality,
					DataPoints: []metricdata.HistogramDataPoint[int64]{
						{
							Attributes: attribute.NewSet(
								semconv.RPCMethod(name),
								semconv.RPCService(serviceName),
								otelgrpc.RPCSystemGRPC,
								otelgrpc.GRPCStatusCodeKey.Int64(int64(code)),
							),
						},
					},
				},
			},
		},
	}

	rm := metricdata.ResourceMetrics{}
	err := reader.Collect(context.Background(), &rm)
	assert.NoError(t, err)
	require.Len(t, rm.ScopeMetrics, 1)
	metricdatatest.AssertEqual(t, want, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())

To make this working you would also need to change the TestUnaryServerInterceptor to update to setup providers, recorders etc for each test case. I also noticed that the providers are not being shutdown.

I think it is better to address it in a separate PR as I think this refactoring could be done for most of the gRPC tests.

Originally posted by @pellared in #4481 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed instrumentation: otelgrpc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant