Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/instance/configstore/unique.go
5340 views
1
package configstore
2
3
import (
4
"github.com/grafana/agent/pkg/metrics/instance"
5
)
6
7
// checkUnique validates that cfg is unique from all, ensuring that no two
8
// configs share a job_name.
9
func checkUnique(all <-chan instance.Config, cfg *instance.Config) error {
10
defer func() {
11
// Drain the channel, which is necessary if we're returning an error.
12
for range all {
13
}
14
}()
15
16
newJobNames := make(map[string]struct{}, len(cfg.ScrapeConfigs))
17
for _, sc := range cfg.ScrapeConfigs {
18
newJobNames[sc.JobName] = struct{}{}
19
}
20
21
for otherConfig := range all {
22
// If the other config is the one we're validating, skip it.
23
if otherConfig.Name == cfg.Name {
24
continue
25
}
26
27
for _, otherScrape := range otherConfig.ScrapeConfigs {
28
if _, exist := newJobNames[otherScrape.JobName]; exist {
29
return NotUniqueError{ScrapeJob: otherScrape.JobName}
30
}
31
}
32
}
33
34
return nil
35
}
36
37