mirror of
https://github.com/grafana/grafana.git
synced 2025-01-16 11:42:35 -06:00
Alerting: Fix mathexp.NoData cannot be reduced (#55347)
This commit fixes a bug where queries from datasources such as InfluxDB that returned no data would not create a DatasourceNoData alert, but instead an error "can only reduce type series, got type noData".
This commit is contained in:
parent
28ebdf1641
commit
7d20766ae9
@ -171,6 +171,8 @@ func (gr *ReduceCommand) Execute(_ context.Context, vars mathexp.Vars) (mathexp.
|
|||||||
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
|
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
|
||||||
})
|
})
|
||||||
newRes.Values = append(newRes.Values, copyV)
|
newRes.Values = append(newRes.Values, copyV)
|
||||||
|
case mathexp.NoData:
|
||||||
|
newRes.Values = append(newRes.Values, v.New())
|
||||||
default:
|
default:
|
||||||
return newRes, fmt.Errorf("can only reduce type series, got type %v", val.Type())
|
return newRes, fmt.Errorf("can only reduce type series, got type %v", val.Type())
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
ptr "github.com/xorcare/pointer"
|
ptr "github.com/xorcare/pointer"
|
||||||
|
|
||||||
@ -136,6 +137,32 @@ func TestReduceExecute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should return new NoData", func(t *testing.T) {
|
||||||
|
var noData mathexp.Values = []mathexp.Value{
|
||||||
|
mathexp.NoData{Frame: data.NewFrame("no data")},
|
||||||
|
}
|
||||||
|
|
||||||
|
vars := map[string]mathexp.Results{
|
||||||
|
varToReduce: {
|
||||||
|
Values: noData,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
results, err := cmd.Execute(context.Background(), vars)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Len(t, results.Values, 1)
|
||||||
|
|
||||||
|
v := results.Values[0]
|
||||||
|
assert.Equal(t, v, mathexp.NoData{}.New())
|
||||||
|
|
||||||
|
// should not be able to change the original frame
|
||||||
|
v.AsDataFrame().Name = "there is still no data"
|
||||||
|
assert.NotEqual(t, v, mathexp.NoData{}.New())
|
||||||
|
assert.NotEqual(t, v, noData[0])
|
||||||
|
assert.Equal(t, "no data", noData[0].AsDataFrame().Name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomReduceFunc() string {
|
func randomReduceFunc() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user