mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Alerting: Copy frame field labels to time series tags (#29886)
* Alerting: Copy frame field labels to time series tags * keep comment * add test case
This commit is contained in:
parent
eee4f92435
commit
af47d28499
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user