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

Fix OpsGenie notifier and add unit tests #1224

Merged
merged 1 commit into from
Feb 6, 2018

Conversation

iksaif
Copy link
Contributor

@iksaif iksaif commented Feb 5, 2018

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.

@@ -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)), ",") {
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 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.

Copy link
Contributor Author

@iksaif iksaif Feb 6, 2018

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

@iksaif iksaif force-pushed the pr-opsgenie branch 2 times, most recently from 2628106 to 32596f0 Compare February 6, 2018 10:23
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
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 removed

Copy link
Contributor Author

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.
@stuartnelson3 stuartnelson3 merged commit a43a513 into prometheus:master Feb 6, 2018
@dswarbrick
Copy link

Is there some reason why Alertmanager doesn't simply use https://github.com/opsgenie/opsgenie-go-sdk?

@stuartnelson3
Copy link
Contributor

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.

@brian-brazil
Copy link
Contributor

I don't believe we were aware of it. We had problems even finding what API docs there were.

hh pushed a commit to ii/alertmanager that referenced this pull request Feb 8, 2019
* 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>
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.

4 participants