Plugins: Auto instrumentation improvements (#94193)
This commit is contained in:
@@ -38,6 +38,16 @@ const (
|
||||
ErrorTypeServerPanic ErrorType = "server_panic"
|
||||
)
|
||||
|
||||
// ErrorSource defines model for TestDataQuery.ErrorSource.
|
||||
// +enum
|
||||
type ErrorSource string
|
||||
|
||||
// Defines values for ErrorSource.
|
||||
const (
|
||||
ErrorSourcePlugin ErrorSource = "plugin"
|
||||
ErrorSourceDownstream ErrorSource = "downstream"
|
||||
)
|
||||
|
||||
// TestDataQueryType defines model for TestDataQueryType.
|
||||
// +enum
|
||||
type TestDataQueryType string
|
||||
@@ -50,6 +60,7 @@ const (
|
||||
TestDataQueryTypeCsvFile TestDataQueryType = "csv_file"
|
||||
TestDataQueryTypeCsvMetricValues TestDataQueryType = "csv_metric_values"
|
||||
TestDataQueryTypeDatapointsOutsideRange TestDataQueryType = "datapoints_outside_range"
|
||||
TestDataQueryTypeErrorWithSource TestDataQueryType = "error_with_source"
|
||||
TestDataQueryTypeExponentialHeatmapBucketData TestDataQueryType = "exponential_heatmap_bucket_data"
|
||||
TestDataQueryTypeFlameGraph TestDataQueryType = "flame_graph"
|
||||
TestDataQueryTypeGrafanaApi TestDataQueryType = "grafana_api"
|
||||
@@ -92,21 +103,22 @@ type TestDataQuery struct {
|
||||
Channel string `json:"channel,omitempty"`
|
||||
|
||||
// Drop percentage (the chance we will lose a point 0-100)
|
||||
DropPercent float64 `json:"dropPercent,omitempty"`
|
||||
ErrorType ErrorType `json:"errorType,omitempty"`
|
||||
FlamegraphDiff bool `json:"flamegraphDiff,omitempty"`
|
||||
LevelColumn bool `json:"levelColumn,omitempty"`
|
||||
StartValue float64 `json:"startValue,omitempty"`
|
||||
Spread float64 `json:"spread,omitempty"`
|
||||
Noise float64 `json:"noise,omitempty"`
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
WithNil bool `json:"withNil,omitempty"`
|
||||
Lines int64 `json:"lines,omitempty"`
|
||||
Points [][]any `json:"points,omitempty"`
|
||||
RawFrameContent string `json:"rawFrameContent,omitempty"`
|
||||
SeriesCount int `json:"seriesCount,omitempty"`
|
||||
SpanCount int `json:"spanCount,omitempty"`
|
||||
DropPercent float64 `json:"dropPercent,omitempty"`
|
||||
ErrorType ErrorType `json:"errorType,omitempty"`
|
||||
FlamegraphDiff bool `json:"flamegraphDiff,omitempty"`
|
||||
LevelColumn bool `json:"levelColumn,omitempty"`
|
||||
StartValue float64 `json:"startValue,omitempty"`
|
||||
Spread float64 `json:"spread,omitempty"`
|
||||
Noise float64 `json:"noise,omitempty"`
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
WithNil bool `json:"withNil,omitempty"`
|
||||
Lines int64 `json:"lines,omitempty"`
|
||||
Points [][]any `json:"points,omitempty"`
|
||||
RawFrameContent string `json:"rawFrameContent,omitempty"`
|
||||
SeriesCount int `json:"seriesCount,omitempty"`
|
||||
SpanCount int `json:"spanCount,omitempty"`
|
||||
ErrorSource ErrorSource `json:"errorSource,omitempty"`
|
||||
|
||||
Nodes *NodesQuery `json:"nodes,omitempty"`
|
||||
PulseWave *PulseWaveQuery `json:"pulseWave,omitempty"`
|
||||
|
||||
@@ -73,6 +73,15 @@
|
||||
"description": "Drop percentage (the chance we will lose a point 0-100)",
|
||||
"type": "number"
|
||||
},
|
||||
"errorSource": {
|
||||
"description": "Possible enum values:\n - `\"plugin\"` \n - `\"downstream\"` ",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"plugin",
|
||||
"downstream"
|
||||
],
|
||||
"x-enum-description": {}
|
||||
},
|
||||
"errorType": {
|
||||
"description": "Possible enum values:\n - `\"frontend_exception\"` \n - `\"frontend_observable\"` \n - `\"server_panic\"` ",
|
||||
"type": "string",
|
||||
@@ -220,7 +229,7 @@
|
||||
"additionalProperties": false
|
||||
},
|
||||
"scenarioId": {
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"error_with_source\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"annotations",
|
||||
@@ -229,6 +238,7 @@
|
||||
"csv_file",
|
||||
"csv_metric_values",
|
||||
"datapoints_outside_range",
|
||||
"error_with_source",
|
||||
"exponential_heatmap_bucket_data",
|
||||
"flame_graph",
|
||||
"grafana_api",
|
||||
|
||||
@@ -83,6 +83,15 @@
|
||||
"description": "Drop percentage (the chance we will lose a point 0-100)",
|
||||
"type": "number"
|
||||
},
|
||||
"errorSource": {
|
||||
"description": "Possible enum values:\n - `\"plugin\"` \n - `\"downstream\"` ",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"plugin",
|
||||
"downstream"
|
||||
],
|
||||
"x-enum-description": {}
|
||||
},
|
||||
"errorType": {
|
||||
"description": "Possible enum values:\n - `\"frontend_exception\"` \n - `\"frontend_observable\"` \n - `\"server_panic\"` ",
|
||||
"type": "string",
|
||||
@@ -230,7 +239,7 @@
|
||||
"additionalProperties": false
|
||||
},
|
||||
"scenarioId": {
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"error_with_source\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"annotations",
|
||||
@@ -239,6 +248,7 @@
|
||||
"csv_file",
|
||||
"csv_metric_values",
|
||||
"datapoints_outside_range",
|
||||
"error_with_source",
|
||||
"exponential_heatmap_bucket_data",
|
||||
"flame_graph",
|
||||
"grafana_api",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "default",
|
||||
"resourceVersion": "1711119846950",
|
||||
"resourceVersion": "1728405292506",
|
||||
"creationTimestamp": "2024-03-01T02:53:35Z"
|
||||
},
|
||||
"spec": {
|
||||
@@ -56,6 +56,15 @@
|
||||
"description": "Drop percentage (the chance we will lose a point 0-100)",
|
||||
"type": "number"
|
||||
},
|
||||
"errorSource": {
|
||||
"description": "Possible enum values:\n - `\"plugin\"` \n - `\"downstream\"` ",
|
||||
"enum": [
|
||||
"plugin",
|
||||
"downstream"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-description": {}
|
||||
},
|
||||
"errorType": {
|
||||
"description": "Possible enum values:\n - `\"frontend_exception\"` \n - `\"frontend_observable\"` \n - `\"server_panic\"` ",
|
||||
"enum": [
|
||||
@@ -142,7 +151,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"scenarioId": {
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"description": "Possible enum values:\n - `\"annotations\"` \n - `\"arrow\"` \n - `\"csv_content\"` \n - `\"csv_file\"` \n - `\"csv_metric_values\"` \n - `\"datapoints_outside_range\"` \n - `\"error_with_source\"` \n - `\"exponential_heatmap_bucket_data\"` \n - `\"flame_graph\"` \n - `\"grafana_api\"` \n - `\"linear_heatmap_bucket_data\"` \n - `\"live\"` \n - `\"logs\"` \n - `\"manual_entry\"` \n - `\"no_data_points\"` \n - `\"node_graph\"` \n - `\"predictable_csv_wave\"` \n - `\"predictable_pulse\"` \n - `\"random_walk\"` \n - `\"random_walk_table\"` \n - `\"random_walk_with_error\"` \n - `\"raw_frame\"` \n - `\"server_error_500\"` \n - `\"simulation\"` \n - `\"slow_query\"` \n - `\"streaming_client\"` \n - `\"table_static\"` \n - `\"trace\"` \n - `\"usa\"` \n - `\"variables-query\"` ",
|
||||
"enum": [
|
||||
"annotations",
|
||||
"arrow",
|
||||
@@ -150,6 +159,7 @@
|
||||
"csv_file",
|
||||
"csv_metric_values",
|
||||
"datapoints_outside_range",
|
||||
"error_with_source",
|
||||
"exponential_heatmap_bucket_data",
|
||||
"flame_graph",
|
||||
"grafana_api",
|
||||
|
||||
@@ -21,6 +21,7 @@ func TestQueryTypeDefinitions(t *testing.T) {
|
||||
reflect.TypeOf(NodesQueryTypeRandom), // pick an example value (not the root)
|
||||
reflect.TypeOf(StreamingQueryTypeFetch), // pick an example value (not the root)
|
||||
reflect.TypeOf(ErrorTypeServerPanic), // pick an example value (not the root)
|
||||
reflect.TypeOf(ErrorSourcePlugin), // pick an example value (not the root)
|
||||
reflect.TypeOf(TestDataQueryTypeAnnotations), // pick an example value (not the root)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
@@ -198,6 +199,12 @@ Timestamps will line up evenly on timeStepSeconds (For example, 60 seconds means
|
||||
Name: "Trace",
|
||||
})
|
||||
|
||||
s.registerScenario(&Scenario{
|
||||
ID: kinds.TestDataQueryTypeErrorWithSource,
|
||||
Name: "Error with source",
|
||||
handler: s.handleErrorWithSourceScenario,
|
||||
})
|
||||
|
||||
s.queryMux.HandleFunc("", s.handleFallbackScenario)
|
||||
}
|
||||
|
||||
@@ -663,6 +670,29 @@ func (s *Service) handleLogsScenario(ctx context.Context, req *backend.QueryData
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) handleErrorWithSourceScenario(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
anErr := errors.New("error")
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := GetJSONModel(q.JSON)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
respD := resp.Responses[q.RefID]
|
||||
respD.Error = anErr
|
||||
|
||||
if model.ErrorSource == kinds.ErrorSourceDownstream {
|
||||
respD.Error = backend.DownstreamError(respD.Error)
|
||||
}
|
||||
|
||||
resp.Responses[q.RefID] = respD
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func RandomWalk(query backend.DataQuery, model kinds.TestDataQuery, index int) *data.Frame {
|
||||
rand := rand.New(rand.NewSource(time.Now().UnixNano() + int64(index)))
|
||||
timeWalkerMs := query.TimeRange.From.UnixNano() / int64(time.Millisecond)
|
||||
|
||||
Reference in New Issue
Block a user