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 Teams field #1101

Merged
merged 2 commits into from
Nov 15, 2017

Conversation

Tom-Fawcett
Copy link
Contributor

#1061 broke the OpsGenie Teams field.

The structure of this field has in fact changed between v1 and v2.

OpsGenie Documentation

Tests

  • No team config set. ✓
  • One team value set. ✓
  • Multiple team values set. ✓

I apologise for missing this in #1061.

notify/impl.go Outdated
@@ -835,13 +839,17 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}

apiURL = n.conf.APIURL + "v2/alerts"
var teams []opsGenieTeam
for _, t := range strings.Split(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.

This mix of templating, splitting and a list of single-field structs seems odd. Why not keep the config as-is, and split?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review.

I am probably going to show myself up here - but this was the only way I could think of to produce the desired JSON array of objects. ie:

"teams":[{"name":"foo_team"}, {"name":"bar_team"}], 

Copy link
Contributor

Choose a reason for hiding this comment

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

@Tom-Fawcett Think that instead of having the teams config be a string https://github.com/prometheus/alertmanager/blob/master/config/notifiers.go#L308 on the alertmanager yaml, it should be a list of key values, this way we can also support the team's id, and not only the name.

eg:

teams: 
   - id: 'team_id1'
   - id: 'team_id2'

or

teams:
  - name: 'team_name1'
  - name: 'team_name2'

@brian-brazil what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with that is that you have to know the number of teams in advance, as we can only template within a field - not across a list.

Copy link
Contributor

@stuartnelson3 stuartnelson3 Nov 15, 2017

Choose a reason for hiding this comment

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

Is there a reason we don't want to do this at the config level? It would break configs for users upgrading, so we would have to do another release.

# Teams that the alert will be routed to. The key value must be either id or name.
[ teams: { <id|name>: <tmpl_string>, ... } ]

The docs support either a name or id as the key; do we want to make the assumption for users that they're providing team names?

Copy link
Contributor

@josedonizetti josedonizetti Nov 15, 2017

Choose a reason for hiding this comment

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

maybe to avoid a new release, and also fix the problem we can for now do

  1. what @stuartnelson3 said We can drop the opsGenieTeam struct and just append a map[string]string{"name": t}
  2. only support one team name, for now, I don't like much the strings.Split by comma approach

Then we discuss a better approach for a next release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback.

The use of Split was to try and preserve functionality without changing config.

I can push the suggestion of using map[string]string{"name": t} in place of opsGenieTeam.

Could I please get some further guidance on the race condition.

And a decision on what I should do about config, if I am removing Split.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry my comment wasn't clear, there is no race condition in the code you've written. @josedonizetti and I suggested the same thing within minutes of eachother, that's what I was referring to.

Only supporting a single team name would also be breaking the interface we present to users, as we explicitly state that it's a comma separated list of teams.

t := strings.Split(n.conf.Teams, ",")
teams := make([]map[string]string, 0, len(t))
for _, name := range t {
	teams = append(teams, map[string]string{"name": tmpl(name)})
}

I would be fine with the above for now.

Copy link
Contributor

@josedonizetti josedonizetti Nov 15, 2017

Choose a reason for hiding this comment

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

@Tom-Fawcett could you tackle the tags problem as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stuartnelson3 ah, yes I missed that joke!

The main difference between your example snippet and this PR (after my latest commit), is you split and then use tmpl. That doesn't seem like it would work?

@josedonizetti yep 👍

Details map[string]string `json:"details"`
Source string `json:"source"`
Teams []map[string]string `json:"teams,omitempty"`
Tags string `json:"tags,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update this to []string, as specified in the API docs, and split n.conf.Tags on , and pass that to the create message?

Copy link
Contributor

Choose a reason for hiding this comment

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

disregard, #1108 covers it

@stuartnelson3 stuartnelson3 merged commit 291fc57 into prometheus:master Nov 15, 2017
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