WaitForServerMetrics waits for eventual server metrics (not emitted synchronously with client side rpc returning).
(ctx context.Context, t *testing.T, mr *metric.ManualReader, gotMetrics map[string]metricdata.Metrics, wantMetrics []metricdata.Metrics)
| 807 | // WaitForServerMetrics waits for eventual server metrics (not emitted |
| 808 | // synchronously with client side rpc returning). |
| 809 | func WaitForServerMetrics(ctx context.Context, t *testing.T, mr *metric.ManualReader, gotMetrics map[string]metricdata.Metrics, wantMetrics []metricdata.Metrics) map[string]metricdata.Metrics { |
| 810 | terminalMetrics := []string{ |
| 811 | "grpc.server.call.sent_total_compressed_message_size", |
| 812 | "grpc.server.call.rcvd_total_compressed_message_size", |
| 813 | "grpc.client.attempt.duration", |
| 814 | "grpc.client.call.duration", |
| 815 | "grpc.server.call.duration", |
| 816 | } |
| 817 | for _, metric := range wantMetrics { |
| 818 | if !slices.Contains(terminalMetrics, metric.Name) { |
| 819 | continue |
| 820 | } |
| 821 | // Sync the metric reader to see the event because stats.End is |
| 822 | // handled async server side. Thus, poll until metrics created from |
| 823 | // stats.End show up. |
| 824 | var err error |
| 825 | if gotMetrics, err = waitForServerCompletedRPCs(ctx, mr, metric); err != nil { // move to shared helper |
| 826 | t.Fatal(err) |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | return gotMetrics |
| 831 | } |