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

Support for responders in OpsGenie #131

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

yuri-tceretian
Copy link
Contributor

@yuri-tceretian yuri-tceretian commented Oct 25, 2023

This PR adds support for a new field "responders" to OpsGenie. Documentation https://docs.opsgenie.com/docs/alert-api#create-alert
The config structure and handling logic are taken from vanilla Alertmanager https://github.com/prometheus/alertmanager/blob/9a8d1f976e12b325ec47b84987a78b7845738be6/notify/opsgenie/opsgenie.go#L185-L213

I improved logic around expanding of "teams" responder to make sure that user provides the correct combination of fields.

Can be tested in grafana/grafana#77159

Copy link
Contributor

@santihernandezc santihernandezc left a comment

Choose a reason for hiding this comment

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

Looks pretty good! I left a few comments, the one about the templated values being the most important one.

if err != nil {
return Config{}, fmt.Errorf("responder at index [%d] type is not a valid template: %v", idx, err)
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This else causes values containing templates to bypass validation. If the value of this field is for example {{ printf "lol" }} the end result will be invalid but no error will be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with this. The main reason to support it is the upstream. So, I think that if a user goes this way and decides to use the template the validity of the result is in their hands.

Copy link
Contributor

Choose a reason for hiding this comment

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

But why not remove the else and let the template be checked as any other value after it's evaluated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the result of the template expansion could be different when it is applied with actual alerts as the context. For example {{ .CommonAnnotations.ResponderType }}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, makes sense!

@@ -74,6 +86,33 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi
raw.OverridePriority = &overridePriority
}

for idx, r := range raw.Responders {
if r.ID == "" && r.Username == "" && r.Name == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the section for the visibleTo field and the examples for both responders and visibleTo in the Opsgenie docs it's not clear to me whether any of these three values are valid for each type.

  • The user type goes with either id or username, but not with name
  • The team type goes with either id or name, but not with username

This validation doesn't take these edge cases into account, could you confirm that this is not an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the id and name can be used for any types but username - is only for the user type.

I think it makes sense to add a validation that would make sure that if username is specified then the type must be user. What worries me is that it would cause even bigger drift between alertmanager flavors. If you think this is ok, I will introduce it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the OpsGenie API returns an error, then adding validation at the Alertmanager level is not really a breaking change, but just catching an error before it happens. I'd say double check and go for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that invalid combinations of the fields are accepted by Opsgenie but ignored. So, I do not think it makes sense to add any additional validation that does not cause the request to fail

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks for double-checking :)

expMsgError: nil,
},
{
name: "Config with teams responders should be exploded",
Copy link
Contributor

Choose a reason for hiding this comment

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

So PHP! 😄

Copy link
Contributor

@santihernandezc santihernandezc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@yuri-tceretian yuri-tceretian merged commit 0799667 into main Oct 26, 2023
3 checks passed
@yuri-tceretian yuri-tceretian deleted the yuri-tceretian/opsgenie-responders branch October 26, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants