mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-29 09:42:58 +00:00
*: rename NotifyInfo to NotificationInfo
This commit is contained in:
parent
37eb2127b7
commit
66c2171bd8
@ -221,7 +221,7 @@ func Dedup(notifies provider.Notifies, n Notifier) *DedupingNotifier {
|
||||
|
||||
// hasUpdates checks an alert against the last notification that was made
|
||||
// about it.
|
||||
func (n *DedupingNotifier) hasUpdate(alert *types.Alert, last *types.NotifyInfo, now time.Time, interval time.Duration) bool {
|
||||
func (n *DedupingNotifier) hasUpdate(alert *types.Alert, last *types.NotificationInfo, now time.Time, interval time.Duration) bool {
|
||||
if last != nil {
|
||||
if alert.Resolved() {
|
||||
if last.Resolved {
|
||||
@ -282,10 +282,10 @@ func (n *DedupingNotifier) Notify(ctx context.Context, alerts ...*types.Alert) e
|
||||
return nil
|
||||
}
|
||||
|
||||
var newNotifies []*types.NotifyInfo
|
||||
var newNotifies []*types.NotificationInfo
|
||||
|
||||
for _, a := range alerts {
|
||||
newNotifies = append(newNotifies, &types.NotifyInfo{
|
||||
newNotifies = append(newNotifies, &types.NotificationInfo{
|
||||
Alert: a.Fingerprint(),
|
||||
Receiver: name,
|
||||
Resolved: a.Resolved(),
|
||||
|
@ -51,7 +51,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
)
|
||||
cases := []struct {
|
||||
inAlert *types.Alert
|
||||
inNotifyInfo *types.NotifyInfo
|
||||
inNotifyInfo *types.NotificationInfo
|
||||
result bool
|
||||
}{
|
||||
// A new alert about which there's no previous notification information.
|
||||
@ -87,7 +87,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
EndsAt: now,
|
||||
},
|
||||
},
|
||||
inNotifyInfo: &types.NotifyInfo{
|
||||
inNotifyInfo: &types.NotificationInfo{
|
||||
Alert: model.LabelSet{"alertname": "a"}.Fingerprint(),
|
||||
Resolved: false,
|
||||
Timestamp: now.Add(-time.Minute),
|
||||
@ -103,7 +103,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
EndsAt: now,
|
||||
},
|
||||
},
|
||||
inNotifyInfo: &types.NotifyInfo{
|
||||
inNotifyInfo: &types.NotificationInfo{
|
||||
Alert: model.LabelSet{"alertname": "a"}.Fingerprint(),
|
||||
Resolved: true,
|
||||
Timestamp: now.Add(-time.Minute),
|
||||
@ -118,7 +118,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
StartsAt: now.Add(-3 * time.Minute),
|
||||
},
|
||||
},
|
||||
inNotifyInfo: &types.NotifyInfo{
|
||||
inNotifyInfo: &types.NotificationInfo{
|
||||
Alert: model.LabelSet{"alertname": "a"}.Fingerprint(),
|
||||
Resolved: true,
|
||||
Timestamp: now.Add(-4 * time.Minute),
|
||||
@ -134,7 +134,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
StartsAt: now.Add(-10 * time.Minute),
|
||||
},
|
||||
},
|
||||
inNotifyInfo: &types.NotifyInfo{
|
||||
inNotifyInfo: &types.NotificationInfo{
|
||||
Alert: model.LabelSet{"alertname": "a"}.Fingerprint(),
|
||||
Resolved: false,
|
||||
Timestamp: now.Add(-15 * time.Minute),
|
||||
@ -150,7 +150,7 @@ func TestDedupingNotifierHasUpdate(t *testing.T) {
|
||||
StartsAt: now.Add(-10 * time.Minute),
|
||||
},
|
||||
},
|
||||
inNotifyInfo: &types.NotifyInfo{
|
||||
inNotifyInfo: &types.NotificationInfo{
|
||||
Alert: model.LabelSet{"alertname": "a"}.Fingerprint(),
|
||||
Resolved: false,
|
||||
Timestamp: now.Add(-115 * time.Minute),
|
||||
@ -194,7 +194,7 @@ func TestDedupingNotifier(t *testing.T) {
|
||||
|
||||
// Set an initial NotifyInfo to ensure that on notification failure
|
||||
// nothing changes.
|
||||
nsBefore := []*types.NotifyInfo{
|
||||
nsBefore := []*types.NotificationInfo{
|
||||
nil,
|
||||
{
|
||||
Alert: alerts[1].Fingerprint(),
|
||||
@ -234,7 +234,7 @@ func TestDedupingNotifier(t *testing.T) {
|
||||
t.Fatalf("Error getting notifies: %s", err)
|
||||
}
|
||||
|
||||
nsAfter := []*types.NotifyInfo{
|
||||
nsAfter := []*types.NotificationInfo{
|
||||
{
|
||||
Alert: alerts[0].Fingerprint(),
|
||||
Receiver: "name",
|
||||
@ -408,17 +408,17 @@ func TestInhibitNotifier(t *testing.T) {
|
||||
|
||||
type testInfos struct {
|
||||
mtx sync.RWMutex
|
||||
m map[string]map[model.Fingerprint]*types.NotifyInfo
|
||||
m map[string]map[model.Fingerprint]*types.NotificationInfo
|
||||
}
|
||||
|
||||
func newTestInfos() *testInfos {
|
||||
return &testInfos{
|
||||
m: map[string]map[model.Fingerprint]*types.NotifyInfo{},
|
||||
m: map[string]map[model.Fingerprint]*types.NotificationInfo{},
|
||||
}
|
||||
}
|
||||
|
||||
// Set implements the Notifies interface.
|
||||
func (n *testInfos) Set(ns ...*types.NotifyInfo) error {
|
||||
func (n *testInfos) Set(ns ...*types.NotificationInfo) error {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
|
||||
@ -429,7 +429,7 @@ func (n *testInfos) Set(ns ...*types.NotifyInfo) error {
|
||||
}
|
||||
am, ok := n.m[v.Receiver]
|
||||
if !ok {
|
||||
am = map[model.Fingerprint]*types.NotifyInfo{}
|
||||
am = map[model.Fingerprint]*types.NotificationInfo{}
|
||||
n.m[v.Receiver] = am
|
||||
}
|
||||
am[v.Alert] = v
|
||||
@ -438,11 +438,11 @@ func (n *testInfos) Set(ns ...*types.NotifyInfo) error {
|
||||
}
|
||||
|
||||
// Get implements the Notifies interface.
|
||||
func (n *testInfos) Get(dest string, fps ...model.Fingerprint) ([]*types.NotifyInfo, error) {
|
||||
func (n *testInfos) Get(dest string, fps ...model.Fingerprint) ([]*types.NotificationInfo, error) {
|
||||
n.mtx.RLock()
|
||||
defer n.mtx.RUnlock()
|
||||
|
||||
res := make([]*types.NotifyInfo, len(fps))
|
||||
res := make([]*types.NotificationInfo, len(fps))
|
||||
|
||||
ns, ok := n.m[dest]
|
||||
if !ok {
|
||||
|
@ -378,8 +378,8 @@ func (n *NotificationInfo) Close() error {
|
||||
}
|
||||
|
||||
// Get notification information for alerts and the given receiver.
|
||||
func (n *NotificationInfo) Get(recv string, fps ...model.Fingerprint) ([]*types.NotifyInfo, error) {
|
||||
var res []*types.NotifyInfo
|
||||
func (n *NotificationInfo) Get(recv string, fps ...model.Fingerprint) ([]*types.NotificationInfo, error) {
|
||||
var res []*types.NotificationInfo
|
||||
|
||||
err := n.db.View(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket(bktNotificationInfo)
|
||||
@ -395,7 +395,7 @@ func (n *NotificationInfo) Get(recv string, fps ...model.Fingerprint) ([]*types.
|
||||
continue
|
||||
}
|
||||
|
||||
ni := &types.NotifyInfo{
|
||||
ni := &types.NotificationInfo{
|
||||
Alert: fp,
|
||||
Receiver: recv,
|
||||
Resolved: v[0] == 1,
|
||||
@ -412,7 +412,7 @@ func (n *NotificationInfo) Get(recv string, fps ...model.Fingerprint) ([]*types.
|
||||
}
|
||||
|
||||
// Set several notifies at once. All or none must succeed.
|
||||
func (n *NotificationInfo) Set(ns ...*types.NotifyInfo) error {
|
||||
func (n *NotificationInfo) Set(ns ...*types.NotificationInfo) error {
|
||||
err := n.db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket(bktNotificationInfo)
|
||||
|
||||
|
@ -39,14 +39,14 @@ func TestNotifiesSet(t *testing.T) {
|
||||
type query struct {
|
||||
recv string
|
||||
fps []model.Fingerprint
|
||||
expected []*types.NotifyInfo
|
||||
expected []*types.NotificationInfo
|
||||
}
|
||||
var steps = []struct {
|
||||
insert []*types.NotifyInfo
|
||||
insert []*types.NotificationInfo
|
||||
queries []query
|
||||
}{
|
||||
{
|
||||
insert: []*types.NotifyInfo{
|
||||
insert: []*types.NotificationInfo{
|
||||
{
|
||||
Alert: 30000,
|
||||
Receiver: "receiver",
|
||||
@ -68,7 +68,7 @@ func TestNotifiesSet(t *testing.T) {
|
||||
{
|
||||
recv: "receiver",
|
||||
fps: []model.Fingerprint{30000, 30001, 20000, 10000},
|
||||
expected: []*types.NotifyInfo{
|
||||
expected: []*types.NotificationInfo{
|
||||
{
|
||||
Alert: 30000,
|
||||
Receiver: "receiver",
|
||||
@ -520,7 +520,7 @@ func silenceListEqual(s1, s2 []*types.Silence) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func notifyInfoEqual(n1, n2 *types.NotifyInfo) bool {
|
||||
func notifyInfoEqual(n1, n2 *types.NotificationInfo) bool {
|
||||
// nil is a sentinel value and thus part of comparisons.
|
||||
if n1 == nil || n2 == nil {
|
||||
return n1 == nil && n2 == nil
|
||||
@ -537,7 +537,7 @@ func notifyInfoEqual(n1, n2 *types.NotifyInfo) bool {
|
||||
return n1.Resolved == n2.Resolved
|
||||
}
|
||||
|
||||
func notifyInfoListEqual(n1, n2 []*types.NotifyInfo) bool {
|
||||
func notifyInfoListEqual(n1, n2 []*types.NotificationInfo) bool {
|
||||
|
||||
if len(n1) != len(n2) {
|
||||
return false
|
||||
|
@ -160,7 +160,7 @@ func (ni *NotificationInfos) OnGossipUnicast(_ mesh.PeerName, b []byte) error {
|
||||
}
|
||||
|
||||
// Set the provided notification information.
|
||||
func (ni *NotificationInfos) Set(ns ...*types.NotifyInfo) error {
|
||||
func (ni *NotificationInfos) Set(ns ...*types.NotificationInfo) error {
|
||||
set := map[string]notificationEntry{}
|
||||
for _, n := range ns {
|
||||
k := fmt.Sprintf("%s:%s", n.Alert, n.Receiver)
|
||||
@ -179,12 +179,12 @@ func (ni *NotificationInfos) Set(ns ...*types.NotifyInfo) error {
|
||||
// Get the notification information for the given receiver about alerts
|
||||
// with the given fingerprints. Returns a slice in order of the input fingerprints.
|
||||
// Result entries are nil if nothing was found.
|
||||
func (ni *NotificationInfos) Get(recv string, fps ...model.Fingerprint) ([]*types.NotifyInfo, error) {
|
||||
res := make([]*types.NotifyInfo, 0, len(fps))
|
||||
func (ni *NotificationInfos) Get(recv string, fps ...model.Fingerprint) ([]*types.NotificationInfo, error) {
|
||||
res := make([]*types.NotificationInfo, 0, len(fps))
|
||||
for _, fp := range fps {
|
||||
k := fmt.Sprintf("%s:%s", fp, recv)
|
||||
if e, ok := ni.st.set[k]; ok {
|
||||
res = append(res, &types.NotifyInfo{
|
||||
res = append(res, &types.NotificationInfo{
|
||||
Alert: fp,
|
||||
Receiver: recv,
|
||||
Resolved: e.Resolved,
|
||||
|
@ -204,13 +204,13 @@ func TestNotificationInfosSet(t *testing.T) {
|
||||
)
|
||||
cases := []struct {
|
||||
initial map[string]notificationEntry
|
||||
input []*types.NotifyInfo
|
||||
input []*types.NotificationInfo
|
||||
update map[string]notificationEntry
|
||||
final map[string]notificationEntry
|
||||
}{
|
||||
{
|
||||
initial: map[string]notificationEntry{},
|
||||
input: []*types.NotifyInfo{
|
||||
input: []*types.NotificationInfo{
|
||||
{
|
||||
Alert: 0x10,
|
||||
Receiver: "recv1",
|
||||
@ -235,7 +235,7 @@ func TestNotificationInfosSet(t *testing.T) {
|
||||
"0000000000000010:recv1": {false, now},
|
||||
"0000000000000010:recv2": {false, now.Add(10 * time.Minute)},
|
||||
},
|
||||
input: []*types.NotifyInfo{
|
||||
input: []*types.NotificationInfo{
|
||||
{
|
||||
Alert: 0x10,
|
||||
Receiver: "recv1",
|
||||
@ -302,7 +302,7 @@ func TestNotificationInfosGet(t *testing.T) {
|
||||
type query struct {
|
||||
recv string
|
||||
fps []model.Fingerprint
|
||||
want []*types.NotifyInfo
|
||||
want []*types.NotificationInfo
|
||||
}
|
||||
cases := []struct {
|
||||
state map[string]notificationEntry
|
||||
@ -319,7 +319,7 @@ func TestNotificationInfosGet(t *testing.T) {
|
||||
{
|
||||
recv: "recv1",
|
||||
fps: []model.Fingerprint{0x1000, 0x10, 0x20},
|
||||
want: []*types.NotifyInfo{
|
||||
want: []*types.NotificationInfo{
|
||||
nil,
|
||||
{
|
||||
Alert: 0x10,
|
||||
@ -333,7 +333,7 @@ func TestNotificationInfosGet(t *testing.T) {
|
||||
{
|
||||
recv: "unknown",
|
||||
fps: []model.Fingerprint{0x10, 0x1000},
|
||||
want: []*types.NotifyInfo{nil, nil},
|
||||
want: []*types.NotificationInfo{nil, nil},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -108,7 +108,7 @@ type Silences interface {
|
||||
// Notifies provides information about pending and successful
|
||||
// notifications. All methods are goroutine-safe.
|
||||
type Notifies interface {
|
||||
Get(dest string, fps ...model.Fingerprint) ([]*types.NotifyInfo, error)
|
||||
Get(dest string, fps ...model.Fingerprint) ([]*types.NotificationInfo, error)
|
||||
// Set several notifies at once. All or none must succeed.
|
||||
Set(ns ...*types.NotifyInfo) error
|
||||
Set(ns ...*types.NotificationInfo) error
|
||||
}
|
||||
|
@ -304,21 +304,21 @@ func (s *Silence) Deleted() bool {
|
||||
return s.StartsAt.Equal(s.EndsAt)
|
||||
}
|
||||
|
||||
// NotifyInfo holds information about the last successful notification
|
||||
// NotifcationInfo holds information about the last successful notification
|
||||
// of an alert to a receiver.
|
||||
type NotifyInfo struct {
|
||||
type NotificationInfo struct {
|
||||
Alert model.Fingerprint
|
||||
Receiver string
|
||||
Resolved bool
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (n *NotifyInfo) String() string {
|
||||
func (n *NotificationInfo) String() string {
|
||||
return fmt.Sprintf("<Notify:%q@%s to=%v res=%v>", n.Alert, n.Timestamp, n.Receiver, n.Resolved)
|
||||
}
|
||||
|
||||
// Fingerprint returns a quasi-unique fingerprint for the NotifyInfo.
|
||||
func (n *NotifyInfo) Fingerprint() model.Fingerprint {
|
||||
func (n *NotificationInfo) Fingerprint() model.Fingerprint {
|
||||
h := fnv.New64a()
|
||||
h.Write([]byte(n.Receiver))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user