Commit 3de091ed by Will Browne Committed by GitHub

Alerting: Use correct time series name override from frame fields (#29693)

* cater for empty labels and new DisplayNameFromDS field

* simplify

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* increase priority for ds display name

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 7974972d
...@@ -333,7 +333,9 @@ func FrameToSeriesSlice(frame *data.Frame) (tsdb.TimeSeriesSlice, error) { ...@@ -333,7 +333,9 @@ func FrameToSeriesSlice(frame *data.Frame) (tsdb.TimeSeriesSlice, error) {
switch { switch {
case field.Config != nil && field.Config.DisplayName != "": case field.Config != nil && field.Config.DisplayName != "":
ts.Name = field.Config.DisplayName ts.Name = field.Config.DisplayName
case field.Labels != nil: case field.Config != nil && field.Config.DisplayNameFromDS != "":
ts.Name = field.Config.DisplayNameFromDS
case len(field.Labels) > 0:
ts.Tags = field.Labels.Copy() ts.Tags = field.Labels.Copy()
// Tags are appended to the name so they are eventually included in EvalMatch's Metric property // Tags are appended to the name so they are eventually included in EvalMatch's Metric property
// for display in notifications. // for display in notifications.
......
...@@ -306,6 +306,53 @@ func TestFrameToSeriesSlice(t *testing.T) { ...@@ -306,6 +306,53 @@ func TestFrameToSeriesSlice(t *testing.T) {
}, },
Err: require.NoError, Err: require.NoError,
}, },
{
name: "empty labels",
frame: data.NewFrame("",
data.NewField("Time", data.Labels{}, []time.Time{}),
data.NewField(`Values`, data.Labels{}, []float64{})),
seriesSlice: tsdb.TimeSeriesSlice{
&tsdb.TimeSeries{
Name: "Values",
Points: tsdb.TimeSeriesPoints{},
},
},
Err: require.NoError,
},
{
name: "display name from data source",
frame: data.NewFrame("",
data.NewField("Time", data.Labels{}, []time.Time{}),
data.NewField(`Values`, data.Labels{}, []*int64{}).SetConfig(&data.FieldConfig{
DisplayNameFromDS: "sloth",
})),
seriesSlice: tsdb.TimeSeriesSlice{
&tsdb.TimeSeries{
Name: "sloth",
Points: tsdb.TimeSeriesPoints{},
},
},
Err: require.NoError,
},
{
name: "prefer display name over data source display name",
frame: data.NewFrame("",
data.NewField("Time", data.Labels{}, []time.Time{}),
data.NewField(`Values`, data.Labels{}, []*int64{}).SetConfig(&data.FieldConfig{
DisplayName: "sloth #1",
DisplayNameFromDS: "sloth #2",
})),
seriesSlice: tsdb.TimeSeriesSlice{
&tsdb.TimeSeries{
Name: "sloth #1",
Points: tsdb.TimeSeriesPoints{},
},
},
Err: require.NoError,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment