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

Function pollForWantMetrics

stats/opentelemetry/e2e_test.go:777–798  ·  view source on GitHub ↗

pollForWantMetrics polls for the wantMetrics to show up on reader. Returns an error if metric is present but not equal to expected, or if the wantMetrics do not show up during the context timeout.

(ctx context.Context, t *testing.T, reader *metric.ManualReader, wantMetrics []metricdata.Metrics)

Source from the content-addressed store, hash-verified

775// error if metric is present but not equal to expected, or if the wantMetrics
776// do not show up during the context timeout.
777func pollForWantMetrics(ctx context.Context, t *testing.T, reader *metric.ManualReader, wantMetrics []metricdata.Metrics) error {
778 for ; ctx.Err() == nil; <-time.After(time.Millisecond) {
779 gotMetrics := metricsDataFromReader(ctx, reader)
780 containsAllMetrics := true
781 for _, metric := range wantMetrics {
782 val, ok := gotMetrics[metric.Name]
783 if !ok {
784 containsAllMetrics = false
785 break
786 }
787 if !metricdatatest.AssertEqual(t, metric, val, metricdatatest.IgnoreValue(), metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars()) {
788 return fmt.Errorf("metrics data type not equal for metric: %v", metric.Name)
789 }
790 }
791 if containsAllMetrics {
792 return nil
793 }
794 time.Sleep(5 * time.Millisecond)
795 }
796
797 return fmt.Errorf("error waiting for metrics %v: %v", wantMetrics, ctx.Err())
798}
799
800// TestMetricsAndTracesOptionEnabled verifies the integration of metrics and traces
801// emitted by the OpenTelemetry instrumentation in a gRPC environment. It sets up a

Callers 3

TestWRRMetricsMethod · 0.85
TestSubChannelMetricsMethod · 0.85
runDisconnectScenarioFunction · 0.85

Calls 3

ErrMethod · 0.80
metricsDataFromReaderFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected