MCPcopy Create free account
hub / github.com/cortexproject/cortex / fetchMetrics

Function fetchMetrics

pkg/ingester/ingester_test.go:7631–7658  ·  view source on GitHub ↗

fetchMetrics is a helper function to fetch metrics from a registry that match a prefix

(t *testing.T, registry *prometheus.Registry, prefix string)

Source from the content-addressed store, hash-verified

7629
7630// fetchMetrics is a helper function to fetch metrics from a registry that match a prefix
7631func 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
7660func TestIngester_checkRegexMatcherLimits(t *testing.T) {
7661 const userID = "test-user"

Callers 1

Calls 4

JoinMethod · 0.80
GetNameMethod · 0.45
GetMetricMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected