-
Notifications
You must be signed in to change notification settings - Fork 9k
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
config¬ifier: Add option to use Alertmanager API v2 #5482
Conversation
notifier/notifier.go
Outdated
@@ -490,13 +513,40 @@ func (n *Manager) sendAll(alerts ...*Alert) bool { | |||
wg.Done() | |||
}(ams, am) | |||
} | |||
ams.mtx.RUnlock() |
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 would unlock the read lock, even though the spawned go routines still had references to ams
, resulting in possible race conditions. Instead, the lock is dropped at the end of the function via defer
now. This is safe as the function waits for all spawned goroutines before exiting.
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.
Another option would be to still release the lock here and pass the necessary inputs to the goroutine:
ams.mtx.RLock()
for _, am := range ams.ams {
...
go func(c *http.Client, u string) {
if err := n.sendOne(ctx, c, u, b); err != nil {
...
}
}(ams.client, am.url().String())
}
ams.mtx.RUnlock()
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.
That's even better, thanks @simonpasquier.
"github.com/pkg/errors" | ||
"github.com/prometheus/client_golang/prometheus" | ||
config_util "github.com/prometheus/common/config" | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/common/version" | ||
|
||
"github.com/prometheus/alertmanager/api/v2/models" |
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 patch vendors the Alertmanager API v2 model. From my point of view, this gives us a strong contract between the two APIs. Let me know what you think.
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.
Looks good to me.
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.
Docs need updating.
config/config.go
Outdated
return err | ||
} | ||
|
||
// Default to Alertmanager API v1. |
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 isn't how we generally implement defaults.
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.
Changed to the default way of doing defaults. Thanks.
notifier/notifier.go
Outdated
@@ -490,13 +513,40 @@ func (n *Manager) sendAll(alerts ...*Alert) bool { | |||
wg.Done() | |||
}(ams, am) | |||
} | |||
ams.mtx.RUnlock() |
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.
Another option would be to still release the lock here and pass the necessary inputs to the goroutine:
ams.mtx.RLock()
for _, am := range ams.ams {
...
go func(c *http.Client, u string) {
if err := n.sendOne(ctx, c, u, b); err != nil {
...
}
}(ams.client, am.url().String())
}
ams.mtx.RUnlock()
ams.mtx.RLock() | ||
defer ams.mtx.RUnlock() | ||
|
||
switch ams.cfg.APIVersion { |
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.
Maybe it could be cached to avoid serializing several times the same data.
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.
Good point. Done.
"github.com/pkg/errors" | ||
"github.com/prometheus/client_golang/prometheus" | ||
config_util "github.com/prometheus/common/config" | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/common/version" | ||
|
||
"github.com/prometheus/alertmanager/api/v2/models" |
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.
Looks good to me.
348ac70
to
585381b
Compare
@brian-brazil I updated docs/configuration/configuration.md. Any other docs that I am missing? |
There's Alerting -> Clients, but that's not in this repo. |
With v0.16.0 Alertmanager introduced a new API (v2). This patch adds a configuration option for Prometheus to send alerts to the v2 endpoint instead of the defautl v1 endpoint. Signed-off-by: Max Leonard Inden <[email protected]>
@simonpasquier @brian-brazil any further thoughts on this? |
👍 |
Tested this on a larger setup as well. Thanks for the help. |
With v0.16.0 Alertmanager introduced a new API (v2). This patch adds a
configuration option for Prometheus to send alerts to the v2 endpoint
instead of the defautl v1 endpoint.
Fixes #5167