K8S/Shared Queries: Add Experimental PeakQ API (#80839)

First pass at a backend api built on top off app platform for shared-queries in explore and a query library with templating. Highly Experimental.

Under grafanaAPIServerWithExperimentalAPIs = true

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
Todd Treece
2024-02-06 11:22:41 -05:00
committed by GitHub
co-authored by Ryan McKinley Kyle Brandt
parent ef9eca3a75
commit abaed01d7e
17 changed files with 1648 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +groupName=peakq.grafana.app
package v0alpha1 // import "github.com/grafana/grafana/pkg/apis/peakq/v0alpha1"
+51
View File
@@ -0,0 +1,51 @@
package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
const (
GROUP = "peakq.grafana.app"
VERSION = "v0alpha1"
APIVERSION = GROUP + "/" + VERSION
)
var QueryTemplateResourceInfo = common.NewResourceInfo(GROUP, VERSION,
"querytemplates", "querytemplate", "QueryTemplate",
func() runtime.Object { return &QueryTemplate{} },
func() runtime.Object { return &QueryTemplateList{} },
)
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: GROUP, Version: VERSION}
// SchemaBuilder is used by standard codegen
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)
func init() {
localSchemeBuilder.Register(addKnownTypes)
}
// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&QueryTemplate{},
&QueryTemplateList{},
&RenderedQuery{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
+123
View File
@@ -0,0 +1,123 @@
package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grafana/grafana-plugin-sdk-go/data"
common "github.com/grafana/grafana/pkg/apis/common/v0alpha1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type QueryTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec QueryTemplateSpec `json:"spec,omitempty"`
}
type QueryTemplateSpec struct {
Title string `json:"title"`
// 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"`
// The raw query: TODO, should be query.GenericQuery
Properties common.Unstructured `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:"defaultValue"`
// 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"`
}
// 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
// See: https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#advanced-variable-format-options
// NOTE: the format parameter is not yet supported!
Format string `json:"format,omitempty"`
// Keep track of the values from previous iterations
History []ReplacementHistory `json:"history,omitempty"`
}
type ReplacementHistory struct {
// Who/what made the change
Source string `json:"source,omitempty"`
// Value before replacement
Previous string `json:"previous"`
// The value(s) that replaced the section
Replacement []string `json:"replacement"`
}
// 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"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type QueryTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []QueryTemplate `json:"items,omitempty"`
}
// Dummy object that represents a real query object
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type RenderedQuery struct {
metav1.TypeMeta `json:",inline"`
// +listType=atomic
Targets []Target `json:"targets,omitempty"`
}
@@ -0,0 +1,255 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by deepcopy-gen. DO NOT EDIT.
package v0alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// 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
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
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
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *QueryTemplate) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *QueryTemplateList) DeepCopyInto(out *QueryTemplateList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]QueryTemplate, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QueryTemplateList.
func (in *QueryTemplateList) DeepCopy() *QueryTemplateList {
if in == nil {
return nil
}
out := new(QueryTemplateList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *QueryTemplateList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *QueryTemplateSpec) DeepCopyInto(out *QueryTemplateSpec) {
*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 QueryTemplateSpec.
func (in *QueryTemplateSpec) DeepCopy() *QueryTemplateSpec {
if in == nil {
return nil
}
out := new(QueryTemplateSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RenderedQuery) DeepCopyInto(out *RenderedQuery) {
*out = *in
out.TypeMeta = in.TypeMeta
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 RenderedQuery.
func (in *RenderedQuery) DeepCopy() *RenderedQuery {
if in == nil {
return nil
}
out := new(RenderedQuery)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *RenderedQuery) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ReplacementHistory) DeepCopyInto(out *ReplacementHistory) {
*out = *in
if in.Replacement != nil {
in, out := &in.Replacement, &out.Replacement
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReplacementHistory.
func (in *ReplacementHistory) DeepCopy() *ReplacementHistory {
if in == nil {
return nil
}
out := new(ReplacementHistory)
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
}
if in.History != nil {
in, out := &in.History, &out.History
*out = make([]ReplacementHistory, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
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
}
@@ -0,0 +1,19 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by defaulter-gen. DO NOT EDIT.
package v0alpha1
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
}
@@ -0,0 +1,450 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1
import (
common "k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
)
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.Position": schema_pkg_apis_peakq_v0alpha1_Position(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplate": schema_pkg_apis_peakq_v0alpha1_QueryTemplate(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplateList": schema_pkg_apis_peakq_v0alpha1_QueryTemplateList(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplateSpec": schema_pkg_apis_peakq_v0alpha1_QueryTemplateSpec(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.RenderedQuery": schema_pkg_apis_peakq_v0alpha1_RenderedQuery(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.ReplacementHistory": schema_pkg_apis_peakq_v0alpha1_ReplacementHistory(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.Target": schema_pkg_apis_peakq_v0alpha1_Target(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.TemplateVariable": schema_pkg_apis_peakq_v0alpha1_TemplateVariable(ref),
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.VariableReplacement": schema_pkg_apis_peakq_v0alpha1_VariableReplacement(ref),
}
}
func schema_pkg_apis_peakq_v0alpha1_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_pkg_apis_peakq_v0alpha1_QueryTemplate(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"kind": {
SchemaProps: spec.SchemaProps{
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Type: []string{"string"},
Format: "",
},
},
"apiVersion": {
SchemaProps: spec.SchemaProps{
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
Type: []string{"string"},
Format: "",
},
},
"metadata": {
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplateSpec"),
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplateSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
}
}
func schema_pkg_apis_peakq_v0alpha1_QueryTemplateList(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"kind": {
SchemaProps: spec.SchemaProps{
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Type: []string{"string"},
Format: "",
},
},
"apiVersion": {
SchemaProps: spec.SchemaProps{
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
Type: []string{"string"},
Format: "",
},
},
"metadata": {
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"),
},
},
"items": {
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/peakq/v0alpha1.QueryTemplate"),
},
},
},
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.QueryTemplate", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"},
}
}
func schema_pkg_apis_peakq_v0alpha1_QueryTemplateSpec(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{
Default: "",
Type: []string{"string"},
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/peakq/v0alpha1.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/peakq/v0alpha1.Target"),
},
},
},
},
},
},
Required: []string{"title", "targets"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.Target", "github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.TemplateVariable"},
}
}
func schema_pkg_apis_peakq_v0alpha1_RenderedQuery(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Dummy object that represents a real query object",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"kind": {
SchemaProps: spec.SchemaProps{
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Type: []string{"string"},
Format: "",
},
},
"apiVersion": {
SchemaProps: spec.SchemaProps{
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
Type: []string{"string"},
Format: "",
},
},
"targets": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-list-type": "atomic",
},
},
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/peakq/v0alpha1.Target"),
},
},
},
},
},
},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.Target"},
}
}
func schema_pkg_apis_peakq_v0alpha1_ReplacementHistory(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"source": {
SchemaProps: spec.SchemaProps{
Description: "Who/what made the change",
Type: []string{"string"},
Format: "",
},
},
"previous": {
SchemaProps: spec.SchemaProps{
Description: "Value before replacement",
Default: "",
Type: []string{"string"},
Format: "",
},
},
"replacement": {
SchemaProps: spec.SchemaProps{
Description: "The value(s) that replaced the section",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: "",
Type: []string{"string"},
Format: "",
},
},
},
},
},
},
Required: []string{"previous", "replacement"},
},
},
}
}
func schema_pkg_apis_peakq_v0alpha1_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/peakq/v0alpha1.VariableReplacement"),
},
},
},
},
},
},
},
},
"properties": {
SchemaProps: spec.SchemaProps{
Description: "The raw query: TODO, should be query.GenericQuery",
Ref: ref("github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured"),
},
},
},
Required: []string{"variables", "properties"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured", "github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.VariableReplacement"},
}
}
func schema_pkg_apis_peakq_v0alpha1_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: "",
},
},
"defaultValue": {
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/apis/common/v0alpha1.Unstructured"),
},
},
},
Required: []string{"key", "defaultValue", "valueListDefinition"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/common/v0alpha1.Unstructured"},
}
}
func schema_pkg_apis_peakq_v0alpha1_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 the the target properties. 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/peakq/v0alpha1.Position"),
},
},
"format": {
SchemaProps: spec.SchemaProps{
Description: "How values should be interpolated See: https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#advanced-variable-format-options NOTE: the format parameter is not yet supported!",
Type: []string{"string"},
Format: "",
},
},
"history": {
SchemaProps: spec.SchemaProps{
Description: "Keep track of the values from previous iterations",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.ReplacementHistory"),
},
},
},
},
},
},
Required: []string{"path"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.Position", "github.com/grafana/grafana/pkg/apis/peakq/v0alpha1.ReplacementHistory"},
}
}
@@ -0,0 +1,4 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/peakq/v0alpha1,ReplacementHistory,Replacement
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/peakq/v0alpha1,VariableReplacement,History
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/peakq/v0alpha1,QueryTemplateSpec,Variables
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/peakq/v0alpha1,TemplateVariable,DefaultValues