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

Add support for alerts, notifiers and add additional ingest-token support. #12

Merged
merged 4 commits into from
Feb 19, 2020

Conversation

SaaldjorMike
Copy link
Member

@SaaldjorMike SaaldjorMike commented Feb 11, 2020

Changes:

  • API: Return tag fields when creating a parser.
  • API: Fix types for repo retention settings.
  • CLI: Fix repo list ordering.
  • CLI: Fix repo retention size output.
  • Tidy up based on different linters. Some day we should enable these things on CI :-)
    • Receiver reference are typically named based on the type.
    • Remove unused functions and structs.
    • Acronyms are typically upper case (updated most of them).
    • Errors being returned should be checked, though we may have places we don't care as much about it.
  • Adds these to the api package:
func (c *Client) Alerts() *Alerts
func (c *Client) Notifiers() *Notifiers

func (i *IngestTokens) Get(repoName, tokenName string) (*IngestToken, error)

func (a *Alerts) Add(viewName string, alert *Alert, updateExisting bool) (*Alert, error)
func (a *Alerts) Delete(viewName, alertName string) error
func (a *Alerts) Get(viewName, alertName string) (*Alert, error)
func (a *Alerts) List(viewName string) ([]Alert, error)
func (a *Alerts) Update(viewName string, alert *Alert) (*Alert, error)

func (n *Notifiers) Add(viewName string, notifier *Notifier, force bool) (*Notifier, error)
func (n *Notifiers) Delete(viewName, notifierName string) error
func (n *Notifiers) Get(viewName, notifierName string) (*Notifier, error)
func (n *Notifiers) GetByID(viewName, notifierID string) (*Notifier, error)
func (n *Notifiers) List(viewName string) ([]Notifier, error)
func (n *Notifiers) Update(viewName string, notifier *Notifier) (*Notifier, error)
  • Adds these new commands to the CLI:
humioctl ingest-tokens show [flags] <repo> <token-name>

humioctl alerts list [flags] <view>
humioctl alerts export [flags] <view> <alert>
humioctl alerts remove [flags] <view> <name>
humioctl alerts install [flags] <view>

humioctl notifiers remove [flags] <view> <name>
humioctl notifiers export [flags] <view> <notifier>
humioctl notifiers show [flags] <view> <name>
humioctl notifiers list [flags] <view>
humioctl notifiers install [flags] <view>

I'm still a bit unsure what to do about a few things, and would love to get some input on these things:

  1. The naming could probably be streamlined a bit, such as:
    1. Parameters to methods in api package: view vs viewName vs repo vs repoName vs repositoryName vs searchDomain. For now I've used viewName for alerts and notifiers, even though it may be a tad confusing that it can also be used on a repository.
    2. Notifier vs alert notifier. Going with the first option.
    3. Actions/methods: delete vs remove.
  2. Multiple places can only be done using our REST API. Do we want to move that to GraphQL, and is that a blocker before merging this? Thinking alerts and notifiers for this PR, but I know saved queries is also missing from the GraphQL API right now (see this WIP that implements functionality to set up saved queries and dashboards).

…port.

API: Return tag fields when creating a parser.
API: Fix types for repo retention settings.
CLI: Fix repo list ordering.
CLI: Fix repo retention size output.

Tidy up based on different linters. Some day we should enable these things on CI :-)
- Receiver reference are typically named based on the type.
- Remove unused functions and structs.
- Acronyms are typically upper case.
- All returned errors should be checked, though we may have places we don't care as much about it.
@SaaldjorMike SaaldjorMike force-pushed the mike/add_alerts_notifiers_etc branch from 6790786 to 6962c3b Compare February 11, 2020 15:22
Copy link
Contributor

@jswoods jswoods left a comment

Choose a reason for hiding this comment

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

Really good stuff!

api/alerts.go Outdated
return a.Update(viewName, alert)
}

url := fmt.Sprintf("api/v1/repositories/%s/alerts/", viewName)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is some duplication between this Add() and the Update(). Perhaps there should be a private method that handles the code from this line down which is then called by these functions.

return &resNotifier, nil
}

func (n *Notifiers) Add(viewName string, notifier *Notifier, force bool) (*Notifier, 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 the above with the Add() and Update() methods (duplication). As well as the duplication around the unmarshalling in the other public methods 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.

After pulling out the marshal/unmarshal code, I'm not sure it would help that much to move this out as well. I'm thinking of just leaving this as-is unless you think I should still do it.

cmd.Println(fmt.Errorf("Failed to serialize the alert: %s", yamlErr))
os.Exit(1)
}
outFilePath := outputName + ".yaml"
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 this should be outputFilename rather than outputName + '.yaml'. It seems a little awkward to append the file suffix like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This actually just comes from how the current export function is done for parsers. See the code.
Just to make sure I understood you: you propose renaming outFilePath to outputFilename?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I suppose we should keep it the same to be consistent.

cmd.Println(fmt.Errorf("Failed to serialize the notifier: %s", yamlErr))
os.Exit(1)
}
outFilePath := outputName + ".yaml"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@SaaldjorMike SaaldjorMike requested a review from mwl February 13, 2020 09:25
@SaaldjorMike
Copy link
Member Author

Merging this in now. Should there be any additional changes, we can fix those before cutting the next release.

@SaaldjorMike SaaldjorMike merged commit 450e51a into master Feb 19, 2020
@SaaldjorMike SaaldjorMike deleted the mike/add_alerts_notifiers_etc branch February 19, 2020 10:29
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