| 53 | ) |
| 54 | |
| 55 | func assertServiceMetricsPrefixes(t *testing.T, serviceType ServiceType, service *e2ecortex.CortexService) { |
| 56 | if service == nil { |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | metrics, err := service.Metrics() |
| 61 | require.NoError(t, err) |
| 62 | |
| 63 | // Build the list of blacklisted metrics prefixes for this specific service. |
| 64 | blacklist := getBlacklistedMetricsPrefixesByService(serviceType) |
| 65 | |
| 66 | // Ensure no metric name matches the blacklisted prefixes. |
| 67 | for _, metricLine := range strings.Split(metrics, "\n") { |
| 68 | metricLine = strings.TrimSpace(metricLine) |
| 69 | if metricLine == "" || strings.HasPrefix(metricLine, "#") { |
| 70 | continue |
| 71 | } |
| 72 | |
| 73 | for _, prefix := range blacklist { |
| 74 | // Skip the metric if it matches an ignored prefix. |
| 75 | if prefix[0] == '!' && strings.HasPrefix(metricLine, prefix[1:]) { |
| 76 | break |
| 77 | } |
| 78 | |
| 79 | assert.NotRegexp(t, "^"+prefix, metricLine, "service: %s endpoint: %s", service.Name(), service.HTTPEndpoint()) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func getBlacklistedMetricsPrefixesByService(serviceType ServiceType) []string { |
| 85 | blacklist := append([]string{}, blacklistedMetricsPrefixes...) |