mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
config: prevent overwrite of DefaultGlobalConfig
This commit is contained in:
parent
0af1cff8af
commit
f6c33a2347
|
@ -46,7 +46,7 @@ func LoadFromFile(filename string) (*Config, error) {
|
||||||
var (
|
var (
|
||||||
// The default top-level configuration.
|
// The default top-level configuration.
|
||||||
DefaultConfig = Config{
|
DefaultConfig = Config{
|
||||||
GlobalConfig: &DefaultGlobalConfig,
|
GlobalConfig: DefaultGlobalConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default global configuration.
|
// The default global configuration.
|
||||||
|
@ -56,7 +56,7 @@ var (
|
||||||
EvaluationInterval: Duration(1 * time.Minute),
|
EvaluationInterval: Duration(1 * time.Minute),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Te default scrape configuration.
|
// The default scrape configuration.
|
||||||
DefaultScrapeConfig = ScrapeConfig{
|
DefaultScrapeConfig = ScrapeConfig{
|
||||||
// ScrapeTimeout and ScrapeInterval default to the
|
// ScrapeTimeout and ScrapeInterval default to the
|
||||||
// configured globals.
|
// configured globals.
|
||||||
|
@ -89,7 +89,7 @@ var (
|
||||||
|
|
||||||
// Config is the top-level configuration for Prometheus's config files.
|
// Config is the top-level configuration for Prometheus's config files.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
GlobalConfig *GlobalConfig `yaml:"global"`
|
GlobalConfig GlobalConfig `yaml:"global"`
|
||||||
RuleFiles []string `yaml:"rule_files,omitempty"`
|
RuleFiles []string `yaml:"rule_files,omitempty"`
|
||||||
ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var expectedConf = &Config{
|
var expectedConf = &Config{
|
||||||
GlobalConfig: &GlobalConfig{
|
GlobalConfig: GlobalConfig{
|
||||||
ScrapeInterval: Duration(15 * time.Second),
|
ScrapeInterval: Duration(15 * time.Second),
|
||||||
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
||||||
EvaluationInterval: Duration(30 * time.Second),
|
EvaluationInterval: Duration(30 * time.Second),
|
||||||
|
@ -118,6 +118,12 @@ var expectedConf = &Config{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadConfig(t *testing.T) {
|
func TestLoadConfig(t *testing.T) {
|
||||||
|
// Parse a valid file that sets a global scrape timeout. This tests whether parsing
|
||||||
|
// an overwritten default field in the global config permanently changes the default.
|
||||||
|
if _, err := LoadFromFile("testdata/global_timeout.good.yml"); err != nil {
|
||||||
|
t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err)
|
||||||
|
}
|
||||||
|
|
||||||
c, err := LoadFromFile("testdata/conf.good.yml")
|
c, err := LoadFromFile("testdata/conf.good.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err)
|
t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err)
|
||||||
|
|
2
config/testdata/global_timeout.good.yml
vendored
Normal file
2
config/testdata/global_timeout.good.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
global:
|
||||||
|
scrape_timeout: 1h
|
Loading…
Reference in a new issue