Skip to content

Conversation

pracucci
Copy link
Contributor

What this PR does:
We recently introduced an empty runtime.yaml in the local dev env setup development/tsdb-blocks-storage-s3/config/, but I've just realised the config fails to load because empty (no YAML node). Should an empty config be legit? If so, then this PR fixes it.

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Comment on lines 24 to 30
content, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}

decoder := yaml.NewDecoder(r)
decoder.SetStrict(true)
if err := decoder.Decode(&overrides); err != nil {
var overrides = &runtimeConfigValues{}
if err := yaml.UnmarshalStrict(content, overrides); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should revert back to original code, and extend the checks as follows:

  • If first returned error is EOF, we return nil. This covers empty document case.
  • We call decoder.Decode second time, and if it doesn't return EOF, then loadRuntimeConfig will return error.

Second check covers the case when there are multiple YAML documents on the input, eg.

---
# This is an empty YAML.
---
multi_kv_config:
  mirror_enabled: true

In this case, first two calls to Decode return nil (no error), so our current version of loadRuntimeConfig (or version suggested in this PR, which only decodes first document) would return no error, which is confusing.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point about multiple documents (that should be forbidden). I've changed it. What do you think?

…cuments

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

LGTM, nice. Remaining comments are just non-blocking nits.

pracucci and others added 2 commits January 21, 2021 14:17
Signed-off-by: Marco Pracucci <marco@pracucci.com>

Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>

Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
@pracucci pracucci merged commit 5682f66 into cortexproject:master Jan 21, 2021
@pracucci pracucci deleted the fix-load-empty-runtime-config branch January 21, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants