fetchMetrics is a helper function to fetch metrics from a registry that match a prefix
(t *testing.T, registry *prometheus.Registry, prefix string)
| 7629 | |
| 7630 | // fetchMetrics is a helper function to fetch metrics from a registry that match a prefix |
| 7631 | func fetchMetrics(t *testing.T, registry *prometheus.Registry, prefix string) []string { |
| 7632 | metricFamilies, err := registry.Gather() |
| 7633 | require.NoError(t, err) |
| 7634 | |
| 7635 | var metrics []string |
| 7636 | for _, mf := range metricFamilies { |
| 7637 | if strings.HasPrefix(mf.GetName(), prefix) { |
| 7638 | for _, m := range mf.GetMetric() { |
| 7639 | var labels []string |
| 7640 | for _, label := range m.GetLabel() { |
| 7641 | labels = append(labels, fmt.Sprintf(`%s="%s"`, label.GetName(), label.GetValue())) |
| 7642 | } |
| 7643 | labelStr := strings.Join(labels, ",") |
| 7644 | |
| 7645 | var value string |
| 7646 | if m.Counter != nil { |
| 7647 | value = fmt.Sprintf("%v", m.Counter.GetValue()) |
| 7648 | } else if m.Gauge != nil { |
| 7649 | value = fmt.Sprintf("%v", m.Gauge.GetValue()) |
| 7650 | } |
| 7651 | |
| 7652 | metricLine := fmt.Sprintf("%s{%s} %s", mf.GetName(), labelStr, value) |
| 7653 | metrics = append(metrics, metricLine) |
| 7654 | } |
| 7655 | } |
| 7656 | } |
| 7657 | return metrics |
| 7658 | } |
| 7659 | |
| 7660 | func TestIngester_checkRegexMatcherLimits(t *testing.T) { |
| 7661 | const userID = "test-user" |
no test coverage detected