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

Alerta support for timeout, tags and service template #1545

Merged
merged 1 commit into from
Sep 8, 2017

Conversation

m4ce
Copy link
Contributor

@m4ce m4ce commented Aug 31, 2017

Add template support to service field as requested in #1543
Add timeout support as requested in #1264
Add tags support as requested in #1546

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

@m4ce m4ce force-pushed the feature/alerta_service_template branch 2 times, most recently from 14a959a to 7416243 Compare August 31, 2017 17:06
@m4ce m4ce changed the title Alerta service template support Alerta support for timeout and service template Sep 1, 2017
@m4ce m4ce changed the title Alerta support for timeout and service template Alerta support for timeout, tags and service template Sep 1, 2017
@m4ce m4ce force-pushed the feature/alerta_service_template branch 10 times, most recently from 80099ef to cd7f1c4 Compare September 1, 2017 21:49
@m4ce
Copy link
Contributor Author

m4ce commented Sep 1, 2017

not exactly sure why it's failing over one test :/

Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

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

Thanks! These changes look good. I have made a few small comments below, mostly relating to using toml.Duartion vs time.Duration.

@@ -22,6 +24,7 @@ const (
defaultResource = "{{ .Name }}"
defaultEvent = "{{ .ID }}"
defaultGroup = "{{ .Group }}"
defaultTimeout = toml.Duration(86400 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

This reads a little better as time.Duration(24*time.Hour). Also once the duration has been parsed from the config its best to use time.Duration so that normal time operations work.

@@ -69,6 +73,7 @@ func (s *Service) TestOptions() interface{} {
Message: "test alerta message",
Origin: c.Origin,
Service: []string{"testServiceA", "testServiceB"},
Timeout: toml.Duration(86400 * time.Second),
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the constant defined above here.

@@ -185,6 +192,10 @@ func (s *Service) preparePost(token, tokenPrefix, resource, event, environment,
origin = c.Origin
}

if timeout == toml.Duration(0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified as if timeout == 0 { Go will infer the type of the constant numeric literal.

Message string `json:"message"`
Origin string `json:"origin"`
Service []string `json:"service"`
Timeout toml.Duration `json:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Use time.Duration

@@ -125,12 +132,12 @@ func (s *Service) Update(newConfig []interface{}) error {
return nil
}

func (s *Service) Alert(token, tokenPrefix, resource, event, environment, severity, group, value, message, origin string, service []string, data models.Result) error {
func (s *Service) Alert(token, tokenPrefix, resource, event, environment, severity, group, value, message, origin string, service []string, timeout toml.Duration, tags map[string]string, data models.Result) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

And here as well you can use time.Duration

@@ -158,7 +165,7 @@ func (s *Service) Alert(token, tokenPrefix, resource, event, environment, severi
return nil
}

func (s *Service) preparePost(token, tokenPrefix, resource, event, environment, severity, group, value, message, origin string, service []string, data models.Result) (*http.Request, error) {
func (s *Service) preparePost(token, tokenPrefix, resource, event, environment, severity, group, value, message, origin string, service []string, timeout toml.Duration, tags map[string]string, data models.Result) (*http.Request, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And again here time.Duration.

@@ -204,6 +215,13 @@ func (s *Service) preparePost(token, tokenPrefix, resource, event, environment,
if len(service) > 0 {
postData["service"] = service
}
postData["timeout"] = int64(timeout / toml.Duration(time.Second))
Copy link
Contributor

Choose a reason for hiding this comment

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

Once the types are changed to time.Duration this can be simplified as int64(timeout/time.Second)

@@ -262,6 +280,9 @@ type HandlerConfig struct {

// List of effected Services
Service []string `mapstructure:"service"`

// Timeout
Timeout toml.Duration `mapstructure:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

And again here time.Duration

@@ -22,6 +23,8 @@ type Config struct {
Environment string `toml:"environment" override:"environment"`
// The origin of the alert.
Origin string `toml:"origin" override:"origin"`
// Optional timeout.
Timeout toml.Duration `toml:"timeout" override:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave this one as toml.Duration so it parses from the configuration.

@@ -204,6 +215,13 @@ func (s *Service) preparePost(token, tokenPrefix, resource, event, environment,
if len(service) > 0 {
postData["service"] = service
}
postData["timeout"] = int64(timeout / toml.Duration(time.Second))

_tags := make([]string, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit tagList would be a better name here.

@m4ce m4ce force-pushed the feature/alerta_service_template branch 4 times, most recently from 63693e6 to 66f6059 Compare September 2, 2017 21:04
@m4ce
Copy link
Contributor Author

m4ce commented Sep 2, 2017

@nathanielc, thanks for the feedback. I've implemented the requested changes. I'm now defaulting timeout using the defaultHanderConfig, that should be okay too?

Looking at it now, there's one test that doesn't go through but can't quite figure out why.

@m4ce m4ce force-pushed the feature/alerta_service_template branch from 749a993 to 5dfcdaf Compare September 3, 2017 15:10
@m4ce
Copy link
Contributor Author

m4ce commented Sep 3, 2017

@nathanielc, I've adjusted the tests and are now passing. Hope it looks good now.

@m4ce m4ce force-pushed the feature/alerta_service_template branch from 1cfcab2 to b75b022 Compare September 3, 2017 18:13
@m4ce m4ce force-pushed the feature/alerta_service_template branch from b75b022 to d73ed51 Compare September 3, 2017 19:26
@m4ce
Copy link
Contributor Author

m4ce commented Sep 8, 2017

@nathanielc, any chance you could review this before cutting the next release? Thanks.

@nathanielc nathanielc merged commit d73ed51 into influxdata:master Sep 8, 2017
nathanielc added a commit that referenced this pull request Sep 8, 2017
Alerta support for timeout, tags and service template
@nathanielc
Copy link
Contributor

@m4ce Thanks for the PR!

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