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

Fix -ruler.alertmanager-url flag #2989

Merged
merged 5 commits into from
Aug 7, 2020
Merged

Conversation

gotjosh
Copy link
Contributor

@gotjosh gotjosh commented Aug 6, 2020

What this PR does:

  • Fixes the flag -ruler.alertmanager-url by reverting it back to using a string (which is meant to be comma-separated) as opposed to a list of strings. As it was this broke compatibility with a file-based configuration where it required a list of strings instead of a single string.
  • Unifies the usage of StringsSlice and Strings flag extensions.
  • Adds an integration test for testing Alertmanager discovery.

Quoting the commits:

@gotjosh
fix: `-ruler.alertmanager-url` should be a string …
6b5a862
This was never space-separated, you needed to register the flag multiple times for it to append to the list of strings.

On top of that, the previous change implied that when using a config file you would need to provide a list instead of a string thus breaking existing configuration.
Unify the use of StringSlice flags …
1b81fa6
We had two very similar flag extensions: `Strings` and `StringSlice`.

With this, we unify its use by removing `Strings` in favour of `StringSlice` but keeping the string representation favoured in `Strings`.

The difference here is that by using `Sprintf` we would get the brackets representation as part of the string.

Checklist

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

gotjosh added 4 commits August 6, 2020 15:36
This was never space separated, you needed to register the flag multiple times for it to append to the list of strings.

On top of that, the previous change implied that when using a config file you would need to provide a a list instead of a string thus breaking exisiting configuration.

Signed-off-by: gotjosh <[email protected]>
We had two very similar flag extensions: `Strings` and `StringSlice`.

With this, we unify its use by removing `Strings` in favour of `StringSlice` but keeping the string representation favoured in `Strings`.

The difference here is that by using `Sprintf` we would get the brackets representation as part of the string.

Signed-off-by: gotjosh <[email protected]>
This is no longer only about the API.

Signed-off-by: gotjosh <[email protected]>

// StringSlice is a slice of strings that implements flag.Value
type StringSlice []string

// String implements flag.Value
func (v StringSlice) String() string {
return strings.Join(v, " ")
return fmt.Sprintf("%s", []string(v))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unification of the flag extensions is basically that I kept the name StringSlice but "borrowed" the String casting function.

I like this because for empty values it renders [] instead of "" which seems to be more accurate.

@gotjosh gotjosh changed the title Fix am url Fix Alertmanager URL flag Aug 6, 2020
@gotjosh gotjosh changed the title Fix Alertmanager URL flag Fix -ruler.alertmanager-url flag Aug 6, 2020
Signed-off-by: gotjosh <[email protected]>
@gotjosh
Copy link
Contributor Author

gotjosh commented Aug 6, 2020

I'm not sure what to include in the changelog - opinions are welcome.

@gouthamve
Copy link
Contributor

I'm not sure what to include in the changelog

Nothing. I don't see any user-impact since the last release that is introduced by this PR.

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Very good job! Clean fix and tested 👏

@pracucci pracucci merged commit 15d2d14 into cortexproject:master Aug 7, 2020
pracucci pushed a commit to pracucci/cortex that referenced this pull request Aug 7, 2020
* fix: `-ruler.alertmanager-url` should be a string

This was never space separated, you needed to register the flag multiple times for it to append to the list of strings.

On top of that, the previous change implied that when using a config file you would need to provide a a list instead of a string thus breaking exisiting configuration.

Signed-off-by: gotjosh <[email protected]>

* Unify the use of StringSlice flags

We had two very similar flag extensions: `Strings` and `StringSlice`.

With this, we unify its use by removing `Strings` in favour of `StringSlice` but keeping the string representation favoured in `Strings`.

The difference here is that by using `Sprintf` we would get the brackets representation as part of the string.

Signed-off-by: gotjosh <[email protected]>

* Rename `api_ruler_test` to `ruler_test`

This is no longer only about the API.

Signed-off-by: gotjosh <[email protected]>

* Create an integration test for Alertmanager discovery

Signed-off-by: gotjosh <[email protected]>

* Fix existing test

Signed-off-by: gotjosh <[email protected]>
pracucci added a commit that referenced this pull request Aug 10, 2020
* fix: `-ruler.alertmanager-url` should be a string

This was never space separated, you needed to register the flag multiple times for it to append to the list of strings.

On top of that, the previous change implied that when using a config file you would need to provide a a list instead of a string thus breaking exisiting configuration.

Signed-off-by: gotjosh <[email protected]>

* Unify the use of StringSlice flags

We had two very similar flag extensions: `Strings` and `StringSlice`.

With this, we unify its use by removing `Strings` in favour of `StringSlice` but keeping the string representation favoured in `Strings`.

The difference here is that by using `Sprintf` we would get the brackets representation as part of the string.

Signed-off-by: gotjosh <[email protected]>

* Rename `api_ruler_test` to `ruler_test`

This is no longer only about the API.

Signed-off-by: gotjosh <[email protected]>

* Create an integration test for Alertmanager discovery

Signed-off-by: gotjosh <[email protected]>

* Fix existing test

Signed-off-by: gotjosh <[email protected]>

Co-authored-by: gotjosh <[email protected]>
@pracucci pracucci mentioned this pull request Aug 10, 2020
3 tasks
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.

3 participants