mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 00:37:04 -06:00
Chore: Fix Random Walk scenario for Grafana DS (#73889)
This commit is contained in:
parent
1a281ac49d
commit
aa0d4b3e45
@ -165,7 +165,11 @@ func (s *Service) doReadQuery(ctx context.Context, query backend.DataQuery) back
|
||||
func (s *Service) doRandomWalk(query backend.DataQuery) backend.DataResponse {
|
||||
response := backend.DataResponse{}
|
||||
|
||||
model := testdatasource.JSONModel{}
|
||||
model, err := testdatasource.GetJSONModel(json.RawMessage{})
|
||||
if err != nil {
|
||||
response.Error = err
|
||||
return response
|
||||
}
|
||||
response.Frames = data.Frames{testdatasource.RandomWalk(query, model, 0)}
|
||||
|
||||
return response
|
||||
|
@ -21,7 +21,7 @@ func (s *Service) handleCsvContentScenario(ctx context.Context, req *backend.Que
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse query json: %v", err)
|
||||
}
|
||||
@ -58,7 +58,7 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse query json %v", err)
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ type pulseWave struct {
|
||||
OffValue interface{} `json:"offValue"`
|
||||
}
|
||||
|
||||
func getModel(j json.RawMessage) (JSONModel, error) {
|
||||
func GetJSONModel(j json.RawMessage) (JSONModel, error) {
|
||||
model := JSONModel{
|
||||
// Default values
|
||||
ScenarioID: string(randomWalkQuery),
|
||||
@ -272,9 +272,11 @@ func getModel(j json.RawMessage) (JSONModel, error) {
|
||||
StartValue: rand.Float64() * 100,
|
||||
Spread: 1,
|
||||
}
|
||||
err := json.Unmarshal(j, &model)
|
||||
if err != nil {
|
||||
return JSONModel{}, err
|
||||
if len(j) > 0 {
|
||||
err := json.Unmarshal(j, &model)
|
||||
if err != nil {
|
||||
return JSONModel{}, err
|
||||
}
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
@ -284,7 +286,7 @@ func (s *Service) handleFallbackScenario(ctx context.Context, req *backend.Query
|
||||
scenarioQueries := map[string][]backend.DataQuery{}
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to unmarshal query model to JSON", "error", err)
|
||||
continue
|
||||
@ -327,7 +329,7 @@ func (s *Service) handleRandomWalkScenario(ctx context.Context, req *backend.Que
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -347,7 +349,7 @@ func (s *Service) handleDatapointsOutsideRangeScenario(ctx context.Context, req
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -371,7 +373,7 @@ func (s *Service) handleCSVMetricValuesScenario(ctx context.Context, req *backen
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -421,7 +423,7 @@ func (s *Service) handleRandomWalkWithErrorScenario(ctx context.Context, req *ba
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -439,7 +441,7 @@ func (s *Service) handleRandomWalkSlowScenario(ctx context.Context, req *backend
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -460,7 +462,7 @@ func (s *Service) handleRandomWalkTableScenario(ctx context.Context, req *backen
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -477,7 +479,7 @@ func (s *Service) handlePredictableCSVWaveScenario(ctx context.Context, req *bac
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -498,7 +500,7 @@ func (s *Service) handlePredictablePulseScenario(ctx context.Context, req *backe
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -517,7 +519,7 @@ func (s *Service) handlePredictablePulseScenario(ctx context.Context, req *backe
|
||||
|
||||
func (s *Service) handleServerError500Scenario(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -539,7 +541,7 @@ func (s *Service) handleArrowScenario(ctx context.Context, req *backend.QueryDat
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -625,7 +627,7 @@ func (s *Service) handleLogsScenario(ctx context.Context, req *backend.QueryData
|
||||
from := q.TimeRange.From.UnixNano() / int64(time.Millisecond)
|
||||
to := q.TimeRange.To.UnixNano() / int64(time.Millisecond)
|
||||
|
||||
model, err := getModel(q.JSON)
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user