Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions store/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Prometheus Team
// Copyright Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -32,7 +32,7 @@ var ErrNotFound = errors.New("alert not found")
// gcInterval. An optional callback can be set which receives a slice of all
// resolved alerts that have been removed.
type Alerts struct {
sync.Mutex
sync.RWMutex
c map[model.Fingerprint]*types.Alert
cb func([]types.Alert)
}
Expand Down Expand Up @@ -97,8 +97,8 @@ func (a *Alerts) GC() []types.Alert {
// Get returns the Alert with the matching fingerprint, or an error if it is
// not found.
func (a *Alerts) Get(fp model.Fingerprint) (*types.Alert, error) {
a.Lock()
defer a.Unlock()
a.RLock()
defer a.RUnlock()

alert, prs := a.c[fp]
if !prs {
Expand Down Expand Up @@ -132,8 +132,8 @@ func (a *Alerts) DeleteIfNotModified(alerts types.AlertSlice) error {

// List returns a slice of Alerts currently held in memory.
func (a *Alerts) List() []*types.Alert {
a.Lock()
defer a.Unlock()
a.RLock()
defer a.RUnlock()

alerts := make([]*types.Alert, 0, len(a.c))
for _, alert := range a.c {
Expand All @@ -145,16 +145,16 @@ func (a *Alerts) List() []*types.Alert {

// Empty returns true if the store is empty.
func (a *Alerts) Empty() bool {
a.Lock()
defer a.Unlock()
a.RLock()
defer a.RUnlock()

return len(a.c) == 0
}

// Len returns the number of alerts in the store.
func (a *Alerts) Len() int {
a.Lock()
defer a.Unlock()
a.RLock()
defer a.RUnlock()

return len(a.c)
}
2 changes: 1 addition & 1 deletion store/store_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Prometheus Team
// Copyright Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down