Skip to content

Commit

Permalink
at least move uniqueStrings to function
Browse files Browse the repository at this point in the history
  • Loading branch information
fourstepper committed Dec 27, 2024
1 parent f7c8cdc commit b26a8d6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/helpers/prometheus_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"regexp"
"slices"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -110,6 +109,19 @@ func mergeLabels(ms ...map[string]string) map[string]string {
return labels
}

func uniqueStrings(input []string) []string {
seen := make(map[string]bool)
result := []string{}

for _, v := range input {
if !seen[v] {
seen[v] = true
result = append(result, v)
}
}
return result
}

func (mrs *MonitoringRuleSet) createBaseRuleLabels(window string) map[string]string {
return map[string]string{
"namespace": mrs.Slo.Namespace,
Expand Down Expand Up @@ -262,7 +274,7 @@ func (mrs *MonitoringRuleSet) SetupRules() ([]monitoringv1.RuleGroup, error) {
}

windows := []string{baseWindow, extendedWindow, "5m", "30m", "1h", "2h", "6h", "24h", "3d"}
windows = slices.Compact(windows)
windows = uniqueStrings(windows)

var alertRuleErrorBudgets []monitoringv1.Rule

Expand Down

0 comments on commit b26a8d6

Please sign in to comment.