SSE: Fix DSNode to not panic when response has empty response (#74866)
This commit is contained in:
+5
-1
@@ -333,7 +333,11 @@ func (dn *DSNode) Execute(ctx context.Context, now time.Time, _ mathexp.Vars, s
|
||||
|
||||
if len(filtered) == 0 {
|
||||
responseType = "no data"
|
||||
return mathexp.Results{Values: mathexp.Values{mathexp.NoData{Frame: response.Frames[0]}}}, nil
|
||||
noData := mathexp.NewNoData()
|
||||
if len(response.Frames) > 0 {
|
||||
noData.Frame = response.Frames[0]
|
||||
}
|
||||
return mathexp.Results{Values: mathexp.Values{noData}}, nil
|
||||
}
|
||||
|
||||
maybeFixerFn := checkIfSeriesNeedToBeFixed(filtered, dataSource)
|
||||
|
||||
+14
-1
@@ -180,6 +180,7 @@ func TestCheckIfSeriesNeedToBeFixed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConvertDataFramesToResults(t *testing.T) {
|
||||
var features featuremgmt.FeatureToggles = &featuremgmt.FeatureManager{}
|
||||
execute := func(frames []*data.Frame, datasourceType string) (mathexp.Results, error) {
|
||||
dsNode := DSNode{
|
||||
baseNode: baseNode{
|
||||
@@ -195,7 +196,7 @@ func TestConvertDataFramesToResults(t *testing.T) {
|
||||
}
|
||||
s := &Service{
|
||||
cfg: setting.NewCfg(),
|
||||
features: &featuremgmt.FeatureManager{},
|
||||
features: features,
|
||||
tracer: tracing.InitializeTracerForTest(),
|
||||
metrics: newMetrics(nil),
|
||||
dataService: &mockEndpoint{
|
||||
@@ -206,6 +207,18 @@ func TestConvertDataFramesToResults(t *testing.T) {
|
||||
return dsNode.Execute(context.Background(), time.Now(), nil, s)
|
||||
}
|
||||
|
||||
t.Run("when it is not dataplane", func(t *testing.T) {
|
||||
f := features
|
||||
t.Cleanup(func() {
|
||||
features = f
|
||||
})
|
||||
features = featuremgmt.WithFeatures(featuremgmt.FlagDisableSSEDataplane)
|
||||
t.Run("should return NoData if no frames", func(t *testing.T) {
|
||||
result, err := execute(nil, "test")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, mathexp.NewNoData(), result.Values[0].Value())
|
||||
})
|
||||
})
|
||||
t.Run("should add name label if no labels and specific data source", func(t *testing.T) {
|
||||
supported := []string{datasources.DS_GRAPHITE, datasources.DS_TESTDATA}
|
||||
t.Run("when only field name is specified", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user