Skip to content
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

Merged
merged 2 commits into from
Jun 8, 2015
Merged

config: simplify default config handling. #773

merged 2 commits into from
Jun 8, 2015

Conversation

fabxc
Copy link
Contributor

@fabxc fabxc commented Jun 4, 2015

As suggested by @neelance, this makes default configuration handling more transparent.
Thanks again @neelance, I like it.

@neelance
Copy link

neelance commented Jun 4, 2015

Glad I could help. :-)

if err != nil {
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultGlobalConfig
type plain GlobalConfig
Copy link
Member

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. ;)

Copy link
Contributor Author

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.

@fabxc fabxc force-pushed the fabxc/simple-cfg branch from 69408d3 to ba22839 Compare June 6, 2015 07:02
@fabxc fabxc force-pushed the fabxc/simple-cfg branch from ba22839 to 0af1cff Compare June 6, 2015 07:04
}

// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo te -> the

@beorn7
Copy link
Member

beorn7 commented Jun 7, 2015

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...

@fabxc
Copy link
Contributor Author

fabxc commented Jun 7, 2015

We copy the values of the default structs into the configuration structs. Then we unmarshal into the latter.
So inside of the package the default structs are only written on definition.

We can take a closer look tomorrow to be sure.

Actually, there might be a problem with the pointer to GlobalConfig :)

@fabxc
Copy link
Contributor Author

fabxc commented Jun 7, 2015

So yep, good catch. It was indeed a problem for the GlobalConfig pointer in DefaultConfig. Test added and fixed.

@fabxc fabxc force-pushed the fabxc/simple-cfg branch from eac85c4 to 6308957 Compare June 7, 2015 15:43
@@ -0,0 +1,2 @@
global:
scrape_timeout: 1h
Copy link
Member

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.

@fabxc fabxc force-pushed the fabxc/simple-cfg branch from 6308957 to 49b102a Compare June 8, 2015 11:25

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo "permanentely".

@beorn7
Copy link
Member

beorn7 commented Jun 8, 2015

Otherwise 👍

@fabxc fabxc force-pushed the fabxc/simple-cfg branch from 49b102a to f6c33a2 Compare June 8, 2015 14:02
fabxc added a commit that referenced this pull request Jun 8, 2015
config: simplify default config handling.
@fabxc fabxc merged commit b5fe2e9 into master Jun 8, 2015
@fabxc fabxc deleted the fabxc/simple-cfg branch June 8, 2015 14:22
julienduchesne pushed a commit to julienduchesne/prometheus that referenced this pull request Dec 13, 2024
TSDB: Always drop 'quiet zeros' if out-of-order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants