fix(backend): tweak auto grid selection

This commit is contained in:
Łukasz Mierzwa
2021-04-19 11:28:27 +01:00
committed by Łukasz Mierzwa
parent e7bf32ff1a
commit 7778e66b7b
2 changed files with 5 additions and 4 deletions

View File

@@ -266,9 +266,10 @@ func sortGrids(r *http.Request, gridLabel string, gridsMap map[string]models.API
}
func autoGridLabel(dedupedAlerts []models.AlertGroup) string {
var alertsCount int
var alertsCount, alertGroupsCount int
labelNameToValueCount := map[string]map[string]int{}
for _, ag := range dedupedAlerts {
alertGroupsCount++
alertsCount += ag.Alerts.Len()
for _, alert := range ag.Alerts {
for key, val := range alert.Labels {
@@ -282,7 +283,7 @@ func autoGridLabel(dedupedAlerts []models.AlertGroup) string {
}
}
}
log.Debug().Int("alerts", alertsCount).Msg("Alerts count for automatic grid label")
log.Debug().Int("alerts", alertsCount).Int("groups", alertGroupsCount).Msg("Alerts count for automatic grid label")
candidates := map[string]int{}
for key, vals := range labelNameToValueCount {
@@ -303,7 +304,7 @@ func autoGridLabel(dedupedAlerts []models.AlertGroup) string {
var lastCnt int
for key, uniqueValues := range candidates {
log.Debug().Int("variants", uniqueValues).Str("label", key).Msg("Automatic grid label candidate")
if uniqueValues == 1 || uniqueValues == alertsCount {
if uniqueValues == 1 || uniqueValues == alertsCount || uniqueValues == alertGroupsCount {
continue
}
if lastCnt == 0 || uniqueValues < lastCnt || (uniqueValues == lastCnt && key > lastLabel) {

View File

@@ -83,7 +83,7 @@ labels:
color: "#ff220c"
log:
config: false
level: warning
level: debug
sentry:
private: "https://84a9ef37a6ed4fdb80e9ea2310d1ed26:8c6ee6f0ab02406482ff4b4e824e2c27@o185090.ingest.sentry.io/1279017"
public: "https://84a9ef37a6ed4fdb80e9ea2310d1ed26@o185090.ingest.sentry.io/1279017"