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

Switch amtool to kingpin #976

Merged
merged 8 commits into from
Dec 22, 2017
Merged

Conversation

carlpett
Copy link
Member

@carlpett carlpett commented Sep 4, 2017

Related to #974, this PR switches amtool to use kingpin.

This PR is a bit more involved, since cobra/viper does not translate quite as easily as the core flag package. There are some remaining points before this can be merged that I would like feedback on:

  1. There were quite nice long format help texts written previously. There is no "long help" field in kingpin, but maybe it would be a good idea to make the man page template (--help-man) use it?
  2. Is the config file an important feature? Kingpin does not have any file loading capabilities, so we'll need to built it ourselves in that case, and ensure it falls back in the correct order. If so, maybe the number of file formats could be reduced to avoid all too much complexity?
  3. What is the purpose of date.format? It is only exposed through the config file from what I understand of the code, and it is not documented.
  4. comment-required is not implemented since it is only supported through config-file at the moment.

Let me know if there are any other changes you think are necessary! @stuartnelson3 @fabx

@stuartnelson3
Copy link
Contributor

  1. 👍
  2. It would be good to maintain the config file functionality, since there is a lot of additional metadata that regularly needs to be added since the cli tool does affect alertmanager. I would say stick with .yml and support the two location that are currently supported.
  3. Not sure .. @Kellel ? I've never used it, and I think we're limited by the date format that alertmanager parses.
  4. I think it would be best to require a comment, since we require one through the UI.

Thanks for doing this!

@Kellel
Copy link
Contributor

Kellel commented Sep 5, 2017

The date.format option is only used for output formatting. I could see people using it, but it just a preference option. I mean, I even forgot about it and I am the one who wrote it.

@Kellel
Copy link
Contributor

Kellel commented Sep 5, 2017

I am happy with the comment being required, but if so we should enforce this at the api level as well (Out of scope for this PR).

@Kellel
Copy link
Contributor

Kellel commented Sep 5, 2017

Also as far as the config file goes, viper (the config file library) can be used without cobra (the flag parsing library). So you can feasibly still use viper for all the config file processing and kingpin for the flags. I don't know if that will be easier, but it might be worth exploring.

@carlpett
Copy link
Member Author

carlpett commented Sep 5, 2017

Thanks for the input!

@stuartnelson3 Sounds good. I'll implement some config file loading.

@Kellel Regarding using viper, I looked into that a bit, but from what I can see in the related issue, it doesn't look trivial at least.

@carlpett
Copy link
Member Author

So, I found this PR lying around on my laptop, thought I had finished it long ago... Sorry about that. I finished up the small work that remained (which mainly consisted of getting a PR into kingpin, done since many months now), and now I'm working through the many merge conflicts... Looks like it could take a while longer than I have available today, but I hope to finish it tomorrow.

@stuartnelson3
Copy link
Contributor

cool, thanks for the update!

@carlpett
Copy link
Member Author

So, merging old branches is a pain (no news there). I'm testing it a bit manually now to make sure parsing etc does what it should, but I'm also seeing the acceptance tests fail. I don't understand why, though, as far as I see, amtool is not used for this?

@carlpett
Copy link
Member Author

Ok, acceptance tests are suddenly green again after some last fixes of other things. Are they known to be flakey, or could I have broken something?

Anyway, I think I've addressed all the points I had in the original post:

  1. Long-form help-texts are given with --help-long.
  2. The config file support is implemented (although only in the default locations, and only with yaml format)
  3. date.format has been given a flag, as well as works from config file
  4. require-comment is supported in the config file, and has a (hidden) flag as well

Let me know what you think!

@carlpett carlpett changed the title WIP: Switch amtool to kingpin Switch amtool to kingpin Dec 19, 2017
@stuartnelson3
Copy link
Contributor

Taking a look, thanks!

And yeah, the acceptance tests are flakey :/

Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

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

mostly superficial changes, but otherwise looks good. will run this locally to see how it works.

"strings"
"time"

"github.com/alecthomas/kingpin"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use gopkg.in/alecthomas/kingpin.v2, like in prometheus (and as recommended in the repo)

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, no :) We need to use the v3-branch, since the pull request I made to kingpin to add support for config files is only present on that branch.

cli/alert.go Outdated
`,
Run: CommandWrapper(queryAlerts),
}
If alertname is ommited and the first argument does not contain a '=' or a
Copy link
Contributor

Choose a reason for hiding this comment

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

/s/ommitted/omitted/

"time"

"github.com/alecthomas/kingpin"
Copy link
Contributor

Choose a reason for hiding this comment

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

same import issue as above

@@ -4,14 +4,22 @@ import (
"io"
"time"

"github.com/alecthomas/kingpin"
Copy link
Contributor

Choose a reason for hiding this comment

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

import

cli/root.go Outdated
from one of two default config locations. Valid config file formats are JSON, TOML, YAML, HCL and Java Properties, use
whatever makes sense for your project.
// This function maps things which have previously had different names in the
// config file to their new names, so old configrations keep working
Copy link
Contributor

Choose a reason for hiding this comment

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

configurations

cli/root.go Outdated
Vars: map[string]interface{}{"LongHelp": longHelpText},
}).Bool()

configResolver := newConfigResolver()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to have newConfigResolver return an error, and instead of panicking on a file read error or a yaml unmarshal error, provide a shorter and clearer message. panic()'s stack trace probably won't aid a user much, and generate a github issue when they just need to fix their yaml.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

"time"

"github.com/alecthomas/kingpin"
Copy link
Contributor

Choose a reason for hiding this comment

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

import

u.Path = path.Join(basePath, arg)
basePath := "/api/v1/silence"
for _, id := range *expireIds {
u := GetAlertmanagerURL(path.Join(basePath, id))
req, err := http.NewRequest("DELETE", u.String(), nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

again, not your fault, but could you do the if err != nil dance here?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@carlpett
Copy link
Member Author

@stuartnelson3 Pushed fixes for all the comments except the import path, because of the reason I replied with there. I think there might be a bit of time until v3 is released, given the number of remaining items on the roadmap, but I haven't had any stability issues in our usage of "v3-unstable" in our work projects.

@stuartnelson3
Copy link
Contributor

Looks great, works great. I have one final, tiny request (or question, I guess), and then this is merged. You mentioned that extended help is available via --help-long, and that's the same flag that's mentioned in the kingpin documentation. It's implemented here as --long-help. I'm fine with either since it shows up as a flag when a user does -h, but just wanted to see if this was done on purpose or not.

@carlpett
Copy link
Member Author

Oh, uh, that is just a silly mistake on my part... I don't know how I miswrote that. Pushing in a sec!

@stuartnelson3
Copy link
Contributor

No worries :)

Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@stuartnelson3 stuartnelson3 merged commit 6088483 into prometheus:master Dec 22, 2017
sinkingpoint added a commit to sinkingpoint/alertmanager that referenced this pull request Jan 10, 2018
Possibly another regression introduced by prometheus#976 . We use the wrong
variable to update comments in the `amtool silence update` command
which causes us to fail silently. This fixes that.
stuartnelson3 pushed a commit that referenced this pull request Jan 10, 2018
Possibly another regression introduced by #976 . We use the wrong
variable to update comments in the `amtool silence update` command
which causes us to fail silently. This fixes that.
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