|
15 | 15 | package prometheusreceiver |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "errors" |
18 | 19 | "fmt" |
19 | 20 | "time" |
20 | 21 |
|
@@ -49,18 +50,20 @@ type Config struct { |
49 | 50 | var _ config.Receiver = (*Config)(nil) |
50 | 51 | var _ config.CustomUnmarshable = (*Config)(nil) |
51 | 52 |
|
52 | | -// Validate checks the receiver configuration is valid |
| 53 | +// Validate checks the receiver configuration is valid. |
53 | 54 | func (cfg *Config) Validate() error { |
54 | | - if cfg.PrometheusConfig != nil { |
55 | | - if len(cfg.PrometheusConfig.ScrapeConfigs) == 0 { |
56 | | - return errNilScrapeConfig |
57 | | - } |
58 | | - for _, sc := range cfg.PrometheusConfig.ScrapeConfigs { |
59 | | - for _, rc := range sc.MetricRelabelConfigs { |
60 | | - if rc.TargetLabel == "__name__" { |
61 | | - // TODO(#2297): Remove validation after renaming is fixed |
62 | | - return fmt.Errorf("error validating scrapeconfig for job %v: %w", sc.JobName, errRenamingDisallowed) |
63 | | - } |
| 55 | + if cfg.PrometheusConfig == nil { |
| 56 | + return nil // noop receiver |
| 57 | + } |
| 58 | + if len(cfg.PrometheusConfig.ScrapeConfigs) == 0 { |
| 59 | + return errors.New("no Prometheus scrape_configs") |
| 60 | + } |
| 61 | + |
| 62 | + for _, sc := range cfg.PrometheusConfig.ScrapeConfigs { |
| 63 | + for _, rc := range sc.MetricRelabelConfigs { |
| 64 | + if rc.TargetLabel == "__name__" { |
| 65 | + // TODO(#2297): Remove validation after renaming is fixed |
| 66 | + return fmt.Errorf("error validating scrapeconfig for job %v: %w", sc.JobName, errRenamingDisallowed) |
64 | 67 | } |
65 | 68 | } |
66 | 69 | } |
@@ -94,5 +97,6 @@ func (cfg *Config) Unmarshal(componentParser *configparser.Parser) error { |
94 | 97 | if err != nil { |
95 | 98 | return fmt.Errorf("prometheus receiver failed to unmarshal yaml to prometheus config: %s", err) |
96 | 99 | } |
| 100 | + |
97 | 101 | return nil |
98 | 102 | } |
0 commit comments