-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display muted alerts on Grafana (#32)
* chore: moved filter string generation to function to reuse * feat: refactor + display muted alerts on Grafana * chore: fixed Grafana template * chore: fixed Grafana template, v2 * chore: fixed Grafana alerts querying
- Loading branch information
1 parent
cf3ea27
commit 6d64e92
Showing
8 changed files
with
113 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"main/pkg/utils/generic" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type SilenceManager interface { | ||
GetSilences() (Silences, error) | ||
GetSilenceMatchingAlerts(silence Silence) ([]AlertmanagerAlert, error) | ||
} | ||
|
||
func GetSilencesWithAlerts(manager SilenceManager) ([]SilenceWithAlerts, error) { | ||
silences, err := manager.GetSilences() | ||
if err != nil { | ||
return []SilenceWithAlerts{}, err | ||
} | ||
|
||
silences = generic.Filter(silences, func(s Silence) bool { | ||
return s.EndsAt.After(time.Now()) | ||
}) | ||
|
||
silencesWithAlerts := make([]SilenceWithAlerts, len(silences)) | ||
|
||
var wg sync.WaitGroup | ||
var mutex sync.Mutex | ||
var errs []error | ||
|
||
for index, silence := range silences { | ||
wg.Add(1) | ||
go func(index int, silence Silence) { | ||
defer wg.Done() | ||
|
||
alerts, alertsErr := manager.GetSilenceMatchingAlerts(silence) | ||
if alertsErr != nil { | ||
mutex.Lock() | ||
errs = append(errs, alertsErr) | ||
mutex.Unlock() | ||
return | ||
} | ||
|
||
mutex.Lock() | ||
silencesWithAlerts[index] = SilenceWithAlerts{ | ||
Silence: silence, | ||
AlertsPresent: true, | ||
Alerts: alerts, | ||
} | ||
mutex.Unlock() | ||
}(index, silence) | ||
} | ||
|
||
wg.Wait() | ||
|
||
if len(errs) > 0 { | ||
return []SilenceWithAlerts{}, fmt.Errorf("Error getting alerts for silence on %d silences!", len(errs)) | ||
} | ||
|
||
return silencesWithAlerts, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters