-
Notifications
You must be signed in to change notification settings - Fork 492
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
Alerta support for timeout, tags and service template #1545
Conversation
14a959a
to
7416243
Compare
80099ef
to
cd7f1c4
Compare
not exactly sure why it's failing over one test :/ |
There was a problem hiding this 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
.
services/alerta/service.go
Outdated
@@ -22,6 +24,7 @@ const ( | |||
defaultResource = "{{ .Name }}" | |||
defaultEvent = "{{ .ID }}" | |||
defaultGroup = "{{ .Group }}" | |||
defaultTimeout = toml.Duration(86400 * time.Second) |
There was a problem hiding this comment.
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.
services/alerta/service.go
Outdated
@@ -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), |
There was a problem hiding this comment.
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.
services/alerta/service.go
Outdated
@@ -185,6 +192,10 @@ func (s *Service) preparePost(token, tokenPrefix, resource, event, environment, | |||
origin = c.Origin | |||
} | |||
|
|||
if timeout == toml.Duration(0) { |
There was a problem hiding this comment.
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.
services/alerta/service.go
Outdated
Message string `json:"message"` | ||
Origin string `json:"origin"` | ||
Service []string `json:"service"` | ||
Timeout toml.Duration `json:"timeout"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use time.Duration
services/alerta/service.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
services/alerta/service.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
.
services/alerta/service.go
Outdated
@@ -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)) |
There was a problem hiding this comment.
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)
services/alerta/service.go
Outdated
@@ -262,6 +280,9 @@ type HandlerConfig struct { | |||
|
|||
// List of effected Services | |||
Service []string `mapstructure:"service"` | |||
|
|||
// Timeout | |||
Timeout toml.Duration `mapstructure:"timeout"` |
There was a problem hiding this comment.
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
services/alerta/config.go
Outdated
@@ -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"` |
There was a problem hiding this comment.
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.
services/alerta/service.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
63693e6
to
66f6059
Compare
@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. |
749a993
to
5dfcdaf
Compare
@nathanielc, I've adjusted the tests and are now passing. Hope it looks good now. |
1cfcab2
to
b75b022
Compare
b75b022
to
d73ed51
Compare
@nathanielc, any chance you could review this before cutting the next release? Thanks. |
Alerta support for timeout, tags and service template
@m4ce Thanks for the PR! |
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