MCPcopy
hub / github.com/grpc/grpc-go / TestAllMetricsOneFunction

Method TestAllMetricsOneFunction

stats/opentelemetry/e2e_test.go:410–538  ·  view source on GitHub ↗

TestAllMetricsOneFunction tests emitted metrics from OpenTelemetry instrumentation component. It then configures a system with a gRPC Client and gRPC server with the OpenTelemetry Dial and Server Option configured specifying all the metrics provided by this package, and makes a Unary RPC and a Strea

(t *testing.T)

Source from the content-addressed store, hash-verified

408// on the Client (no StaticMethodCallOption set) and Server. The method
409// attribute on subsequent metrics should be bucketed in "other".
410func (s) TestAllMetricsOneFunction(t *testing.T) {
411 mo, reader := defaultMetricsOptions(t, nil)
412 ss := setupStubServer(t, mo, nil)
413 defer ss.Stop()
414 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
415 defer cancel()
416 // Make two RPC's, a unary RPC and a streaming RPC. These should cause
417 // certain metrics to be emitted, which should be observed through the
418 // Metric Reader.
419 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{Payload: &testpb.Payload{
420 Body: make([]byte, 10000),
421 }}, grpc.UseCompressor(gzip.Name)); err != nil { // Deterministic compression.
422 t.Fatalf("Unexpected error from UnaryCall: %v", err)
423 }
424 stream, err := ss.Client.FullDuplexCall(ctx)
425 if err != nil {
426 t.Fatalf("ss.Client.FullDuplexCall failed: %f", err)
427 }
428
429 stream.CloseSend()
430 if _, err = stream.Recv(); err != io.EOF {
431 t.Fatalf("stream.Recv received an unexpected error: %v, expected an EOF error", err)
432 }
433
434 rm := &metricdata.ResourceMetrics{}
435 reader.Collect(ctx, rm)
436
437 gotMetrics := map[string]metricdata.Metrics{}
438 for _, sm := range rm.ScopeMetrics {
439 for _, m := range sm.Metrics {
440 gotMetrics[m.Name] = m
441 }
442 }
443
444 wantMetrics := testutils.MetricData(testutils.MetricDataOptions{
445 Target: ss.Target,
446 UnaryCompressedMessageSize: float64(57),
447 })
448 gotMetrics = testutils.WaitForServerMetrics(ctx, t, reader, gotMetrics, wantMetrics)
449 testutils.CompareMetrics(t, gotMetrics, wantMetrics)
450
451 stream, err = ss.Client.FullDuplexCall(ctx)
452 if err != nil {
453 t.Fatalf("ss.Client.FullDuplexCall failed: %f", err)
454 }
455
456 stream.CloseSend()
457 if _, err = stream.Recv(); err != io.EOF {
458 t.Fatalf("stream.Recv received an unexpected error: %v, expected an EOF error", err)
459 }
460 // This Invoke doesn't pass the StaticMethodCallOption. Thus, the method
461 // attribute should become "other" on client side metrics. Since it is also
462 // not registered on the server either, it should also become "other" on the
463 // server metrics method attribute.
464 ss.CC.Invoke(ctx, "/grpc.testing.TestService/UnregisteredCall", nil, nil, []grpc.CallOption{}...)
465 ss.CC.Invoke(ctx, "/grpc.testing.TestService/UnregisteredCall", nil, nil, []grpc.CallOption{}...)
466 ss.CC.Invoke(ctx, "/grpc.testing.TestService/UnregisteredCall", nil, nil, []grpc.CallOption{}...)
467

Callers

nothing calls this directly

Calls 14

UseCompressorFunction · 0.92
MetricDataFunction · 0.92
WaitForServerMetricsFunction · 0.92
CompareMetricsFunction · 0.92
defaultMetricsOptionsFunction · 0.85
setupStubServerFunction · 0.85
StopMethod · 0.65
UnaryCallMethod · 0.65
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65
CloseSendMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected