From e26e4b6e89e55cb30c76902e091b519e54b3feaa Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 12 Feb 2016 12:51:55 +0100 Subject: [PATCH] Restrict scrape timeout to interval length --- config/config.go | 3 +++ config/config_test.go | 3 +++ config/testdata/scrape_interval.bad.yml | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 config/testdata/scrape_interval.bad.yml diff --git a/config/config.go b/config/config.go index 19bec5423..73459b20d 100644 --- a/config/config.go +++ b/config/config.go @@ -266,6 +266,9 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { if scfg.ScrapeTimeout == 0 { scfg.ScrapeTimeout = c.GlobalConfig.ScrapeTimeout } + if scfg.ScrapeTimeout > scfg.ScrapeInterval { + return fmt.Errorf("scrape timeout greater than scrape interval for scrape config with job name %q", scfg.JobName) + } if _, ok := jobNames[scfg.JobName]; ok { return fmt.Errorf("found multiple scrape configs with job name %q", scfg.JobName) diff --git a/config/config_test.go b/config/config_test.go index 477bee706..c0cc9a3ba 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -335,6 +335,9 @@ var expectedErrors = []struct { }, { filename: "jobname_dup.bad.yml", errMsg: `found multiple scrape configs with job name "prometheus"`, + }, { + filename: "scrape_interval.bad.yml", + errMsg: `scrape timeout greater than scrape interval`, }, { filename: "labelname.bad.yml", errMsg: `"not$allowed" is not a valid label name`, diff --git a/config/testdata/scrape_interval.bad.yml b/config/testdata/scrape_interval.bad.yml new file mode 100644 index 000000000..b334c7775 --- /dev/null +++ b/config/testdata/scrape_interval.bad.yml @@ -0,0 +1,4 @@ +scrape_configs: +- job_name: prometheus + scrape_interval: 5s + scrape_timeout: 6s