mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SSE: Reduce to add warning notice to only the first result (#74940)
This commit is contained in:
parent
9328fda8ea
commit
40c12c17bf
@ -166,7 +166,7 @@ func (gr *ReduceCommand) Execute(ctx context.Context, _ time.Time, vars mathexp.
|
||||
span.SetAttributes("reducer", gr.Reducer, attribute.Key("reducer").String(gr.Reducer))
|
||||
|
||||
newRes := mathexp.Results{}
|
||||
for _, val := range vars[gr.VarToReduce].Values {
|
||||
for i, val := range vars[gr.VarToReduce].Values {
|
||||
switch v := val.(type) {
|
||||
case mathexp.Series:
|
||||
num, err := v.Reduce(gr.refID, gr.Reducer, gr.seriesMapper)
|
||||
@ -184,7 +184,7 @@ func (gr *ReduceCommand) Execute(ctx context.Context, _ time.Time, vars mathexp.
|
||||
}
|
||||
copyV := mathexp.NewNumber(gr.refID, v.GetLabels())
|
||||
copyV.SetValue(value)
|
||||
if gr.seriesMapper == nil {
|
||||
if gr.seriesMapper == nil && i == 0 { // Add notice to only the first result to not multiple them in presentation
|
||||
copyV.AddNotice(data.Notice{
|
||||
Severity: data.NoticeSeverityWarning,
|
||||
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
|
||||
|
@ -133,12 +133,12 @@ func TestReduceExecute(t *testing.T) {
|
||||
require.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
t.Run("should add warn notices to every frame", func(t *testing.T) {
|
||||
t.Run("should add warn notices to the first frame", func(t *testing.T) {
|
||||
frames := execute.Values.AsDataFrames("test")
|
||||
for _, frame := range frames {
|
||||
require.Len(t, frame.Meta.Notices, 1)
|
||||
notice := frame.Meta.Notices[0]
|
||||
require.Equal(t, data.NoticeSeverityWarning, notice.Severity)
|
||||
notice := frames[0].Meta.Notices[0]
|
||||
require.Equal(t, data.NoticeSeverityWarning, notice.Severity)
|
||||
for _, frame := range frames[1:] {
|
||||
require.Empty(t, frame.Meta.Notices)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user