Skip to content

Commit

Permalink
Merge pull request #17 from perses/nexucis/fix-grafana
Browse files Browse the repository at this point in the history
support all global variable and variable syntaxes in grafana collector
  • Loading branch information
Nexucis authored Nov 6, 2024
2 parents a5dc19b + 389272f commit 8ce3afb
Show file tree
Hide file tree
Showing 8 changed files with 1,425 additions and 109 deletions.
29 changes: 4 additions & 25 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/perses/metrics-usage/config"
v1 "github.com/perses/metrics-usage/pkg/api/v1"
"github.com/perses/metrics-usage/utils"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -176,30 +177,8 @@ func mergeUsage(old, new *v1.MetricUsage) *v1.MetricUsage {
return old
}
return &v1.MetricUsage{
Dashboards: mergeSlice(old.Dashboards, new.Dashboards),
RecordingRules: mergeSlice(old.RecordingRules, new.RecordingRules),
AlertRules: mergeSlice(old.AlertRules, new.AlertRules),
Dashboards: utils.Merge(old.Dashboards, new.Dashboards),
RecordingRules: utils.Merge(old.RecordingRules, new.RecordingRules),
AlertRules: utils.Merge(old.AlertRules, new.AlertRules),
}
}

func mergeSlice[T comparable](old, new []T) []T {
if len(old) == 0 {
return new
}
if len(new) == 0 {
return old
}
for _, a := range old {
found := false
for _, b := range new {
if a == b {
found = true
break
}
}
if !found {
new = append(new, a)
}
}
return new
}
Loading

0 comments on commit 8ce3afb

Please sign in to comment.