-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix OpsGenie notifier and add unit tests #1224
Conversation
@@ -987,45 +1013,39 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
|
|||
apiURL = n.conf.APIURL + "v2/alerts" | |||
var teams []map[string]string | |||
for _, t := range strings.Split(string(tmpl(n.conf.Teams)), ",") { | |||
for _, t := range safeSplit(string(tmpl(n.conf.Teams)), ",") { |
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.
I think this should be returned to just strings.Split
and then check each t
for being an empty string. If someone enters "team1,"
in their config, it'll still end up adding "name":""
in the json.
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.
done, and added a test for it
2628106
to
32596f0
Compare
notify/impl.go
Outdated
|
||
// Like Split but filter out empty strings. | ||
func safeSplit(s string, sep string) []string { | ||
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating |
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 removed
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.
done
See prometheus#1223, looks like OpsGenie now sometimes returns a 422 when you don't specify a team. This change cleans up the JSON output and add a few unit tests.
Is there some reason why Alertmanager doesn't simply use https://github.com/opsgenie/opsgenie-go-sdk? |
Not that I'm aware of. Potentially it didn't exist when this was written. Also, the entire implementation in our codebase is ~150 lines of code. Maybe it wasn't viewed as necessary to add the dependency. |
I don't believe we were aware of it. We had problems even finding what API docs there were. |
* Rename interface to device in netclass collector This makes it consistent with other networking metrics like node_network_receive_bytes_total This closes prometheus#1223 Signed-off-by: Johannes 'fish' Ziemke <github@freigeist.org>
See #1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.