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)
| 775 | // error if metric is present but not equal to expected, or if the wantMetrics |
| 776 | // do not show up during the context timeout. |
| 777 | func 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 |
no test coverage detected