Path: blob/main/pkg/metrics/instance/configstore/unique.go
5340 views
package configstore12import (3"github.com/grafana/agent/pkg/metrics/instance"4)56// checkUnique validates that cfg is unique from all, ensuring that no two7// configs share a job_name.8func checkUnique(all <-chan instance.Config, cfg *instance.Config) error {9defer func() {10// Drain the channel, which is necessary if we're returning an error.11for range all {12}13}()1415newJobNames := make(map[string]struct{}, len(cfg.ScrapeConfigs))16for _, sc := range cfg.ScrapeConfigs {17newJobNames[sc.JobName] = struct{}{}18}1920for otherConfig := range all {21// If the other config is the one we're validating, skip it.22if otherConfig.Name == cfg.Name {23continue24}2526for _, otherScrape := range otherConfig.ScrapeConfigs {27if _, exist := newJobNames[otherScrape.JobName]; exist {28return NotUniqueError{ScrapeJob: otherScrape.JobName}29}30}31}3233return nil34}353637