diff --git a/pkg/apis/query/v0alpha1/template/doc.go b/pkg/apis/query/v0alpha1/template/doc.go deleted file mode 100644 index 3585a3a5806..00000000000 --- a/pkg/apis/query/v0alpha1/template/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// +k8s:deepcopy-gen=package -// +k8s:openapi-gen=true -// +k8s:defaulter-gen=TypeMeta -// +groupName=query.grafana.app - -package template // import "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template" diff --git a/pkg/apis/query/v0alpha1/template/format.go b/pkg/apis/query/v0alpha1/template/format.go deleted file mode 100644 index 353a49ef2d3..00000000000 --- a/pkg/apis/query/v0alpha1/template/format.go +++ /dev/null @@ -1,68 +0,0 @@ -package template - -import ( - "bytes" - "encoding/csv" - "encoding/json" - "strings" -) - -func FormatVariables(fmt VariableFormat, input []string) string { - if len(input) < 1 { - return "" - } - - // MultiValued formats - // nolint: exhaustive - switch fmt { - case FormatJSON: - v, _ := json.Marshal(input) - return string(v) - - case FormatDoubleQuote: - sb := bytes.NewBufferString("") - for idx, val := range input { - if idx > 0 { - _, _ = sb.WriteRune(',') - } - _, _ = sb.WriteRune('"') - _, _ = sb.WriteString(strings.ReplaceAll(val, `"`, `\"`)) - _, _ = sb.WriteRune('"') - } - return sb.String() - - case FormatSingleQuote: - sb := bytes.NewBufferString("") - for idx, val := range input { - if idx > 0 { - _, _ = sb.WriteRune(',') - } - _, _ = sb.WriteRune('\'') - _, _ = sb.WriteString(strings.ReplaceAll(val, `'`, `\'`)) - _, _ = sb.WriteRune('\'') - } - return sb.String() - - case FormatCSV: - sb := bytes.NewBufferString("") - w := csv.NewWriter(sb) - _ = w.Write(input) - w.Flush() - v := sb.Bytes() - return string(v[:len(v)-1]) - } - - // Single valued formats - if len(input) == 1 { - return input[0] - } - - // nolint: exhaustive - switch fmt { - case FormatPipe: - return strings.Join(input, "|") - } - - // Raw output (joined with a comma) - return strings.Join(input, ",") -} diff --git a/pkg/apis/query/v0alpha1/template/format_test.go b/pkg/apis/query/v0alpha1/template/format_test.go deleted file mode 100644 index ace0a499efe..00000000000 --- a/pkg/apis/query/v0alpha1/template/format_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package template - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestFormat(t *testing.T) { - // Invalid input - require.Equal(t, "", FormatVariables(FormatCSV, nil)) - require.Equal(t, "", FormatVariables(FormatCSV, []string{})) - - type check struct { - name string - input []string - output map[VariableFormat]string - } - - tests := []check{ - { - name: "three simple variables", - input: []string{"a", "b", "c"}, - output: map[VariableFormat]string{ - FormatCSV: "a,b,c", - FormatJSON: `["a","b","c"]`, - FormatDoubleQuote: `"a","b","c"`, - FormatSingleQuote: `'a','b','c'`, - FormatPipe: `a|b|c`, - FormatRaw: "a,b,c", - }, - }, - { - name: "single value", - input: []string{"a"}, - output: map[VariableFormat]string{ - FormatCSV: "a", - FormatJSON: `["a"]`, - FormatDoubleQuote: `"a"`, - FormatSingleQuote: `'a'`, - FormatPipe: "a", - FormatRaw: "a", - }, - }, - { - name: "value with quote", - input: []string{`hello "world"`}, - output: map[VariableFormat]string{ - FormatCSV: `"hello ""world"""`, // note the double quotes - FormatJSON: `["hello \"world\""]`, - FormatDoubleQuote: `"hello \"world\""`, - FormatSingleQuote: `'hello "world"'`, - FormatPipe: `hello "world"`, - FormatRaw: `hello "world"`, - }, - }, - } - for _, test := range tests { - // Make sure all keys are set in tests - all := map[VariableFormat]bool{ - FormatRaw: true, - FormatCSV: true, - FormatJSON: true, - FormatDoubleQuote: true, - FormatSingleQuote: true, - FormatPipe: true, - } - - // Check the default (no format) matches CSV - require.Equal(t, test.output[FormatRaw], - FormatVariables("", test.input), - "test %s default values are not raw", test.name) - - // Check each input value - for format, v := range test.output { - require.Equal(t, v, FormatVariables(format, test.input), "Test: %s (format:%s)", test.name, format) - delete(all, format) - } - require.Empty(t, all, "test %s is missing cases for: %v", test.name, all) - } -} diff --git a/pkg/apis/query/v0alpha1/template/render.go b/pkg/apis/query/v0alpha1/template/render.go deleted file mode 100644 index 372756139a3..00000000000 --- a/pkg/apis/query/v0alpha1/template/render.go +++ /dev/null @@ -1,119 +0,0 @@ -package template - -import ( - "fmt" - "sort" - - data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1" - "github.com/spyzhov/ajson" -) - -// RenderTemplate applies selected values into a query template -func RenderTemplate(qt QueryTemplate, selectedValues map[string][]string) ([]Target, error) { - targets := qt.DeepCopy().Targets - - rawTargetObjects := make([]*ajson.Node, len(qt.Targets)) - for i, t := range qt.Targets { - b, err := t.Properties.MarshalJSON() - if err != nil { - return nil, err - } - rawTargetObjects[i], err = ajson.Unmarshal(b) - if err != nil { - return nil, err - } - } - - rm := getReplacementMap(qt) - for targetIdx, byTargetIdx := range rm { - for path, reps := range byTargetIdx { - o := rawTargetObjects[targetIdx] - nodes, err := o.JSONPath(path) - if err != nil { - return nil, fmt.Errorf("failed to find path %v: %w", path, err) - } - if len(nodes) != 1 { - return nil, fmt.Errorf("expected one lead node at path %v but got %v", path, len(nodes)) - } - n := nodes[0] - if !n.IsString() { - return nil, fmt.Errorf("only string type leaf notes supported currently, %v is not a string", path) - } - s := []rune(n.String()) - s = s[1 : len(s)-1] - var offSet int64 - for _, r := range reps { - sV := selectedValues[r.Key] - if sV == nil { - sV = r.DefaultValues - } - value := []rune(FormatVariables(r.format, sV)) - if r.Position == nil { - return nil, fmt.Errorf("nil position not support yet, will be full replacement") - } - s = append(s[:r.Start+offSet], append(value, s[r.End+offSet:]...)...) - offSet += int64(len(value)) - (r.End - r.Start) - } - if err = n.SetString(string(s)); err != nil { - return nil, err - } - } - } - - for i, aT := range rawTargetObjects { - raw, err := ajson.Marshal(aT) - if err != nil { - return nil, err - } - u := data.DataQuery{} - err = u.UnmarshalJSON(raw) - if err != nil { - return nil, err - } - targets[i].Properties = u - } - - return targets, nil -} - -type replacement struct { - *Position - *TemplateVariable - format VariableFormat -} - -func getReplacementMap(qt QueryTemplate) map[int]map[string][]replacement { - byTargetPath := make(map[int]map[string][]replacement) - - varMap := make(map[string]*TemplateVariable, len(qt.Variables)) - for i, v := range qt.Variables { - varMap[v.Key] = &qt.Variables[i] - } - - for i, target := range qt.Targets { - if byTargetPath[i] == nil { - byTargetPath[i] = make(map[string][]replacement) - } - for k, vReps := range target.Variables { - for rI, rep := range vReps { - byTargetPath[i][rep.Path] = append(byTargetPath[i][rep.Path], - replacement{ - Position: vReps[rI].Position, - TemplateVariable: varMap[k], - format: rep.Format, - }, - ) - } - } - } - - for idx, byTargetIdx := range byTargetPath { - for path := range byTargetIdx { - sort.Slice(byTargetPath[idx][path], func(i, j int) bool { - return byTargetPath[idx][path][i].Start < byTargetPath[idx][path][j].Start - }) - } - } - - return byTargetPath -} diff --git a/pkg/apis/query/v0alpha1/template/render_test.go b/pkg/apis/query/v0alpha1/template/render_test.go deleted file mode 100644 index 0ac5ae144af..00000000000 --- a/pkg/apis/query/v0alpha1/template/render_test.go +++ /dev/null @@ -1,244 +0,0 @@ -package template - -import ( - "testing" - - "github.com/grafana/grafana-plugin-sdk-go/data" - apidata "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1" - "github.com/stretchr/testify/require" -) - -var nestedFieldRender = QueryTemplate{ - Title: "Test", - Variables: []TemplateVariable{ - { - Key: "metricName", - DefaultValues: []string{"cow_count"}, - }, - }, - Targets: []Target{ - { - DataType: data.FrameTypeUnknown, - //DataTypeVersion: data.FrameTypeVersion{0, 0}, - - Variables: map[string][]VariableReplacement{ - "metricName": { - { - Path: "$.nestedObject.anArray[0]", - Position: &Position{ - Start: 0, - End: 3, - }, - }, - }, - }, - Properties: apidata.NewDataQuery(map[string]any{ - "nestedObject": map[string]any{ - "anArray": []any{"foo", .2}, - }, - }), - }, - }, -} - -var nestedFieldRenderedTargets = []Target{ - { - DataType: data.FrameTypeUnknown, - Variables: map[string][]VariableReplacement{ - "metricName": { - { - Path: "$.nestedObject.anArray[0]", - Position: &Position{ - Start: 0, - End: 3, - }, - }, - }, - }, - //DataTypeVersion: data.FrameTypeVersion{0, 0}, - Properties: apidata.NewDataQuery( - map[string]any{ - "nestedObject": map[string]any{ - "anArray": []any{"up", .2}, - }, - }), - }, -} - -var nestedFieldDefaultRenderedTargets = []Target{ - { - DataType: data.FrameTypeUnknown, - Variables: map[string][]VariableReplacement{ - "metricName": { - { - Path: "$.nestedObject.anArray[0]", - Position: &Position{ - Start: 0, - End: 3, - }, - }, - }, - }, - //DataTypeVersion: data.FrameTypeVersion{0, 0}, - Properties: apidata.NewDataQuery( - map[string]any{ - "nestedObject": map[string]any{ - "anArray": []any{"cow_count", .2}, - }, - }), - }, -} - -func TestNestedFieldRender(t *testing.T) { - rT, err := RenderTemplate(nestedFieldRender, map[string][]string{"metricName": {"up"}}) - require.NoError(t, err) - require.Equal(t, - nestedFieldRenderedTargets, - rT, - ) -} - -func TestNestedFieldDefaultsRender(t *testing.T) { - rT, err := RenderTemplate(nestedFieldRender, nil) - require.NoError(t, err) - require.Equal(t, - nestedFieldDefaultRenderedTargets, - rT, - ) -} - -var multiVarTemplate = QueryTemplate{ - Title: "Test", - Variables: []TemplateVariable{ - { - Key: "metricName", - }, - { - Key: "anotherMetric", - }, - }, - Targets: []Target{ - { - DataType: data.FrameTypeUnknown, - //DataTypeVersion: data.FrameTypeVersion{0, 0}, - - Variables: map[string][]VariableReplacement{ - "metricName": { - { - Path: "$.expr", - Position: &Position{ - Start: 4, - End: 14, - }, - }, - { - Path: "$.expr", - Position: &Position{ - Start: 37, - End: 47, - }, - }, - }, - "anotherMetric": { - { - Path: "$.expr", - Position: &Position{ - Start: 21, - End: 34, - }, - }, - }, - }, - - Properties: apidata.NewDataQuery(map[string]any{ - "expr": "1 + metricName + 1 + anotherMetric + metricName", - }), - }, - }, -} - -var multiVarRenderedTargets = []Target{ - { - DataType: data.FrameTypeUnknown, - Variables: map[string][]VariableReplacement{ - "metricName": { - { - Path: "$.expr", - Position: &Position{ - Start: 4, - End: 14, - }, - }, - { - Path: "$.expr", - Position: &Position{ - Start: 37, - End: 47, - }, - }, - }, - "anotherMetric": { - { - Path: "$.expr", - Position: &Position{ - Start: 21, - End: 34, - }, - }, - }, - }, - //DataTypeVersion: data.FrameTypeVersion{0, 0}, - Properties: apidata.NewDataQuery(map[string]any{ - "expr": "1 + up + 1 + sloths_do_like_a_good_nap + up", - }), - }, -} - -func TestMultiVarTemplate(t *testing.T) { - rT, err := RenderTemplate(multiVarTemplate, map[string][]string{ - "metricName": {"up"}, - "anotherMetric": {"sloths_do_like_a_good_nap"}, - }) - require.NoError(t, err) - require.Equal(t, - multiVarRenderedTargets, - rT, - ) -} - -func TestRenderWithRune(t *testing.T) { - qt := QueryTemplate{ - Variables: []TemplateVariable{ - { - Key: "name", - }, - }, - Targets: []Target{ - { - Properties: apidata.NewDataQuery(map[string]any{ - "message": "🐦 name!", - }), - Variables: map[string][]VariableReplacement{ - "name": { - { - Path: "$.message", - Position: &Position{ - Start: 2, - End: 6, - }, - }, - }, - }, - }, - }, - } - - selectedValues := map[string][]string{ - "name": {"🦥"}, - } - - rq, err := RenderTemplate(qt, selectedValues) - require.NoError(t, err) - - require.Equal(t, "🐦 🦥!", rq[0].Properties.GetString("message")) -} diff --git a/pkg/apis/query/v0alpha1/template/types.go b/pkg/apis/query/v0alpha1/template/types.go deleted file mode 100644 index f99847107e9..00000000000 --- a/pkg/apis/query/v0alpha1/template/types.go +++ /dev/null @@ -1,123 +0,0 @@ -package template - -import ( - "github.com/grafana/grafana-plugin-sdk-go/data" - apidata "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1" - - common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" -) - -type QueryTemplate struct { - // A display name - Title string `json:"title,omitempty"` - - // Longer description for why it is interesting - Description string `json:"description,omitempty"` - - // Toggle for visible/hidden queries - IsVisible bool `json:"isVisible,omitempty"` - - // The tags that can be used to filter the template - // +listType=set - Tags []string `json:"tags,omitempty"` - - // Whether the query is locked and cannot be edited - // Note: This is purely for UI display purposes and not for security - IsLocked bool `json:"isLocked,omitempty"` - - // The variables that can be used to render - // +listType=map - // +listMapKey=key - Variables []TemplateVariable `json:"vars,omitempty"` - - // Output variables - // +listType=set - Targets []Target `json:"targets"` -} - -type Target struct { - // DataType is the returned Dataplane type from the query. - DataType data.FrameType `json:"dataType,omitempty"` - - // DataTypeVersion is the version for the Dataplane type. - // TODO 2[uint] seems to panic, maybe implement DeepCopy on data.FrameTypeVersion? - // DataTypeVersion data.FrameTypeVersion `json:"dataTypeVersion,omitempty"` - - // Variables that will be replaced in the query - Variables map[string][]VariableReplacement `json:"variables"` - - // Query target - Properties apidata.DataQuery `json:"properties"` -} - -// TemplateVariable is the definition of a variable that will be interpolated -// in targets. -type TemplateVariable struct { - // Key is the name of the variable. - Key string `json:"key"` - - // DefaultValue is the value to be used when there is no selected value - // during render. - // +listType=atomic - DefaultValues []string `json:"defaultValues,omitempty"` - - // ValueListDefinition is the object definition used by the FE - // to get a list of possible values to select for render. - ValueListDefinition common.Unstructured `json:"valueListDefinition,omitempty"` -} - -// QueryVariable is the definition of a variable that will be interpolated -// in targets. -type VariableReplacement struct { - // Path is the location of the property within a target. - // The format for this is not figured out yet (Maybe JSONPath?). - // Idea: ["string", int, "string"] where int indicates array offset - Path string `json:"path"` - - // Positions is a list of where to perform the interpolation - // within targets during render. - // The first string is the Idx of the target as a string, since openAPI - // does not support ints as map keys - Position *Position `json:"position,omitempty"` - - // How values should be interpolated - Format VariableFormat `json:"format,omitempty"` -} - -// Define how to format values in the template. -// See: https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#advanced-variable-format-options -// +enum -type VariableFormat string - -// Defines values for ItemType. -const ( - // Formats variables with multiple values as a comma-separated string. - FormatCSV VariableFormat = "csv" - - // Formats variables with multiple values as a comma-separated string. - FormatJSON VariableFormat = "json" - - // Formats single- and multi-valued variables into a comma-separated string - FormatDoubleQuote VariableFormat = "doublequote" - - // Formats single- and multi-valued variables into a comma-separated string - FormatSingleQuote VariableFormat = "singlequote" - - // Formats variables with multiple values into a pipe-separated string. - FormatPipe VariableFormat = "pipe" - - // Formats variables with multiple values into comma-separated string. - // This is the default behavior when no format is specified - FormatRaw VariableFormat = "raw" -) - -// Position is where to do replacement in the targets -// during render. -type Position struct { - // Start is the byte offset within TargetKey's property of the variable. - // It is the start location for replacements). - Start int64 `json:"start"` // TODO: byte, rune? - - // End is the byte offset of the end of the variable. - End int64 `json:"end"` -} diff --git a/pkg/apis/query/v0alpha1/template/zz_generated.deepcopy.go b/pkg/apis/query/v0alpha1/template/zz_generated.deepcopy.go deleted file mode 100644 index 0d97b4a439f..00000000000 --- a/pkg/apis/query/v0alpha1/template/zz_generated.deepcopy.go +++ /dev/null @@ -1,136 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package template - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Position) DeepCopyInto(out *Position) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Position. -func (in *Position) DeepCopy() *Position { - if in == nil { - return nil - } - out := new(Position) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *QueryTemplate) DeepCopyInto(out *QueryTemplate) { - *out = *in - if in.Tags != nil { - in, out := &in.Tags, &out.Tags - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = make([]TemplateVariable, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Targets != nil { - in, out := &in.Targets, &out.Targets - *out = make([]Target, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QueryTemplate. -func (in *QueryTemplate) DeepCopy() *QueryTemplate { - if in == nil { - return nil - } - out := new(QueryTemplate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Target) DeepCopyInto(out *Target) { - *out = *in - if in.Variables != nil { - in, out := &in.Variables, &out.Variables - *out = make(map[string][]VariableReplacement, len(*in)) - for key, val := range *in { - var outVal []VariableReplacement - if val == nil { - (*out)[key] = nil - } else { - in, out := &val, &outVal - *out = make([]VariableReplacement, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - (*out)[key] = outVal - } - } - in.Properties.DeepCopyInto(&out.Properties) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Target. -func (in *Target) DeepCopy() *Target { - if in == nil { - return nil - } - out := new(Target) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateVariable) DeepCopyInto(out *TemplateVariable) { - *out = *in - if in.DefaultValues != nil { - in, out := &in.DefaultValues, &out.DefaultValues - *out = make([]string, len(*in)) - copy(*out, *in) - } - in.ValueListDefinition.DeepCopyInto(&out.ValueListDefinition) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateVariable. -func (in *TemplateVariable) DeepCopy() *TemplateVariable { - if in == nil { - return nil - } - out := new(TemplateVariable) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *VariableReplacement) DeepCopyInto(out *VariableReplacement) { - *out = *in - if in.Position != nil { - in, out := &in.Position, &out.Position - *out = new(Position) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VariableReplacement. -func (in *VariableReplacement) DeepCopy() *VariableReplacement { - if in == nil { - return nil - } - out := new(VariableReplacement) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/query/v0alpha1/template/zz_generated.defaults.go b/pkg/apis/query/v0alpha1/template/zz_generated.defaults.go deleted file mode 100644 index f50cedd6396..00000000000 --- a/pkg/apis/query/v0alpha1/template/zz_generated.defaults.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// SPDX-License-Identifier: AGPL-3.0-only - -// Code generated by defaulter-gen. DO NOT EDIT. - -package template - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// RegisterDefaults adds defaulters functions to the given scheme. -// Public to allow building arbitrary schemes. -// All generated defaulters are covering - they call all nested defaulters. -func RegisterDefaults(scheme *runtime.Scheme) error { - return nil -} diff --git a/pkg/apis/query/v0alpha1/zz_generated.openapi.go b/pkg/apis/query/v0alpha1/zz_generated.openapi.go index 5f4a98317f1..b4089bd94f1 100644 --- a/pkg/apis/query/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/query/v0alpha1/zz_generated.openapi.go @@ -14,18 +14,12 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.DataSourceApiServer": schema_pkg_apis_query_v0alpha1_DataSourceApiServer(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.DataSourceApiServerList": schema_pkg_apis_query_v0alpha1_DataSourceApiServerList(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryDataRequest": schema_pkg_apis_query_v0alpha1_QueryDataRequest(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryDataResponse": schema_pkg_apis_query_v0alpha1_QueryDataResponse(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryTypeDefinition": schema_pkg_apis_query_v0alpha1_QueryTypeDefinition(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryTypeDefinitionList": schema_pkg_apis_query_v0alpha1_QueryTypeDefinitionList(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Position": schema_apis_query_v0alpha1_template_Position(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.QueryTemplate": schema_apis_query_v0alpha1_template_QueryTemplate(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Target": schema_apis_query_v0alpha1_template_Target(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.TemplateVariable": schema_apis_query_v0alpha1_template_TemplateVariable(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.VariableReplacement": schema_apis_query_v0alpha1_template_VariableReplacement(ref), - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.replacement": schema_apis_query_v0alpha1_template_replacement(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.DataSourceApiServer": schema_pkg_apis_query_v0alpha1_DataSourceApiServer(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.DataSourceApiServerList": schema_pkg_apis_query_v0alpha1_DataSourceApiServerList(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryDataRequest": schema_pkg_apis_query_v0alpha1_QueryDataRequest(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryDataResponse": schema_pkg_apis_query_v0alpha1_QueryDataResponse(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryTypeDefinition": schema_pkg_apis_query_v0alpha1_QueryTypeDefinition(ref), + "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryTypeDefinitionList": schema_pkg_apis_query_v0alpha1_QueryTypeDefinitionList(ref), } } @@ -351,309 +345,3 @@ func schema_pkg_apis_query_v0alpha1_QueryTypeDefinitionList(ref common.Reference "github.com/grafana/grafana/pkg/apis/query/v0alpha1.QueryTypeDefinition", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, } } - -func schema_apis_query_v0alpha1_template_Position(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Position is where to do replacement in the targets during render.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "start": { - SchemaProps: spec.SchemaProps{ - Description: "Start is the byte offset within TargetKey's property of the variable. It is the start location for replacements).", - Default: 0, - Type: []string{"integer"}, - Format: "int64", - }, - }, - "end": { - SchemaProps: spec.SchemaProps{ - Description: "End is the byte offset of the end of the variable.", - Default: 0, - Type: []string{"integer"}, - Format: "int64", - }, - }, - }, - Required: []string{"start", "end"}, - }, - }, - } -} - -func schema_apis_query_v0alpha1_template_QueryTemplate(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "title": { - SchemaProps: spec.SchemaProps{ - Description: "A display name", - Type: []string{"string"}, - Format: "", - }, - }, - "description": { - SchemaProps: spec.SchemaProps{ - Description: "Longer description for why it is interesting", - Type: []string{"string"}, - Format: "", - }, - }, - "isVisible": { - SchemaProps: spec.SchemaProps{ - Description: "Toggle for visible/hidden queries", - Type: []string{"boolean"}, - Format: "", - }, - }, - "tags": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "set", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "The tags that can be used to filter the template", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "isLocked": { - SchemaProps: spec.SchemaProps{ - Description: "Whether the query is locked and cannot be edited Note: This is purely for UI display purposes and not for security", - Type: []string{"boolean"}, - Format: "", - }, - }, - "vars": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-map-keys": []interface{}{ - "key", - }, - "x-kubernetes-list-type": "map", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "The variables that can be used to render", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.TemplateVariable"), - }, - }, - }, - }, - }, - "targets": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "set", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Output variables", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Target"), - }, - }, - }, - }, - }, - }, - Required: []string{"targets"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Target", "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.TemplateVariable"}, - } -} - -func schema_apis_query_v0alpha1_template_Target(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "dataType": { - SchemaProps: spec.SchemaProps{ - Description: "DataType is the returned Dataplane type from the query.", - Type: []string{"string"}, - Format: "", - }, - }, - "variables": { - SchemaProps: spec.SchemaProps{ - Description: "Variables that will be replaced in the query", - Type: []string{"object"}, - AdditionalProperties: &spec.SchemaOrBool{ - Allows: true, - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.VariableReplacement"), - }, - }, - }, - }, - }, - }, - }, - }, - "properties": { - SchemaProps: spec.SchemaProps{ - Description: "Query target", - Ref: ref("github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1.DataQuery"), - }, - }, - }, - Required: []string{"variables", "properties"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1.DataQuery", "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.VariableReplacement"}, - } -} - -func schema_apis_query_v0alpha1_template_TemplateVariable(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "TemplateVariable is the definition of a variable that will be interpolated in targets.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "key": { - SchemaProps: spec.SchemaProps{ - Description: "Key is the name of the variable.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "defaultValues": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "atomic", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "DefaultValue is the value to be used when there is no selected value during render.", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "valueListDefinition": { - SchemaProps: spec.SchemaProps{ - Description: "ValueListDefinition is the object definition used by the FE to get a list of possible values to select for render.", - Ref: ref("github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"), - }, - }, - }, - Required: []string{"key"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1.Unstructured"}, - } -} - -func schema_apis_query_v0alpha1_template_VariableReplacement(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "QueryVariable is the definition of a variable that will be interpolated in targets.", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "path": { - SchemaProps: spec.SchemaProps{ - Description: "Path is the location of the property within a target. The format for this is not figured out yet (Maybe JSONPath?). Idea: [\"string\", int, \"string\"] where int indicates array offset", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "position": { - SchemaProps: spec.SchemaProps{ - Description: "Positions is a list of where to perform the interpolation within targets during render. The first string is the Idx of the target as a string, since openAPI does not support ints as map keys", - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Position"), - }, - }, - "format": { - SchemaProps: spec.SchemaProps{ - Description: "How values should be interpolated\n\nPossible enum values:\n - `\"csv\"` Formats variables with multiple values as a comma-separated string.\n - `\"doublequote\"` Formats single- and multi-valued variables into a comma-separated string\n - `\"json\"` Formats variables with multiple values as a comma-separated string.\n - `\"pipe\"` Formats variables with multiple values into a pipe-separated string.\n - `\"raw\"` Formats variables with multiple values into comma-separated string. This is the default behavior when no format is specified\n - `\"singlequote\"` Formats single- and multi-valued variables into a comma-separated string", - Type: []string{"string"}, - Format: "", - Enum: []interface{}{"csv", "doublequote", "json", "pipe", "raw", "singlequote"}, - }, - }, - }, - Required: []string{"path"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Position"}, - } -} - -func schema_apis_query_v0alpha1_template_replacement(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "Position": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Position"), - }, - }, - "TemplateVariable": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.TemplateVariable"), - }, - }, - "format": { - SchemaProps: spec.SchemaProps{ - Description: "Possible enum values:\n - `\"csv\"` Formats variables with multiple values as a comma-separated string.\n - `\"doublequote\"` Formats single- and multi-valued variables into a comma-separated string\n - `\"json\"` Formats variables with multiple values as a comma-separated string.\n - `\"pipe\"` Formats variables with multiple values into a pipe-separated string.\n - `\"raw\"` Formats variables with multiple values into comma-separated string. This is the default behavior when no format is specified\n - `\"singlequote\"` Formats single- and multi-valued variables into a comma-separated string", - Default: "", - Type: []string{"string"}, - Format: "", - Enum: []interface{}{"csv", "doublequote", "json", "pipe", "raw", "singlequote"}, - }, - }, - }, - Required: []string{"Position", "TemplateVariable", "format"}, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.Position", "github.com/grafana/grafana/pkg/apis/query/v0alpha1/template.TemplateVariable"}, - } -} diff --git a/pkg/apis/query/v0alpha1/zz_generated.openapi_violation_exceptions.list b/pkg/apis/query/v0alpha1/zz_generated.openapi_violation_exceptions.list index ccded359446..85c5a768907 100644 --- a/pkg/apis/query/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ b/pkg/apis/query/v0alpha1/zz_generated.openapi_violation_exceptions.list @@ -1,5 +1 @@ API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/query/v0alpha1,DataSourceApiServer,AliasIDs -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/query/v0alpha1/template,QueryTemplate,Variables -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/query/v0alpha1/template,replacement,Position -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/query/v0alpha1/template,replacement,TemplateVariable -API rule violation: names_match,github.com/grafana/grafana/pkg/apis/query/v0alpha1/template,replacement,format