Switch amtool to kingpin#976
Conversation
Thanks for doing this! |
|
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. |
|
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). |
|
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. |
|
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. |
c30617b to
6f7279c
Compare
|
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. |
|
cool, thanks for the update! |
|
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? |
056c8d9 to
e8190b9
Compare
|
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:
Let me know what you think! |
|
Taking a look, thanks! And yeah, the acceptance tests are flakey :/ |
stuartnelson3
left a comment
There was a problem hiding this comment.
mostly superficial changes, but otherwise looks good. will run this locally to see how it works.
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/alecthomas/kingpin" |
There was a problem hiding this comment.
We should use gopkg.in/alecthomas/kingpin.v2, like in prometheus (and as recommended in the repo)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
/s/ommitted/omitted/
| "path" | ||
| "time" | ||
|
|
||
| "github.com/alecthomas/kingpin" |
There was a problem hiding this comment.
same import issue as above
| "io" | ||
| "time" | ||
|
|
||
| "github.com/alecthomas/kingpin" |
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 |
cli/root.go
Outdated
| Vars: map[string]interface{}{"LongHelp": longHelpText}, | ||
| }).Bool() | ||
|
|
||
| configResolver := newConfigResolver() |
There was a problem hiding this comment.
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.
| "path" | ||
| "time" | ||
|
|
||
| "github.com/alecthomas/kingpin" |
| basePath := "/api/v1/silence" | ||
| for _, id := range *expireIds { | ||
| u := GetAlertmanagerURL(path.Join(basePath, id)) | ||
| req, err := http.NewRequest("DELETE", u.String(), nil) |
There was a problem hiding this comment.
again, not your fault, but could you do the if err != nil dance here?
|
@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. |
|
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 |
|
Oh, uh, that is just a silly mistake on my part... I don't know how I miswrote that. Pushing in a sec! |
|
No worries :) |
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.
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.
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:
--help-man) use it?date.format? It is only exposed through the config file from what I understand of the code, and it is not documented.comment-requiredis 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