CompareMetrics asserts wantMetrics are what we expect. For duration metrics makes sure the data point is within possible testing time (five seconds from context timeout).
(t *testing.T, gotMetrics map[string]metricdata.Metrics, wantMetrics []metricdata.Metrics)
| 769 | // makes sure the data point is within possible testing time (five seconds from |
| 770 | // context timeout). |
| 771 | func CompareMetrics(t *testing.T, gotMetrics map[string]metricdata.Metrics, wantMetrics []metricdata.Metrics) { |
| 772 | for _, metric := range wantMetrics { |
| 773 | val, ok := gotMetrics[metric.Name] |
| 774 | if !ok { |
| 775 | t.Errorf("Metric %v not present in recorded metrics", metric.Name) |
| 776 | continue |
| 777 | } |
| 778 | |
| 779 | if metric.Name == "grpc.server.call.sent_total_compressed_message_size" || metric.Name == "grpc.server.call.rcvd_total_compressed_message_size" { |
| 780 | val := gotMetrics[metric.Name] |
| 781 | if !metricdatatest.AssertEqual(t, metric, val, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars()) { |
| 782 | t.Errorf("Metrics data type not equal for metric: %v", metric.Name) |
| 783 | } |
| 784 | continue |
| 785 | } |
| 786 | |
| 787 | // If one of the duration metrics, ignore the bucket counts, and make |
| 788 | // sure it count falls within a bucket <= 5 seconds (maximum duration of |
| 789 | // test due to context). |
| 790 | if metric.Name == "grpc.client.attempt.duration" || metric.Name == "grpc.client.call.duration" || metric.Name == "grpc.server.call.duration" { |
| 791 | val := gotMetrics[metric.Name] |
| 792 | if !metricdatatest.AssertEqual(t, metric, val, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars(), metricdatatest.IgnoreValue()) { |
| 793 | t.Errorf("Metrics data type not equal for metric: %v", metric.Name) |
| 794 | } |
| 795 | if err := checkDataPointWithinFiveSeconds(val); err != nil { |
| 796 | t.Errorf("Data point not within five seconds for metric %v: %v", metric.Name, err) |
| 797 | } |
| 798 | continue |
| 799 | } |
| 800 | |
| 801 | if !metricdatatest.AssertEqual(t, metric, val, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars()) { |
| 802 | t.Errorf("Metrics data type not equal for metric: %v", metric.Name) |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | // WaitForServerMetrics waits for eventual server metrics (not emitted |
| 808 | // synchronously with client side rpc returning). |