|
|
@ -16,7 +16,6 @@ package notification |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"flag" |
|
|
|
|
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
@ -42,10 +41,6 @@ const ( |
|
|
|
subsystem = "notifications" |
|
|
|
subsystem = "notifications" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
deadline = flag.Duration("alertmanager.http-deadline", 10*time.Second, "Alert manager HTTP API timeout.") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NotificationReq is a request for sending a notification to the alert manager
|
|
|
|
// NotificationReq is a request for sending a notification to the alert manager
|
|
|
|
// for a single alert vector element.
|
|
|
|
// for a single alert vector element.
|
|
|
|
type NotificationReq struct { |
|
|
|
type NotificationReq struct { |
|
|
@ -93,13 +88,20 @@ type NotificationHandler struct { |
|
|
|
stopped chan struct{} |
|
|
|
stopped chan struct{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NotificationHandlerOptions are the configurable parameters of a NotificationHandler.
|
|
|
|
|
|
|
|
type NotificationHandlerOptions struct { |
|
|
|
|
|
|
|
AlertmanagerURL string |
|
|
|
|
|
|
|
QueueCapacity int |
|
|
|
|
|
|
|
Deadline time.Duration |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewNotificationHandler constructs a new NotificationHandler.
|
|
|
|
// NewNotificationHandler constructs a new NotificationHandler.
|
|
|
|
func NewNotificationHandler(alertmanagerURL string, notificationQueueCapacity int) *NotificationHandler { |
|
|
|
func NewNotificationHandler(o *NotificationHandlerOptions) *NotificationHandler { |
|
|
|
return &NotificationHandler{ |
|
|
|
return &NotificationHandler{ |
|
|
|
alertmanagerURL: strings.TrimRight(alertmanagerURL, "/"), |
|
|
|
alertmanagerURL: strings.TrimRight(o.AlertmanagerURL, "/"), |
|
|
|
pendingNotifications: make(chan NotificationReqs, notificationQueueCapacity), |
|
|
|
pendingNotifications: make(chan NotificationReqs, o.QueueCapacity), |
|
|
|
|
|
|
|
|
|
|
|
httpClient: httputil.NewDeadlineClient(*deadline), |
|
|
|
httpClient: httputil.NewDeadlineClient(o.Deadline), |
|
|
|
|
|
|
|
|
|
|
|
notificationLatency: prometheus.NewSummary(prometheus.SummaryOpts{ |
|
|
|
notificationLatency: prometheus.NewSummary(prometheus.SummaryOpts{ |
|
|
|
Namespace: namespace, |
|
|
|
Namespace: namespace, |
|
|
@ -132,7 +134,7 @@ func NewNotificationHandler(alertmanagerURL string, notificationQueueCapacity in |
|
|
|
nil, nil, |
|
|
|
nil, nil, |
|
|
|
), |
|
|
|
), |
|
|
|
prometheus.GaugeValue, |
|
|
|
prometheus.GaugeValue, |
|
|
|
float64(notificationQueueCapacity), |
|
|
|
float64(o.QueueCapacity), |
|
|
|
), |
|
|
|
), |
|
|
|
stopped: make(chan struct{}), |
|
|
|
stopped: make(chan struct{}), |
|
|
|
} |
|
|
|
} |
|
|
|