Alerting: Fix and re-enable `filters instance labels in log line` test (#65618)

Fix and reenable test
pull/65623/head
Alexander Weaver 2 years ago committed by GitHub
parent df946ca5eb
commit 5e87ea745d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      pkg/services/ngalert/state/historian/loki.go
  2. 23
      pkg/services/ngalert/state/historian/loki_test.go

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math" "math"
"sort"
"time" "time"
"github.com/benbjohnson/clock" "github.com/benbjohnson/clock"
@ -360,8 +361,14 @@ func buildLogQuery(query models.HistoryQuery) (string, error) {
logQL := selectorString(selectors) logQL := selectorString(selectors)
labelFilters := "" labelFilters := ""
for k, v := range query.Labels { labelKeys := make([]string, 0, len(query.Labels))
labelFilters += fmt.Sprintf(" | labels_%s=%q", k, v) for k := range query.Labels {
labelKeys = append(labelKeys, k)
}
// Ensure that all queries we build are deterministic.
sort.Strings(labelKeys)
for _, k := range labelKeys {
labelFilters += fmt.Sprintf(" | labels_%s=%q", k, query.Labels[k])
} }
if labelFilters != "" { if labelFilters != "" {

@ -183,18 +183,17 @@ func TestRemoteLokiBackend(t *testing.T) {
}, },
exp: `{orgID="123",from="state-history",ruleUID="rule-uid"}`, exp: `{orgID="123",from="state-history",ruleUID="rule-uid"}`,
}, },
// TODO this case is flaky - investigate and re-enable. ref: https://drone.grafana.net/grafana/grafana/108325/3/7 {
//{ name: "filters instance labels in log line",
// name: "filters instance labels in log line", query: models.HistoryQuery{
// query: models.HistoryQuery{ OrgID: 123,
// OrgID: 123, Labels: map[string]string{
// Labels: map[string]string{ "customlabel": "customvalue",
// "customlabel": "customvalue", "labeltwo": "labelvaluetwo",
// "labeltwo": "labelvaluetwo", },
// }, },
// }, exp: `{orgID="123",from="state-history"} | json | labels_customlabel="customvalue" | labels_labeltwo="labelvaluetwo"`,
// exp: `{orgID="123",from="state-history"} | json | labels_customlabel="customvalue" | labels_labeltwo="labelvaluetwo"`, },
//},
} }
for _, tc := range cases { for _, tc := range cases {

Loading…
Cancel
Save