mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-01 02:52:06 +00:00
Generalize iterator interface, locking fixes
This commit is contained in:
parent
4d2ab84503
commit
5d0f3ffa0e
@ -85,6 +85,9 @@ func (a *MemAlerts) IterActive() AlertIterator {
|
||||
}
|
||||
|
||||
func (a *MemAlerts) All() ([]*types.Alert, error) {
|
||||
a.mtx.RLock()
|
||||
defer a.mtx.RUnlock()
|
||||
|
||||
var alerts []*types.Alert
|
||||
for _, a := range a.alerts {
|
||||
alerts = append(alerts, a)
|
||||
@ -93,8 +96,8 @@ func (a *MemAlerts) All() ([]*types.Alert, error) {
|
||||
}
|
||||
|
||||
func (a *MemAlerts) Put(alerts ...*types.Alert) error {
|
||||
a.mtx.RLock()
|
||||
defer a.mtx.RUnlock()
|
||||
a.mtx.Lock()
|
||||
defer a.mtx.Unlock()
|
||||
|
||||
for _, alert := range alerts {
|
||||
a.alerts[alert.Fingerprint()] = alert
|
||||
|
@ -20,12 +20,16 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
)
|
||||
|
||||
type AlertIterator interface {
|
||||
Next() <-chan *types.Alert
|
||||
type Iterator interface {
|
||||
Err() error
|
||||
Close()
|
||||
}
|
||||
|
||||
type AlertIterator interface {
|
||||
Iterator
|
||||
Next() <-chan *types.Alert
|
||||
}
|
||||
|
||||
// Alerts gives access to a set of alerts.
|
||||
type Alerts interface {
|
||||
// IterActive returns an iterator over active alerts from the
|
||||
@ -48,7 +52,7 @@ type Silences interface {
|
||||
types.Silencer
|
||||
|
||||
// All returns all existing silences.
|
||||
All() []*types.Silence
|
||||
All() ([]*types.Silence, error)
|
||||
// Set a new silence.
|
||||
Set(*types.Silence) error
|
||||
// Del removes a silence.
|
||||
@ -57,6 +61,27 @@ type Silences interface {
|
||||
Get(model.Fingerprint) (*types.Silence, error)
|
||||
}
|
||||
|
||||
type Notify struct {
|
||||
Target string
|
||||
Alerts []model.Fingerprint
|
||||
Pending bool
|
||||
}
|
||||
|
||||
type NotifyIterator interface {
|
||||
Iterator
|
||||
Next() <-chan *Notify
|
||||
}
|
||||
|
||||
// Notifies provides information about pending and successful
|
||||
// notifications.
|
||||
type Notifies interface {
|
||||
// IterPending returns an iterator over all notifies that have not
|
||||
// yet been sent successfully.
|
||||
IterPending() NotifyIterator
|
||||
//
|
||||
Set(*Notify) error
|
||||
}
|
||||
|
||||
// Reloadable is a component that can change its state based
|
||||
// on a new configuration.
|
||||
type Reloadable interface {
|
||||
|
Loading…
Reference in New Issue
Block a user