| 187 | } |
| 188 | |
| 189 | func verifyClientMetricsHistogram(t *testing.T, reg *prometheus.Registry, metricNameToVerify string, sampleCounts map[string]uint64) { |
| 190 | metrics, err := reg.Gather() |
| 191 | require.NoError(t, err) |
| 192 | |
| 193 | var metricToVerify *dto.MetricFamily |
| 194 | for _, metric := range metrics { |
| 195 | if metric.GetName() != metricNameToVerify { |
| 196 | continue |
| 197 | } |
| 198 | metricToVerify = metric |
| 199 | break |
| 200 | } |
| 201 | require.NotNilf(t, metricToVerify, "Metric %s not found in registry", metricNameToVerify) |
| 202 | require.Equal(t, dto.MetricType_HISTOGRAM, metricToVerify.GetType()) |
| 203 | |
| 204 | getMetricOperation := func(labels []*dto.LabelPair) (string, error) { |
| 205 | for _, l := range labels { |
| 206 | if l.GetName() == "operation" { |
| 207 | return l.GetValue(), nil |
| 208 | } |
| 209 | } |
| 210 | return "", errors.New("no operation") |
| 211 | } |
| 212 | |
| 213 | for _, metric := range metricToVerify.GetMetric() { |
| 214 | op, err := getMetricOperation(metric.Label) |
| 215 | require.NoErrorf(t, err, "No operation label found in metric %v", metric.String()) |
| 216 | assert.Equal(t, sampleCounts[op], metric.GetHistogram().GetSampleCount(), op) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | type stringCodec struct{} |
| 221 | |