fix(backend): run go fix ./...

This commit is contained in:
Lukasz Mierzwa
2026-02-26 09:46:44 +00:00
committed by Łukasz Mierzwa
parent d739ef1aac
commit 6d1efa9b71
8 changed files with 20 additions and 48 deletions
+4 -10
View File
@@ -121,11 +121,8 @@ func (acl *silenceACL) isAllowed(amName string, silence *models.Silence, groups
}
amMatch := len(acl.Scope.Alertmanagers) == 0
for _, aclAM := range acl.Scope.Alertmanagers {
if amName == aclAM {
amMatch = true
break
}
if slices.Contains(acl.Scope.Alertmanagers, amName) {
amMatch = true
}
filterMatch := true
@@ -144,11 +141,8 @@ func (acl *silenceACL) isAllowed(amName string, silence *models.Silence, groups
case aclActionRequireMatcher:
for _, aclM := range acl.Matchers.Required {
var wasFound bool
for _, m := range silence.Matchers {
if aclM.isMatch(m) {
wasFound = true
break
}
if slices.ContainsFunc(silence.Matchers, aclM.isMatch) {
wasFound = true
}
if !wasFound {
return false, fmt.Errorf("silence blocked by ACL rule: %s", acl.Reason)
+3 -5
View File
@@ -81,7 +81,7 @@ func alertHistory(historyPoller *historyPoller, w http.ResponseWriter, r *http.R
Samples: make([]OffsetSample, 24),
}
ts := time.Now().Add(time.Hour)
for i := 0; i < 24; i++ {
for i := range 24 {
ts = ts.Add(time.Hour * -1)
resp.Samples[i].Timestamp = ts
}
@@ -148,11 +148,9 @@ func (hp *historyPoller) run(workers int) {
hp.isRunning.Store(true)
wg := sync.WaitGroup{}
for w := 1; w <= workers; w++ {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
hp.startWorker(w)
}()
})
}
wg.Wait()
}
+3 -6
View File
@@ -2,6 +2,7 @@ package main
import (
"fmt"
"maps"
"math"
"slices"
"sort"
@@ -103,12 +104,8 @@ func getUpstreams() models.AlertmanagerAPISummary {
ClusterMembers: members,
}
if !upstream.ProxyRequests {
for k, v := range uri.HeadersForBasicAuth(upstream.URI) {
u.Headers[k] = v
}
for k, v := range upstream.HTTPHeaders {
u.Headers[k] = v
}
maps.Copy(u.Headers, uri.HeadersForBasicAuth(upstream.URI))
maps.Copy(u.Headers, upstream.HTTPHeaders)
}
summary.Instances = append(summary.Instances, u)
+1 -1
View File
@@ -27,7 +27,7 @@ func groupsFromHeaders(r *http.Request, groupName, groupValueRegex, groupValueSe
groupRegex := regex.MustCompileAnchored(groupValueRegex)
rawGroups := groupRegex.FindAllStringSubmatch(r.Header.Get(groupName), 1)
if len(rawGroups) > 0 && len(rawGroups[0]) > 1 {
for _, group := range strings.Split(rawGroups[0][1], groupValueSeparator) {
for group := range strings.SplitSeq(rawGroups[0][1], groupValueSeparator) {
if v := strings.TrimSpace(group); v != "" {
groups = append(groups, v)
}
+2 -5
View File
@@ -469,7 +469,7 @@ func alerts(w http.ResponseWriter, r *http.Request) {
}
sortedGrids := sortGrids(request, gridLabel, grids, request.GridSortReverse)
for i := 0; i < len(sortedGrids); i++ {
for i := range sortedGrids {
sortedGrids[i].TotalGroups = len(sortedGrids[i].AlertGroups)
limit, found := request.GridLimits[sortedGrids[i].LabelValue]
@@ -477,10 +477,7 @@ func alerts(w http.ResponseWriter, r *http.Request) {
limit = config.Config.Grid.GroupLimit
}
l := sortedGrids[i].TotalGroups
if limit < l {
l = limit
}
l := min(limit, sortedGrids[i].TotalGroups)
if l < 1 {
l = 1
}
+3 -6
View File
@@ -2,6 +2,7 @@ package alertmanager
import (
"fmt"
"maps"
"net/http"
"net/url"
"sort"
@@ -405,9 +406,7 @@ func (am *Alertmanager) Silences() map[string]models.Silence {
defer am.lock.RUnlock()
silences := make(map[string]models.Silence, len(am.silences))
for id, silence := range am.silences {
silences[id] = silence
}
maps.Copy(silences, am.silences)
return silences
}
@@ -447,9 +446,7 @@ func (am *Alertmanager) Colors() models.LabelsColorMap {
colors := make(models.LabelsColorMap, len(am.colors))
for k, v := range am.colors {
colors[k] = make(map[string]models.LabelColors, len(v))
for nk, nv := range v {
colors[k][nk] = nv
}
maps.Copy(colors[k], v)
}
return colors
}
+1 -1
View File
@@ -149,7 +149,7 @@ func TestBuildAutocomplete(t *testing.T) {
func BenchmarkAutocomplete(b *testing.B) {
const n = 10000
alerts := make([]models.Alert, 0, n)
for i := 0; i < n; i++ {
for i := range n {
alerts = append(alerts, models.Alert{
State: models.AlertStateActive,
Labels: models.Labels{
+3 -14
View File
@@ -4,6 +4,7 @@ import (
"crypto/sha1"
"encoding/hex"
"regexp"
"slices"
)
// StringSliceToSHA1 returns a SHA1 hash computed from a slice of strings
@@ -23,26 +24,14 @@ func StringSliceDiff(slice1, slice2 []string) ([]string, []string) {
var found bool
for _, s1 := range slice1 {
found = false
for _, s2 := range slice2 {
if s1 == s2 {
found = true
break
}
}
found = slices.Contains(slice2, s1)
if !found {
missing = append(missing, s1)
}
}
for _, s2 := range slice2 {
found = false
for _, s1 := range slice1 {
if s2 == s1 {
found = true
break
}
}
found = slices.Contains(slice1, s2)
if !found {
extra = append(extra, s2)
}