54
// recordings were namespace-scoped. Metrics with no recordings are treated as
55
// inconclusive and do not trigger misuse detection.
56
>
func (c *GlobalMetricCapture) checkForNamespaceCaptureMisuse() {
metric_capture.go
57
>
queriedMetrics := c.queriedMetricNames()
58
>
59
>
if len(queriedMetrics) == 0 {
60
return
61
}
62
63
>
if allQueriedMetricsAreNamespaceScoped(c.capture.Snapshot(), queriedMetrics) {
metric_capture.go
64
panic("GlobalMetricCapture was used, but all queried metrics were namespace-scoped; use NamespaceMetricCapture instead")
65
}
66
}
67
69
>
c.mu.Lock()
70
>
defer c.mu.Unlock()
71
>
72
>
queriedMetrics := make([]string, 0, len(c.queriedMetrics))
73
>
for name := range c.queriedMetrics {
74
>
queriedMetrics = append(queriedMetrics, name)
75
>
}
76
>
return queriedMetrics
77
}
78
79
>
func allQueriedMetricsAreNamespaceScoped(snap metricstest.CaptureSnapshot, queriedMetrics []string) bool {
metric_capture.go
80
>
for _, name := range queriedMetrics {
81
>
recordings := snap[name]
82
>
if len(recordings) == 0 {
83
return false
84
}
86
>
if _, ok := rec.Tags["namespace"]; !ok {
87
return false
88
}