Skip to content

Split cli package#1314

Merged
stuartnelson3 merged 6 commits intoprometheus:masterfrom
simonpasquier:split-cli-pkg
Apr 11, 2018
Merged

Split cli package#1314
stuartnelson3 merged 6 commits intoprometheus:masterfrom
simonpasquier:split-cli-pkg

Conversation

@simonpasquier
Copy link
Member

This PR modifies the cli commands to use the newly added API client.

cc @stuartnelson3

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 submitting!

One additional question: What was your motivation for moving all the cli files into their own cli/cmd directory? To me, cmd is a bit confusing as I always associate it with a top level cmd/<binary-name/main.go structure, where it contains something that will result in a binary for consumers.

It might make more sense to move those files back to cli/, and then move cli/client.go to its own client/ dir. I'm guessing that was the separation you wanted, between "cli stuff" and "the client that interacts with the api".

Thanks for all the work!

cli/client.go Outdated
type AlertAPI interface {
// List returns all the active alerts.
List(ctx context.Context) ([]*ExtendedAlert, error)
List(ctx context.Context, filter string, silenced bool, inhibited bool) ([]*ExtendedAlert, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

List(ctx context.Context, filter string, silenced, inhibited bool) ([]*ExtendedAlert, error)

cli/client.go Outdated
}

func (h *httpAlertAPI) List(ctx context.Context) ([]*ExtendedAlert, error) {
func (h *httpAlertAPI) List(ctx context.Context, filter string, silenced bool, inhibited bool) ([]*ExtendedAlert, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, you only need to declare bool the one time

}

func addSilence(silence *types.Silence) (string, error) {
client, err := api.NewClient(api.Config{Address: (*alertmanagerUrl).String()})
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 most of this function can disappear. It makes sense to me to create the client + silence client once, and then pass the silence client into each addSilenceWorker function. A bulk import could potentially have thousands of silences, which in its current form would create thousands of clients when only one is needed.

With this, the line silenceID, err := addSilence(s) in addSilenceWorker could just be silenceID, err := silenceAPI.Set(context.Background(), *silence)

@simonpasquier
Copy link
Member Author

It might make more sense to move those files back to cli/, and then move cli/client.go to its own client/ dir. I'm guessing that was the separation you wanted, between "cli stuff" and "the client that interacts with the api".

👍 I'll update accordingly. Thanks for the other tips.

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.

awesome, thanks!

@stuartnelson3 stuartnelson3 merged commit c92ed69 into prometheus:master Apr 11, 2018
@simonpasquier simonpasquier deleted the split-cli-pkg branch April 11, 2018 09:23
mxinden pushed a commit to mxinden/alertmanager that referenced this pull request May 5, 2018
* cli: move commands to cli/cmd

* cli: use StatusAPI interface for config command

* cli: use SilenceAPI interface for silence commands

* cli: use AlertAPI for alert command

* cli: move back commands to cli package

And move API client code to its own package.

* cli: remove unused structs
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.

2 participants