mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
b2d5b920f5
commit
20bfe443fe
@ -84,8 +84,10 @@ func formatLegend(metric pmodel.Metric, query *PrometheusQuery) string {
|
|||||||
reg, _ := regexp.Compile(`\{\{\s*(.+?)\s*\}\}`)
|
reg, _ := regexp.Compile(`\{\{\s*(.+?)\s*\}\}`)
|
||||||
|
|
||||||
result := reg.ReplaceAllFunc([]byte(query.LegendFormat), func(in []byte) []byte {
|
result := reg.ReplaceAllFunc([]byte(query.LegendFormat), func(in []byte) []byte {
|
||||||
ind := strings.Replace(strings.Replace(string(in), "{{", "", 1), "}}", "", 1)
|
labelName := strings.Replace(string(in), "{{", "", 1)
|
||||||
if val, exists := metric[pmodel.LabelName(ind)]; exists {
|
labelName = strings.Replace(labelName, "}}", "", 1)
|
||||||
|
labelName = strings.TrimSpace(labelName)
|
||||||
|
if val, exists := metric[pmodel.LabelName(labelName)]; exists {
|
||||||
return []byte(val)
|
return []byte(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ func TestPrometheus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query := &PrometheusQuery{
|
query := &PrometheusQuery{
|
||||||
LegendFormat: "legend {{app}} {{device}} {{broken}}",
|
LegendFormat: "legend {{app}} {{ device }} {{broken}}",
|
||||||
}
|
}
|
||||||
|
|
||||||
So(formatLegend(metric, query), ShouldEqual, "legend backend mobile {{broken}}")
|
So(formatLegend(metric, query), ShouldEqual, "legend backend mobile {{broken}}")
|
||||||
|
Loading…
Reference in New Issue
Block a user