-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: simplify default config handling. #773
Conversation
Glad I could help. :-) |
if err != nil { | ||
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
*c = DefaultGlobalConfig | ||
type plain GlobalConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment with a hint why we do this. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added on first occurrence.
} | ||
|
||
// The default global configuration. | ||
DefaultGlobalConfig = DefaultedGlobalConfig{ | ||
DefaultGlobalConfig = GlobalConfig{ | ||
ScrapeInterval: Duration(1 * time.Minute), | ||
ScrapeTimeout: Duration(10 * time.Second), | ||
EvaluationInterval: Duration(1 * time.Minute), | ||
} | ||
|
||
// Te default scrape configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo te -> the
Dumb question: I don't fully understand how the yaml marshaling works under the hood, but it looks to me that the default config structs are actually partially overwritten, thus modifying the defaults for future config loads. The test just loads once and cannot prove that this is not happening. Perhaps discuss in person tomorrow... |
We copy the values of the default structs into the configuration structs. Then we unmarshal into the latter. We can take a closer look tomorrow to be sure. Actually, there might be a problem with the pointer to |
So yep, good catch. It was indeed a problem for the |
@@ -0,0 +1,2 @@ | |||
global: | |||
scrape_timeout: 1h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No newline at end of file.
|
||
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 permanentely changes the default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "permanentely".
Otherwise 👍 |
config: simplify default config handling.
TSDB: Always drop 'quiet zeros' if out-of-order
As suggested by @neelance, this makes default configuration handling more transparent.
Thanks again @neelance, I like it.