Commit af47d284 by Will Browne Committed by GitHub

Alerting: Copy frame field labels to time series tags (#29886)

* Alerting: Copy frame field labels to time series tags

* keep comment

* add test case
parent eee4f924
......@@ -330,13 +330,16 @@ func FrameToSeriesSlice(frame *data.Frame) (tsdb.TimeSeriesSlice, error) {
Points: make(tsdb.TimeSeriesPoints, field.Len()),
}
if len(field.Labels) > 0 {
ts.Tags = field.Labels.Copy()
}
switch {
case field.Config != nil && field.Config.DisplayName != "":
ts.Name = field.Config.DisplayName
case field.Config != nil && field.Config.DisplayNameFromDS != "":
ts.Name = field.Config.DisplayNameFromDS
case len(field.Labels) > 0:
ts.Tags = field.Labels.Copy()
// Tags are appended to the name so they are eventually included in EvalMatch's Metric property
// for display in notifications.
ts.Name = fmt.Sprintf("%v {%v}", field.Name, field.Labels.String())
......
......@@ -324,7 +324,7 @@ func TestFrameToSeriesSlice(t *testing.T) {
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{
data.NewField(`Values`, data.Labels{"Rating": "10"}, []*int64{}).SetConfig(&data.FieldConfig{
DisplayNameFromDS: "sloth",
})),
......@@ -332,6 +332,7 @@ func TestFrameToSeriesSlice(t *testing.T) {
&tsdb.TimeSeries{
Name: "sloth",
Points: tsdb.TimeSeriesPoints{},
Tags: map[string]string{"Rating": "10"},
},
},
Err: require.NoError,
......
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