mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix and re-enable filters instance labels in log line
test (#65618)
Fix and reenable test
This commit is contained in:
parent
df946ca5eb
commit
5e87ea745d
pkg/services/ngalert/state/historian
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
@ -360,8 +361,14 @@ func buildLogQuery(query models.HistoryQuery) (string, error) {
|
||||
logQL := selectorString(selectors)
|
||||
|
||||
labelFilters := ""
|
||||
for k, v := range query.Labels {
|
||||
labelFilters += fmt.Sprintf(" | labels_%s=%q", k, v)
|
||||
labelKeys := make([]string, 0, len(query.Labels))
|
||||
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 != "" {
|
||||
|
@ -183,18 +183,17 @@ func TestRemoteLokiBackend(t *testing.T) {
|
||||
},
|
||||
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",
|
||||
// query: models.HistoryQuery{
|
||||
// OrgID: 123,
|
||||
// Labels: map[string]string{
|
||||
// "customlabel": "customvalue",
|
||||
// "labeltwo": "labelvaluetwo",
|
||||
// },
|
||||
// },
|
||||
// exp: `{orgID="123",from="state-history"} | json | labels_customlabel="customvalue" | labels_labeltwo="labelvaluetwo"`,
|
||||
//},
|
||||
{
|
||||
name: "filters instance labels in log line",
|
||||
query: models.HistoryQuery{
|
||||
OrgID: 123,
|
||||
Labels: map[string]string{
|
||||
"customlabel": "customvalue",
|
||||
"labeltwo": "labelvaluetwo",
|
||||
},
|
||||
},
|
||||
exp: `{orgID="123",from="state-history"} | json | labels_customlabel="customvalue" | labels_labeltwo="labelvaluetwo"`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user