Codegen: Generate Golang code using cog (#98812)

* Use cog for Go types

* Delete old generation code

* Fix plugins generation

* workspaces update

* Update datasources with new generated code

* More fixes

* Update swagger and openapi specs

* Fixes

* More files...

* Update workspace

* More fixes...

* Remove unused functions
This commit is contained in:
Selene
2025-01-14 15:58:38 +01:00
committed by GitHub
parent b96a752db3
commit 7151ea6abc
58 changed files with 4913 additions and 4205 deletions

2
go.mod
View File

@@ -300,7 +300,7 @@ require (
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect

4
go.sum
View File

@@ -1692,8 +1692,8 @@ github.com/influxdata/influxql v1.4.0 h1:Lf62rbAF8KWQf+4Djqf4hVXgmQuGozUoSD6kNWj
github.com/influxdata/influxql v1.4.0/go.mod h1:VqxAKyQz5p8GzgGsxWalCWYGxEqw6kvJo2IickMQiQk=
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/ionos-cloud/sdk-go/v6 v6.3.0 h1:/lTieTH9Mo/CWm3cTlFLnK10jgxjUGkAqRffGqvPteY=

View File

@@ -1609,6 +1609,7 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8 h1:a9ENSRDFBUPkJ5lCg
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fsouza/fake-gcs-server v1.7.0 h1:Un0BXUXrRWYSmYyC1Rqm2e2WJfTPyDy/HGMz31emTi8=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
@@ -1661,6 +1662,7 @@ github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-resty/resty/v2 v2.12.0 h1:rsVL8P90LFvkUYq/V5BTVe203WfRIU4gvcf+yfzJzGA=
github.com/go-resty/resty/v2 v2.12.0/go.mod h1:o0yGPrkS3lOe1+eFajk6kBW8ScXzwU3hD69/gt2yB/0=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
@@ -1707,6 +1709,7 @@ github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoG
github.com/google/go-pkcs11 v0.3.0 h1:PVRnTgtArZ3QQqTGtbtjtnIkzl2iY2kt24yqbrf7td8=
github.com/google/go-pkcs11 v0.3.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/pprof v0.0.0-20240416155748-26353dc0451f/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
@@ -1983,7 +1986,11 @@ github.com/ncw/swift/v2 v2.0.2/go.mod h1:z0A9RVdYPjNjXVo2pDOPxZ4eu3oarO1P91fTItc
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1 h1:dOYG7LS/WK00RWZc8XGgcUTlTxpp3mKhdR2Q9z9HbXM=
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
github.com/onsi/ginkgo/v2 v2.3.0/go.mod h1:Eew0uilEqZmIEZr8JrvYlvOM7Rr6xzTmMV8AyFNU9d0=
@@ -1998,7 +2005,11 @@ github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3Ro
github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
@@ -2445,7 +2456,9 @@ golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@@ -2482,6 +2495,10 @@ golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -2528,6 +2545,7 @@ golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=

View File

@@ -2,7 +2,7 @@ module github.com/grafana/grafana/kindsv2
go 1.23.1
require github.com/grafana/cog v0.0.10
require github.com/grafana/cog v0.0.12
require (
cuelabs.dev/go/oci/ociregistry v0.0.0-20240906074133-82eb438dd565 // indirect

View File

@@ -26,8 +26,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d h1:hrXbGJ5jgp6yNITzs5o+zXq0V5yT3siNJ+uM8LGwWKk=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d/go.mod h1:zmwwM/DRyQB7pfuBjTWII3CWtxcXh8LTwAYGfDfpR6s=
github.com/grafana/cog v0.0.10 h1:YqtqZ1a51njXEVRKspuQifRwgYgU5NcK5KwuiEDGUqo=
github.com/grafana/cog v0.0.10/go.mod h1:HwJbc60fZ+viayROClLGdDwO5w/JjBOpO9wjGnAfMLc=
github.com/grafana/cog v0.0.12 h1:MJfFUVzp0El3+zZCmUQ2Y8uzwvM3aa5zj7EOeeuG6VY=
github.com/grafana/cog v0.0.12/go.mod h1:HwJbc60fZ+viayROClLGdDwO5w/JjBOpO9wjGnAfMLc=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=

View File

@@ -1,282 +0,0 @@
package generators
import (
"fmt"
"regexp"
"strings"
"unicode"
"github.com/dave/dst"
"github.com/dave/dst/dstutil"
)
// depointerizer returns an AST manipulator that removes redundant
// pointer indirection from the defined types.
func depointerizer() dstutil.ApplyFunc {
return func(c *dstutil.Cursor) bool {
switch x := c.Node().(type) {
case *dst.Field:
if s, is := x.Type.(*dst.StarExpr); is {
switch deref := depoint(s).(type) {
case *dst.ArrayType, *dst.MapType:
x.Type = deref
}
}
}
return true
}
}
func depoint(e dst.Expr) dst.Expr {
if star, is := e.(*dst.StarExpr); is {
return star.X
}
return e
}
func setStar(e dst.Expr) string {
if _, is := e.(*dst.StarExpr); is {
return "*"
}
return ""
}
func fixTODOComments() dstutil.ApplyFunc {
return func(cursor *dstutil.Cursor) bool {
switch f := cursor.Node().(type) {
case *dst.File:
for _, d := range f.Decls {
if isTypeSpec(d) {
removeGoFieldComment(d.Decorations().Start.All())
}
fixTODOComment(d.Decorations().Start.All())
}
case *dst.Field:
if len(f.Names) > 0 {
removeGoFieldComment(f.Decorations().Start.All())
}
}
return true
}
}
func fixTODOComment(comments []string) {
todoRegex := regexp.MustCompile("(//) (.*) (TODO.*)")
if len(comments) > 0 {
comments[0] = todoRegex.ReplaceAllString(comments[0], "$1 $3")
}
}
func removeGoFieldComment(comments []string) {
todoRegex := regexp.MustCompile("(//) ([A-Z].*?) ([A-Z]?.*?) (.*)")
if len(comments) > 0 {
matches := todoRegex.FindAllStringSubmatch(comments[0], -1)
if len(matches) > 0 {
if strings.EqualFold(matches[0][3], matches[0][2]) {
comments[0] = fmt.Sprintf("%s %s %s", matches[0][1], matches[0][3], matches[0][4])
} else {
r := []rune(matches[0][3])
if !unicode.IsLower(r[0]) {
comments[0] = fmt.Sprintf("%s %s %s", matches[0][1], matches[0][3], matches[0][4])
}
}
}
}
}
func isTypeSpec(d dst.Decl) bool {
gd, ok := d.(*dst.GenDecl)
if !ok {
return false
}
_, is := gd.Specs[0].(*dst.TypeSpec)
return is
}
// It fixes the "generic" fields. It happens when a value in cue could be different structs.
// For Go it generates a struct with a json.RawMessage field inside and multiple functions to map it between the different possibilities.
func fixRawData() dstutil.ApplyFunc {
return func(c *dstutil.Cursor) bool {
f, is := c.Node().(*dst.File)
if !is {
return false
}
rawFields := make(map[string]bool)
existingRawFields := make(map[string]bool)
for _, decl := range f.Decls {
switch x := decl.(type) {
// Find the structs that only contains one json.RawMessage inside
case *dst.GenDecl:
for _, t := range x.Specs {
if ts, ok := t.(*dst.TypeSpec); ok {
if tp, ok := ts.Type.(*dst.StructType); ok && len(tp.Fields.List) == 1 {
if fn, ok := tp.Fields.List[0].Type.(*dst.SelectorExpr); ok {
if fmt.Sprintf("%s.%s", fn.X, fn.Sel.Name) == "json.RawMessage" {
rawFields[ts.Name.Name] = true
}
}
}
}
}
// Find the functions of the previous structs to verify that are the ones that we are looking for.
case *dst.FuncDecl:
for _, recv := range x.Recv.List {
fnType := depoint(recv.Type).(*dst.Ident).Name
if rawFields[fnType] {
existingRawFields[fnType] = true
}
}
}
}
dstutil.Apply(f, func(c *dstutil.Cursor) bool {
switch x := c.Node().(type) {
// Delete the functions
case *dst.FuncDecl:
c.Delete()
case *dst.GenDecl:
// Deletes all "generics" generated for these json.RawMessage structs
comments := x.Decorations().Start.All()
if len(comments) > 0 {
if strings.HasSuffix(comments[0], "defines model for .") {
c.Delete()
}
}
for _, spec := range x.Specs {
if tp, ok := spec.(*dst.TypeSpec); ok {
// Delete structs with only json.RawMessage
if existingRawFields[tp.Name.Name] && tp.Name.Name != "MetricAggregation2" {
c.Delete()
continue
}
// Set types that was using these structs as interface{}
if st, ok := tp.Type.(*dst.StructType); ok {
iterateStruct(st, withoutRawData(existingRawFields))
}
if mt, ok := tp.Type.(*dst.MapType); ok {
iterateMap(mt, withoutRawData(existingRawFields))
}
if at, ok := tp.Type.(*dst.ArrayType); ok {
iterateArray(at, withoutRawData(existingRawFields))
}
}
}
}
return true
}, nil)
return true
}
}
// Fixes type name containing underscores in the generated Go files
func fixUnderscoreInTypeName() dstutil.ApplyFunc {
return func(c *dstutil.Cursor) bool {
switch x := c.Node().(type) {
case *dst.GenDecl:
if specs, isType := x.Specs[0].(*dst.TypeSpec); isType {
if strings.Contains(specs.Name.Name, "_") {
oldName := specs.Name.Name
specs.Name.Name = strings.ReplaceAll(specs.Name.Name, "_", "")
x.Decs.Start[0] = strings.ReplaceAll(x.Decs.Start[0], oldName, specs.Name.Name)
}
if st, ok := specs.Type.(*dst.StructType); ok {
iterateStruct(st, withoutUnderscore)
}
if mt, ok := specs.Type.(*dst.MapType); ok {
iterateMap(mt, withoutUnderscore)
}
if at, ok := specs.Type.(*dst.ArrayType); ok {
iterateArray(at, withoutUnderscore)
}
}
case *dst.Field:
findFieldsWithUnderscores(x)
}
return true
}
}
func findFieldsWithUnderscores(x *dst.Field) {
switch t := x.Type.(type) {
case *dst.Ident:
withoutUnderscore(t)
case *dst.StarExpr:
if i, is := t.X.(*dst.Ident); is {
withoutUnderscore(i)
}
case *dst.ArrayType:
iterateArray(t, withoutUnderscore)
case *dst.MapType:
iterateMap(t, withoutUnderscore)
}
}
func withoutUnderscore(i *dst.Ident) {
if strings.Contains(i.Name, "_") {
i.Name = strings.ReplaceAll(i.Name, "_", "")
}
}
func withoutRawData(existingFields map[string]bool) func(ident *dst.Ident) {
return func(i *dst.Ident) {
if existingFields[i.Name] {
i.Name = setStar(i) + "any"
}
}
}
func iterateStruct(s *dst.StructType, fn func(i *dst.Ident)) {
for i, f := range s.Fields.List {
switch mx := depoint(f.Type).(type) {
case *dst.Ident:
fn(mx)
case *dst.ArrayType:
iterateArray(mx, fn)
case *dst.MapType:
iterateMap(mx, fn)
case *dst.StructType:
iterateStruct(mx, fn)
case *dst.InterfaceType:
s.Fields.List[i].Type = interfaceToAny(f.Type)
}
}
}
func iterateMap(s *dst.MapType, fn func(i *dst.Ident)) {
switch mx := s.Value.(type) {
case *dst.Ident:
fn(mx)
case *dst.ArrayType:
iterateArray(mx, fn)
case *dst.MapType:
iterateMap(mx, fn)
case *dst.InterfaceType:
s.Value = interfaceToAny(s.Value)
}
}
func iterateArray(a *dst.ArrayType, fn func(i *dst.Ident)) {
switch mx := a.Elt.(type) {
case *dst.Ident:
fn(mx)
case *dst.ArrayType:
iterateArray(mx, fn)
case *dst.StructType:
iterateStruct(mx, fn)
case *dst.InterfaceType:
a.Elt = interfaceToAny(a.Elt)
}
}
func interfaceToAny(i dst.Expr) dst.Expr {
star := ""
if _, is := i.(*dst.StarExpr); is {
star = "*"
}
return &dst.Ident{Name: star + "any"}
}

View File

@@ -1,193 +0,0 @@
package generators
import (
"bytes"
"fmt"
"go/parser"
"go/token"
"path/filepath"
"strings"
"cuelang.org/go/cue"
"cuelang.org/go/pkg/encoding/yaml"
"github.com/dave/dst/decorator"
"github.com/dave/dst/dstutil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen"
"golang.org/x/tools/imports"
)
type GoConfig struct {
Config *OpenApiConfig
PackageName string
ApplyFuncs []dstutil.ApplyFunc
}
func GenerateTypesGo(v cue.Value, cfg *GoConfig) ([]byte, error) {
if cfg == nil {
return nil, fmt.Errorf("configuration cannot be nil")
}
applyFuncs := []dstutil.ApplyFunc{depointerizer(), fixRawData(), fixUnderscoreInTypeName(), fixTODOComments()}
applyFuncs = append(applyFuncs, cfg.ApplyFuncs...)
f, err := generateOpenAPI(v, cfg.Config)
if err != nil {
return nil, err
}
str, err := yaml.Marshal(v.Context().BuildFile(f))
if err != nil {
return nil, fmt.Errorf("cue-yaml marshaling failed: %w", err)
}
loader := openapi3.NewLoader()
oT, err := loader.LoadFromData([]byte(str))
if err != nil {
return nil, fmt.Errorf("loading generated openapi failed: %w", err)
}
schemaName, err := getSchemaName(v)
if err != nil {
return nil, err
}
if cfg.PackageName == "" {
cfg.PackageName = schemaName
}
// Hack to fix https://github.com/grafana/thema/pull/127 issue without importing
// to avoid to add the whole vendor in Grafana code
if cfg.PackageName == "dataquery" {
fixDataQuery(oT)
}
ccfg := codegen.Configuration{
PackageName: cfg.PackageName,
Compatibility: codegen.CompatibilityOptions{
AlwaysPrefixEnumValues: true,
},
Generate: codegen.GenerateOptions{
Models: true,
},
OutputOptions: codegen.OutputOptions{
SkipPrune: true,
UserTemplates: map[string]string{
"imports.tmpl": importstmpl,
},
},
}
gostr, err := codegen.Generate(oT, ccfg)
if err != nil {
return nil, fmt.Errorf("openapi generation failed: %w", err)
}
return postprocessGoFile(genGoFile{
path: fmt.Sprintf("%s_type_gen.go", schemaName),
appliers: applyFuncs,
in: []byte(gostr),
})
}
type genGoFile struct {
path string
appliers []dstutil.ApplyFunc
in []byte
}
func postprocessGoFile(cfg genGoFile) ([]byte, error) {
fname := sanitizeLabelString(filepath.Base(cfg.path))
buf := new(bytes.Buffer)
fset := token.NewFileSet()
gf, err := decorator.ParseFile(fset, fname, string(cfg.in), parser.ParseComments)
if err != nil {
return nil, fmt.Errorf("error parsing generated file: %w", err)
}
for _, af := range cfg.appliers {
dstutil.Apply(gf, af, nil)
}
err = decorator.Fprint(buf, gf)
if err != nil {
return nil, fmt.Errorf("error formatting generated file: %w", err)
}
byt, err := imports.Process(fname, buf.Bytes(), nil)
if err != nil {
return nil, fmt.Errorf("goimports processing of generated file failed: %w", err)
}
// Compare imports before and after; warn about performance if some were added
gfa, _ := parser.ParseFile(fset, fname, string(byt), parser.ParseComments)
imap := make(map[string]bool)
for _, im := range gf.Imports {
imap[im.Path.Value] = true
}
var added []string
for _, im := range gfa.Imports {
if !imap[im.Path.Value] {
added = append(added, im.Path.Value)
}
}
if len(added) != 0 {
// TODO improve the guidance in this error if/when we better abstract over imports to generate
return nil, fmt.Errorf("goimports added the following import statements to %s: \n\t%s\nRelying on goimports to find imports significantly slows down code generation. Either add these imports with an AST manipulation in cfg.ApplyFuncs, or set cfg.IgnoreDiscoveredImports to true", cfg.path, strings.Join(added, "\n\t"))
}
return byt, nil
}
// fixDataQuery extends the properties for the AllOf schemas when a DataQuery exists.
// deep/oapi-codegen library ignores the properties of the models and only ones have references.
// It doesn't apply this change https://github.com/grafana/thema/pull/154 since it modifies the
// vendor implementation, and we don't import it.
func fixDataQuery(spec *openapi3.T) *openapi3.T {
for _, sch := range spec.Components.Schemas {
if sch.Value != nil && len(sch.Value.AllOf) > 0 {
for _, allOf := range sch.Value.AllOf {
for n, p := range allOf.Value.Properties {
sch.Value.Properties[n] = p
}
}
sch.Value.AllOf = nil
}
}
return spec
}
// Almost all of the below imports are eliminated by dst transformers and calls
// to goimports - but if they're not present in the template, then the internal
// call to goimports that oapi-codegen makes will trigger a search for them,
// which can slow down codegen by orders of magnitude.
var importstmpl = `package {{ .PackageName }}
import (
"bytes"
"compress/gzip"
"context"
"encoding/base64"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"os"
"net/http"
"net/url"
"path"
"strings"
"time"
"github.com/oapi-codegen/runtime"
openapi_types "github.com/oapi-codegen/runtime/types"
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-chi/chi/v5"
"github.com/labstack/echo/v4"
"github.com/gin-gonic/gin"
"github.com/gorilla/mux"
)
`

View File

@@ -1,199 +0,0 @@
package generators
import (
"fmt"
"strings"
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/encoding/openapi"
)
type OpenApiConfig struct {
Config *openapi.Config
IsGroup bool
RootName string
SubPath cue.Path
}
func generateOpenAPI(v cue.Value, cfg *OpenApiConfig) (*ast.File, error) {
if cfg == nil {
return nil, fmt.Errorf("missing openapi configuration")
}
if cfg.Config == nil {
cfg.Config = &openapi.Config{}
}
name, err := getSchemaName(v)
if err != nil {
return nil, err
}
gen := &oapiGen{
cfg: cfg,
name: name,
val: v.LookupPath(cue.ParsePath("lineage.schemas[0].schema")),
subpath: cfg.SubPath,
bpath: v.LookupPath(cue.ParsePath("lineage.schemas[0]")).Path(),
}
declFunc := genSchema
if cfg.IsGroup {
declFunc = genGroup
}
decls, err := declFunc(gen)
if err != nil {
return nil, err
}
// TODO recursively sort output to improve stability of output
return &ast.File{
Decls: []ast.Decl{
ast.NewStruct(
"openapi", ast.NewString("3.0.0"),
"paths", ast.NewStruct(),
"components", ast.NewStruct(
"schemas", &ast.StructLit{Elts: decls},
),
),
},
}, nil
}
type oapiGen struct {
cfg *OpenApiConfig
val cue.Value
subpath cue.Path
// overall name for the generated oapi doc
name string
// original NameFunc
onf func(cue.Value, cue.Path) string
// full prefix path that leads up to the #SchemaDef, e.g. lin._sortedSchemas[0]
bpath cue.Path
}
func genGroup(gen *oapiGen) ([]ast.Decl, error) {
ctx := gen.val.Context()
iter, err := gen.val.Fields(cue.Definitions(true), cue.Optional(true))
if err != nil {
panic(fmt.Errorf("unreachable - should always be able to get iter for struct kinds: %w", err))
}
var decls []ast.Decl
for iter.Next() {
val, sel := iter.Value(), iter.Selector()
name := strings.Trim(sel.String(), "?#")
v := ctx.CompileString(fmt.Sprintf("#%s: _", name))
defpath := cue.MakePath(cue.Def(name))
defsch := v.FillPath(defpath, val)
cfgi := *gen.cfg.Config
cfgi.NameFunc = func(val cue.Value, path cue.Path) string {
return gen.nfSingle(val, path, defpath, name)
}
part, err := openapi.Generate(defsch, &cfgi)
if err != nil {
return nil, fmt.Errorf("failed generation for grouped field %s: %w", sel, err)
}
decls = append(decls, getSchemas(part)...)
}
return decls, nil
}
func genSchema(gen *oapiGen) ([]ast.Decl, error) {
hasSubpath := len(gen.cfg.SubPath.Selectors()) > 0
name := sanitizeLabelString(gen.name)
if gen.cfg.RootName != "" {
name = gen.cfg.RootName
} else if hasSubpath {
sel := gen.cfg.SubPath.Selectors()
name = sel[len(sel)-1].String()
}
val := gen.val
if hasSubpath {
for i, sel := range gen.cfg.SubPath.Selectors() {
if !gen.val.Allows(sel) {
return nil, fmt.Errorf("subpath %q not present in schema", cue.MakePath(gen.cfg.SubPath.Selectors()[:i+1]...))
}
}
val = val.LookupPath(gen.cfg.SubPath)
}
v := gen.val.Context().CompileString(fmt.Sprintf("#%s: _", name))
defpath := cue.MakePath(cue.Def(name))
defsch := v.FillPath(defpath, val)
gen.cfg.Config.NameFunc = func(val cue.Value, path cue.Path) string {
return gen.nfSingle(val, path, defpath, name)
}
f, err := openapi.Generate(defsch.Eval(), gen.cfg.Config)
if err != nil {
return nil, err
}
return getSchemas(f), nil
}
// For generating a single, our NameFunc must:
// - Eliminate any path prefixes on the element, both internal lineage and wrapping
// - Replace the name "_#schema" with the desired name
// - Call the user-provided NameFunc, if any
// - Remove CUE markers like #, !, ?
func (gen *oapiGen) nfSingle(val cue.Value, path, defpath cue.Path, name string) string {
tpath := trimPathPrefix(trimThemaPathPrefix(path, gen.bpath), defpath)
if path.String() == "" || tpath.String() == defpath.String() {
return name
}
if val == gen.val {
return ""
}
if gen.onf != nil {
return gen.onf(val, tpath)
}
return strings.Trim(tpath.String(), "?#")
}
func getSchemas(f *ast.File) []ast.Decl {
compos := orp(getFieldByLabel(f, "components"))
schemas := orp(getFieldByLabel(compos.Value, "schemas"))
return schemas.Value.(*ast.StructLit).Elts
}
func orp[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}
func trimThemaPathPrefix(p, base cue.Path) cue.Path {
if !pathHasPrefix(p, base) {
return p
}
rest := p.Selectors()[len(base.Selectors()):]
if len(rest) == 0 {
return cue.Path{}
}
switch rest[0].String() {
case "schema", "_#schema", "_join", "joinSchema":
return cue.MakePath(rest[1:]...)
default:
return cue.MakePath(rest...)
}
}

View File

@@ -1,130 +0,0 @@
package generators
import (
"fmt"
"strconv"
"strings"
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/token"
)
// sanitizeLabelString strips characters from a string that are not allowed for
// use in a CUE label.
func sanitizeLabelString(s string) string {
return strings.Map(func(r rune) rune {
switch {
case r >= 'a' && r <= 'z':
fallthrough
case r >= 'A' && r <= 'Z':
fallthrough
case r >= '0' && r <= '9':
fallthrough
case r == '_':
return r
default:
return -1
}
}, s)
}
// trimPathPrefix strips the provided prefix from the provided path, if the
// prefix exists.
//
// If path and prefix are equivalent, and there is at least one additional
// selector in the provided path.
func trimPathPrefix(path, prefix cue.Path) cue.Path {
sels, psels := path.Selectors(), prefix.Selectors()
if len(sels) == 1 {
return path
}
var i int
for ; i < len(psels) && i < len(sels); i++ {
if !selEq(psels[i], sels[i]) {
break
}
}
return cue.MakePath(sels[i:]...)
}
// selEq indicates whether two selectors are equivalent. Selectors are equivalent if
// they are either exactly equal, or if they are equal ignoring path optionality.
func selEq(s1, s2 cue.Selector) bool {
return s1 == s2 || s1.Optional() == s2.Optional()
}
// getFieldByLabel returns the ast.Field with a given label from a struct-ish input.
func getFieldByLabel(n ast.Node, label string) (*ast.Field, error) {
var d []ast.Decl
switch x := n.(type) {
case *ast.File:
d = x.Decls
case *ast.StructLit:
d = x.Elts
default:
return nil, fmt.Errorf("not an *ast.File or *ast.StructLit")
}
for _, el := range d {
if isFieldWithLabel(el, label) {
return el.(*ast.Field), nil
}
}
return nil, fmt.Errorf("no field with label %q", label)
}
func isFieldWithLabel(n ast.Node, label string) bool {
if x, is := n.(*ast.Field); is {
if l, is := x.Label.(*ast.BasicLit); is {
return strEq(l, label)
}
if l, is := x.Label.(*ast.Ident); is {
return identStrEq(l, label)
}
}
return false
}
func strEq(lit *ast.BasicLit, str string) bool {
if lit.Kind != token.STRING {
return false
}
ls, _ := strconv.Unquote(lit.Value)
return str == ls || str == lit.Value
}
func identStrEq(id *ast.Ident, str string) bool {
if str == id.Name {
return true
}
ls, _ := strconv.Unquote(id.Name)
return str == ls
}
// pathHasPrefix tests whether the [cue.Path] p begins with prefix.
func pathHasPrefix(p, prefix cue.Path) bool {
ps, pres := p.Selectors(), prefix.Selectors()
if len(pres) > len(ps) {
return false
}
return pathsAreEq(ps[:len(pres)], pres)
}
func pathsAreEq(p1s, p2s []cue.Selector) bool {
if len(p1s) != len(p2s) {
return false
}
for i := 0; i < len(p2s); i++ {
if !selEq(p2s[i], p1s[i]) {
return false
}
}
return true
}
func getSchemaName(v cue.Value) (string, error) {
nameValue := v.LookupPath(cue.ParsePath("name"))
return nameValue.String()
}

View File

@@ -5,21 +5,19 @@ go 1.23.1
require (
cuelang.org/go v0.11.1
github.com/dave/dst v0.27.3
github.com/getkin/kin-openapi v0.128.0
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d
github.com/grafana/cog v0.0.12
github.com/grafana/cuetsy v0.1.11
github.com/matryer/is v1.4.1
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
golang.org/x/tools v0.29.0
)
require (
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/dave/jennifer v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/emicklei/proto v1.13.2 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/golang/glog v1.2.2 // indirect
@@ -27,29 +25,28 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.35.1 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20241112170944-20d2c9ebc01d // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yalue/merged_fs v1.3.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.29.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,6 +1,3 @@
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E=
github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
@@ -12,48 +9,30 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 h1:PRxIJD8XjimM5aTknUK9w6DHLDox2r2M3DI4i2pnd3w=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936/go.mod h1:ttYvX5qlB+mlV1okblJqcSMtR4c52UKxDiX9GRBS8+Q=
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d h1:hrXbGJ5jgp6yNITzs5o+zXq0V5yT3siNJ+uM8LGwWKk=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d/go.mod h1:zmwwM/DRyQB7pfuBjTWII3CWtxcXh8LTwAYGfDfpR6s=
github.com/grafana/cog v0.0.12 h1:MJfFUVzp0El3+zZCmUQ2Y8uzwvM3aa5zj7EOeeuG6VY=
github.com/grafana/cog v0.0.12/go.mod h1:HwJbc60fZ+viayROClLGdDwO5w/JjBOpO9wjGnAfMLc=
github.com/grafana/cue v0.0.0-20230926092038-971951014e3f h1:TmYAMnqg3d5KYEAaT6PtTguL2GjLfvr6wnAX8Azw6tQ=
github.com/grafana/cue v0.0.0-20230926092038-971951014e3f/go.mod h1:okjJBHFQFer+a41sAe2SaGm1glWS8oEb6CmJvn5Zdws=
github.com/grafana/cuetsy v0.1.11 h1:I3IwBhF+UaQxRM79HnImtrAn8REGdb5M3+C4QrYHoWk=
@@ -63,8 +42,8 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -90,25 +69,6 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de h1:D5x39vF5KCwKQaw+OC9ZPiLVHXz3UFw2+psEX+gYcto=
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de/go.mod h1:kJun4WP5gFuHZgRjZUWWuH1DTxCtxbHDOIJsudS8jzY=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 h1:ykgG34472DWey7TSjd8vIfNykXgjOgYJZoQbKfEeY/Q=
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1/go.mod h1:N5+lY1tiTDV3V1BeHtOxeWXHoPVeApvsvjJqegfoaz8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -121,98 +81,38 @@ github.com/protocolbuffers/txtpbfmt v0.0.0-20220428173112-74888fd59c2b h1:zd/2RN
github.com/protocolbuffers/txtpbfmt v0.0.0-20220428173112-74888fd59c2b/go.mod h1:KjY0wibdYKc4DYkerHSbguaf3JeIPGhNJBp2BNiFH78=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54VRhy1aSutx0PQg=
github.com/speakeasy-api/openapi-overlay v0.9.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
github.com/yalue/merged_fs v1.3.0 h1:qCeh9tMPNy/i8cwDsQTJ5bLr6IRxbs6meakNE5O+wyY=
github.com/yalue/merged_fs v1.3.0/go.mod h1:WqqchfVYQyclV2tnR7wtRhBddzBvLVR83Cjw9BKQw0M=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,13 +1,14 @@
package codegen
import (
"context"
"fmt"
"strings"
"cuelang.org/go/cue"
"github.com/dave/dst/dstutil"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/codegen/generators"
"github.com/grafana/cog"
)
type GoSpecJenny struct {
@@ -20,25 +21,20 @@ func (jenny *GoSpecJenny) JennyName() string {
func (jenny *GoSpecJenny) Generate(sfg ...SchemaForGen) (codejen.Files, error) {
files := make(codejen.Files, len(sfg))
for i, v := range sfg {
packageName := strings.ToLower(v.Name)
b, err := generators.GenerateTypesGo(v.CueFile,
&generators.GoConfig{
Config: &generators.OpenApiConfig{
IsGroup: false,
RootName: "Spec",
SubPath: cue.MakePath(cue.Str("spec")),
},
PackageName: packageName,
ApplyFuncs: append(jenny.ApplyFuncs, PrefixDropper(v.Name)),
},
)
cueValue := v.CueFile.LookupPath(cue.ParsePath("lineage.schemas[0].schema.spec"))
b, err := cog.TypesFromSchema().
CUEValue(packageName, cueValue, cog.ForceEnvelope("Spec")).
Golang(cog.GoConfig{}).
Run(context.Background())
if err != nil {
return nil, err
}
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", packageName, packageName), b, jenny)
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", packageName, packageName), b[0].Data, jenny)
}
return files, nil

View File

@@ -7,54 +7,73 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package accesspolicy
// Defines values for RoleRefKind.
const (
RoleRefKindBuiltinRole RoleRefKind = "BuiltinRole"
RoleRefKindRole RoleRefKind = "Role"
RoleRefKindTeam RoleRefKind = "Team"
RoleRefKindUser RoleRefKind = "User"
)
// AccessRule defines model for AccessRule.
type AccessRule struct {
// The kind this rule applies to (dashboards, alert, etc)
Kind string `json:"kind"`
// Specific sub-elements like "alert.rules" or "dashboard.permissions"????
Target *string `json:"target,omitempty"`
// READ, WRITE, CREATE, DELETE, ...
// should move to k8s style verbs like: "get", "list", "watch", "create", "update", "patch", "delete"
Verb string `json:"verb"`
}
// ResourceRef defines model for ResourceRef.
type ResourceRef struct {
// explicit resource or folder will cascade
Kind string `json:"kind"`
Name string `json:"name"`
}
// RoleRef defines model for RoleRef.
// NewResourceRef creates a new ResourceRef object.
func NewResourceRef() *ResourceRef {
return &ResourceRef{}
}
type RoleRef struct {
// Policies can apply to roles, teams, or users
// Applying policies to individual users is supported, but discouraged
Kind RoleRefKind `json:"kind"`
Name string `json:"name"`
Xname string `json:"xname"`
Kind RoleRefKind `json:"kind"`
Name string `json:"name"`
// temporary
Xname string `json:"xname"`
}
// Policies can apply to roles, teams, or users
// Applying policies to individual users is supported, but discouraged
type RoleRefKind string
// NewRoleRef creates a new RoleRef object.
func NewRoleRef() *RoleRef {
return &RoleRef{}
}
type AccessRule struct {
// The kind this rule applies to (dashboards, alert, etc)
Kind string `json:"kind"`
// READ, WRITE, CREATE, DELETE, ...
// should move to k8s style verbs like: "get", "list", "watch", "create", "update", "patch", "delete"
Verb string `json:"verb"`
// Specific sub-elements like "alert.rules" or "dashboard.permissions"????
Target *string `json:"target,omitempty"`
}
// NewAccessRule creates a new AccessRule object.
func NewAccessRule() *AccessRule {
return &AccessRule{}
}
// Spec defines model for Spec.
type Spec struct {
// The scope where these policies should apply
Scope ResourceRef `json:"scope"`
// The role that must apply this policy
Role RoleRef `json:"role"`
// The set of rules to apply. Note that * is required to modify
// access policy rules, and that "none" will reject all actions
Rules []AccessRule `json:"rules"`
Scope ResourceRef `json:"scope"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{
Scope: *NewResourceRef(),
Role: *NewRoleRef(),
}
}
type RoleRefKind string
const (
RoleRefKindRole RoleRefKind = "Role"
RoleRefKindBuiltinRole RoleRefKind = "BuiltinRole"
RoleRefKindTeam RoleRefKind = "Team"
RoleRefKindUser RoleRefKind = "User"
)

File diff suppressed because it is too large Load Diff

View File

@@ -7,55 +7,66 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package librarypanel
import (
"time"
time "time"
)
// LibraryElementDTOMeta defines model for LibraryElementDTOMeta.
type LibraryElementDTOMetaUser struct {
Id int64 `json:"id"`
Name string `json:"name"`
AvatarUrl string `json:"avatarUrl"`
}
// NewLibraryElementDTOMetaUser creates a new LibraryElementDTOMetaUser object.
func NewLibraryElementDTOMetaUser() *LibraryElementDTOMetaUser {
return &LibraryElementDTOMetaUser{}
}
type LibraryElementDTOMeta struct {
ConnectedDashboards int64 `json:"connectedDashboards"`
Created time.Time `json:"created"`
CreatedBy LibraryElementDTOMetaUser `json:"createdBy"`
FolderName string `json:"folderName"`
FolderUid string `json:"folderUid"`
ConnectedDashboards int64 `json:"connectedDashboards"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
CreatedBy LibraryElementDTOMetaUser `json:"createdBy"`
UpdatedBy LibraryElementDTOMetaUser `json:"updatedBy"`
}
// LibraryElementDTOMetaUser defines model for LibraryElementDTOMetaUser.
type LibraryElementDTOMetaUser struct {
AvatarUrl string `json:"avatarUrl"`
Id int64 `json:"id"`
Name string `json:"name"`
// NewLibraryElementDTOMeta creates a new LibraryElementDTOMeta object.
func NewLibraryElementDTOMeta() *LibraryElementDTOMeta {
return &LibraryElementDTOMeta{
CreatedBy: *NewLibraryElementDTOMetaUser(),
UpdatedBy: *NewLibraryElementDTOMetaUser(),
}
}
// Spec defines model for Spec.
type Spec struct {
// Folder UID
FolderUid *string `json:"folderUid,omitempty"`
// Library element UID
Uid string `json:"uid"`
// Panel name (also saved in the model)
Name string `json:"name"`
// Panel description
Description *string `json:"description,omitempty"`
// Folder UID
FolderUid *string `json:"folderUid,omitempty"`
Meta *LibraryElementDTOMeta `json:"meta,omitempty"`
// The panel type (from inside the model)
Type string `json:"type"`
// Dashboard version when this was saved (zero if unknown)
SchemaVersion *uint16 `json:"schemaVersion,omitempty"`
// panel version, incremented each time the dashboard is updated.
Version int64 `json:"version"`
// TODO: should be the same panel schema defined in dashboard
// Typescript: Omit<Panel, 'gridPos' | 'id' | 'libraryPanel'>;
Model map[string]any `json:"model"`
// Panel name (also saved in the model)
Name string `json:"name"`
// Dashboard version when this was saved (zero if unknown)
SchemaVersion *int `json:"schemaVersion,omitempty"`
// The panel type (from inside the model)
Type string `json:"type"`
// Library element UID
Uid string `json:"uid"`
// Version panel version, incremented each time the dashboard is updated.
Version int64 `json:"version"`
// Object storage metadata
Meta *LibraryElementDTOMeta `json:"meta,omitempty"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{}
}

View File

@@ -7,46 +7,63 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package preferences
// CookiePreferences defines model for CookiePreferences.
type CookiePreferences struct {
Analytics map[string]any `json:"analytics,omitempty"`
Functional map[string]any `json:"functional,omitempty"`
Performance map[string]any `json:"performance,omitempty"`
type QueryHistoryPreference struct {
// one of: '' | 'query' | 'starred';
HomeTab *string `json:"homeTab,omitempty"`
}
// NewQueryHistoryPreference creates a new QueryHistoryPreference object.
func NewQueryHistoryPreference() *QueryHistoryPreference {
return &QueryHistoryPreference{}
}
type CookiePreferences struct {
Analytics any `json:"analytics,omitempty"`
Performance any `json:"performance,omitempty"`
Functional any `json:"functional,omitempty"`
}
// NewCookiePreferences creates a new CookiePreferences object.
func NewCookiePreferences() *CookiePreferences {
return &CookiePreferences{}
}
// NavbarPreference defines model for NavbarPreference.
type NavbarPreference struct {
BookmarkUrls []string `json:"bookmarkUrls"`
}
// QueryHistoryPreference defines model for QueryHistoryPreference.
type QueryHistoryPreference struct {
// HomeTab one of: '' | 'query' | 'starred';
HomeTab *string `json:"homeTab,omitempty"`
// NewNavbarPreference creates a new NavbarPreference object.
func NewNavbarPreference() *NavbarPreference {
return &NavbarPreference{}
}
// Spec defines user, team or org Grafana preferences
// swagger:model Preferences
type Spec struct {
CookiePreferences *CookiePreferences `json:"cookiePreferences,omitempty"`
// UID for the home dashboard
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
// Selected language (beta)
Language *string `json:"language,omitempty"`
Navbar *NavbarPreference `json:"navbar,omitempty"`
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
// Theme light, dark, empty is default
Theme *string `json:"theme,omitempty"`
// The timezone selection
// TODO: this should use the timezone defined in common
Timezone *string `json:"timezone,omitempty"`
// WeekStart day of the week (sunday, monday, etc)
// day of the week (sunday, monday, etc)
WeekStart *string `json:"weekStart,omitempty"`
// light, dark, empty is default
Theme *string `json:"theme,omitempty"`
// Selected language (beta)
Language *string `json:"language,omitempty"`
// Explore query history preferences
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
// Cookie preferences
CookiePreferences *CookiePreferences `json:"cookiePreferences,omitempty"`
// Navigation preferences
Navbar *NavbarPreference `json:"navbar,omitempty"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{}
}

View File

@@ -7,25 +7,26 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package publicdashboard
// Spec defines model for Spec.
type Spec struct {
// Unique public access token
AccessToken *string `json:"accessToken,omitempty"`
// Flag that indicates if annotations are enabled
AnnotationsEnabled bool `json:"annotationsEnabled"`
// Dashboard unique identifier referenced by this public dashboard
DashboardUid string `json:"dashboardUid"`
// Flag that indicates if the public dashboard is enabled
IsEnabled bool `json:"isEnabled"`
// Flag that indicates if the time range picker is enabled
TimeSelectionEnabled bool `json:"timeSelectionEnabled"`
// Unique public dashboard identifier
Uid string `json:"uid"`
// Dashboard unique identifier referenced by this public dashboard
DashboardUid string `json:"dashboardUid"`
// Unique public access token
AccessToken *string `json:"accessToken,omitempty"`
// Flag that indicates if the public dashboard is enabled
IsEnabled bool `json:"isEnabled"`
// Flag that indicates if annotations are enabled
AnnotationsEnabled bool `json:"annotationsEnabled"`
// Flag that indicates if the time range picker is enabled
TimeSelectionEnabled bool `json:"timeSelectionEnabled"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{}
}

View File

@@ -7,22 +7,24 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package role
// Spec defines model for Spec.
type Spec struct {
// Role description
Description *string `json:"description,omitempty"`
// Optional display
DisplayName *string `json:"displayName,omitempty"`
// Name of the team.
GroupName *string `json:"groupName,omitempty"`
// Do not show this role
Hidden bool `json:"hidden"`
// The role identifier `managed:builtins:editor:permissions`
Name string `json:"name"`
// Optional display
DisplayName *string `json:"displayName,omitempty"`
// Name of the team.
GroupName *string `json:"groupName,omitempty"`
// Role description
Description *string `json:"description,omitempty"`
// Do not show this role
Hidden bool `json:"hidden"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{}
}

View File

@@ -7,66 +7,138 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package rolebinding
// Defines values for BuiltinRoleRefKind.
const (
BuiltinRoleRefKindBuiltinRole BuiltinRoleRefKind = "BuiltinRole"
import (
json "encoding/json"
errors "errors"
fmt "fmt"
)
// Defines values for BuiltinRoleRefName.
const (
BuiltinRoleRefNameAdmin BuiltinRoleRefName = "admin"
BuiltinRoleRefNameEditor BuiltinRoleRefName = "editor"
BuiltinRoleRefNameViewer BuiltinRoleRefName = "viewer"
)
// Defines values for CustomRoleRefKind.
const (
CustomRoleRefKindRole CustomRoleRefKind = "Role"
)
// Defines values for SubjectKind.
const (
SubjectKindTeam SubjectKind = "Team"
SubjectKindUser SubjectKind = "User"
)
// BuiltinRoleRef defines model for BuiltinRoleRef.
type BuiltinRoleRef struct {
Kind BuiltinRoleRefKind `json:"kind"`
Kind string `json:"kind"`
Name BuiltinRoleRefName `json:"name"`
}
// BuiltinRoleRefKind defines model for BuiltinRoleRef.Kind.
type BuiltinRoleRefKind string
// BuiltinRoleRefName defines model for BuiltinRoleRef.Name.
type BuiltinRoleRefName string
// CustomRoleRef defines model for CustomRoleRef.
type CustomRoleRef struct {
Kind CustomRoleRefKind `json:"kind"`
Name string `json:"name"`
// NewBuiltinRoleRef creates a new BuiltinRoleRef object.
func NewBuiltinRoleRef() *BuiltinRoleRef {
return &BuiltinRoleRef{
Kind: "BuiltinRole",
}
}
// CustomRoleRefKind defines model for CustomRoleRef.Kind.
type CustomRoleRefKind string
type CustomRoleRef struct {
Kind string `json:"kind"`
Name string `json:"name"`
}
// Subject defines model for Subject.
type Subject struct {
Kind SubjectKind `json:"kind"`
// NewCustomRoleRef creates a new CustomRoleRef object.
func NewCustomRoleRef() *CustomRoleRef {
return &CustomRoleRef{
Kind: "Role",
}
}
type RoleBindingSubject struct {
Kind RoleBindingSubjectKind `json:"kind"`
// The team/user identifier name
Name string `json:"name"`
}
// SubjectKind defines model for Subject.Kind.
type SubjectKind string
// NewRoleBindingSubject creates a new RoleBindingSubject object.
func NewRoleBindingSubject() *RoleBindingSubject {
return &RoleBindingSubject{}
}
// Spec defines model for Spec.
type Spec struct {
// The role we are discussing
Role any `json:"role"`
Subject Subject `json:"subject"`
Role BuiltinRoleRefOrCustomRoleRef `json:"role"`
// The team or user that has the specified role
Subject RoleBindingSubject `json:"subject"`
}
// NewSpec creates a new Spec object.
func NewSpec() *Spec {
return &Spec{
Role: *NewBuiltinRoleRefOrCustomRoleRef(),
Subject: *NewRoleBindingSubject(),
}
}
type BuiltinRoleRefName string
const (
BuiltinRoleRefNameViewer BuiltinRoleRefName = "viewer"
BuiltinRoleRefNameEditor BuiltinRoleRefName = "editor"
BuiltinRoleRefNameAdmin BuiltinRoleRefName = "admin"
)
type RoleBindingSubjectKind string
const (
RoleBindingSubjectKindTeam RoleBindingSubjectKind = "Team"
RoleBindingSubjectKindUser RoleBindingSubjectKind = "User"
)
type BuiltinRoleRefOrCustomRoleRef struct {
BuiltinRoleRef *BuiltinRoleRef `json:"BuiltinRoleRef,omitempty"`
CustomRoleRef *CustomRoleRef `json:"CustomRoleRef,omitempty"`
}
// NewBuiltinRoleRefOrCustomRoleRef creates a new BuiltinRoleRefOrCustomRoleRef object.
func NewBuiltinRoleRefOrCustomRoleRef() *BuiltinRoleRefOrCustomRoleRef {
return &BuiltinRoleRefOrCustomRoleRef{}
}
// MarshalJSON implements a custom JSON marshalling logic to encode `BuiltinRoleRefOrCustomRoleRef` as JSON.
func (resource BuiltinRoleRefOrCustomRoleRef) MarshalJSON() ([]byte, error) {
if resource.BuiltinRoleRef != nil {
return json.Marshal(resource.BuiltinRoleRef)
}
if resource.CustomRoleRef != nil {
return json.Marshal(resource.CustomRoleRef)
}
return nil, fmt.Errorf("no value for disjunction of refs")
}
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode `BuiltinRoleRefOrCustomRoleRef` from JSON.
func (resource *BuiltinRoleRefOrCustomRoleRef) UnmarshalJSON(raw []byte) error {
if raw == nil {
return nil
}
// FIXME: this is wasteful, we need to find a more efficient way to unmarshal this.
parsedAsMap := make(map[string]any)
if err := json.Unmarshal(raw, &parsedAsMap); err != nil {
return err
}
discriminator, found := parsedAsMap["kind"]
if !found {
return errors.New("discriminator field 'kind' not found in payload")
}
switch discriminator {
case "BuiltinRole":
var builtinRoleRef BuiltinRoleRef
if err := json.Unmarshal(raw, &builtinRoleRef); err != nil {
return err
}
resource.BuiltinRoleRef = &builtinRoleRef
return nil
case "Role":
var customRoleRef CustomRoleRef
if err := json.Unmarshal(raw, &customRoleRef); err != nil {
return err
}
resource.CustomRoleRef = &customRoleRef
return nil
}
return fmt.Errorf("could not unmarshal resource with `kind = %v`", discriminator)
}

View File

@@ -7,6 +7,7 @@ replace github.com/grafana/grafana/pkg/codegen => ../../codegen
require (
cuelang.org/go v0.11.1
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d
github.com/grafana/cog v0.0.12
github.com/grafana/cuetsy v0.1.11
github.com/grafana/grafana/pkg/codegen v0.0.0-00010101000000-000000000000
)
@@ -15,8 +16,8 @@ require (
cuelabs.dev/go/oci/ociregistry v0.0.0-20240906074133-82eb438dd565 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/dave/dst v0.27.3 // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/emicklei/proto v1.13.2 // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
@@ -24,25 +25,25 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20241112170944-20d2c9ebc01d // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yalue/merged_fs v1.3.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.29.0 // indirect

View File

@@ -2,29 +2,18 @@ cuelabs.dev/go/oci/ociregistry v0.0.0-20240906074133-82eb438dd565 h1:R5wwEcbEZSB
cuelabs.dev/go/oci/ociregistry v0.0.0-20240906074133-82eb438dd565/go.mod h1:5A4xfTzHTXfeVJBU6RAUf+QrlfTCW+017q/QiW+sMLg=
cuelang.org/go v0.11.1 h1:pV+49MX1mmvDm8Qh3Za3M786cty8VKPWzQ1Ho4gZRP0=
cuelang.org/go v0.11.1/go.mod h1:PBY6XvPUswPPJ2inpvUozP9mebDVTXaeehQikhZPBz0=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dave/dst v0.27.3 h1:P1HPoMza3cMEquVf9kKy8yXsFirry4zEnWOdYPOoIzY=
github.com/dave/dst v0.27.3/go.mod h1:jHh6EOibnHgcUW3WjKHisiooEkYwqpHLBSX1iOBhEyc=
github.com/dave/jennifer v1.6.0 h1:MQ/6emI2xM7wt0tJzJzyUik2Q3Tcn2eE0vtYgh4GPVI=
github.com/dave/jennifer v1.6.0/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 h1:PRxIJD8XjimM5aTknUK9w6DHLDox2r2M3DI4i2pnd3w=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936/go.mod h1:ttYvX5qlB+mlV1okblJqcSMtR4c52UKxDiX9GRBS8+Q=
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
@@ -33,29 +22,16 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d h1:hrXbGJ5jgp6yNITzs5o+zXq0V5yT3siNJ+uM8LGwWKk=
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d/go.mod h1:zmwwM/DRyQB7pfuBjTWII3CWtxcXh8LTwAYGfDfpR6s=
github.com/grafana/cog v0.0.12 h1:MJfFUVzp0El3+zZCmUQ2Y8uzwvM3aa5zj7EOeeuG6VY=
github.com/grafana/cog v0.0.12/go.mod h1:HwJbc60fZ+viayROClLGdDwO5w/JjBOpO9wjGnAfMLc=
github.com/grafana/cuetsy v0.1.11 h1:I3IwBhF+UaQxRM79HnImtrAn8REGdb5M3+C4QrYHoWk=
github.com/grafana/cuetsy v0.1.11/go.mod h1:Ix97+CPD8ws9oSSxR3/Lf4ahU1I4Np83kjJmDVnLZvc=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -63,17 +39,14 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
@@ -88,25 +61,6 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 h1:ykgG34472DWey7TSjd8vIfNykXgjOgYJZoQbKfEeY/Q=
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1/go.mod h1:N5+lY1tiTDV3V1BeHtOxeWXHoPVeApvsvjJqegfoaz8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
@@ -124,100 +78,35 @@ github.com/protocolbuffers/txtpbfmt v0.0.0-20241112170944-20d2c9ebc01d h1:HWfigq
github.com/protocolbuffers/txtpbfmt v0.0.0-20241112170944-20d2c9ebc01d/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54VRhy1aSutx0PQg=
github.com/speakeasy-api/openapi-overlay v0.9.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
github.com/yalue/merged_fs v1.3.0 h1:qCeh9tMPNy/i8cwDsQTJ5bLr6IRxbs6meakNE5O+wyY=
github.com/yalue/merged_fs v1.3.0/go.mod h1:WqqchfVYQyclV2tnR7wtRhBddzBvLVR83Cjw9BKQw0M=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,13 +1,14 @@
package codegen
import (
"context"
"fmt"
"path/filepath"
"strings"
copenapi "cuelang.org/go/encoding/openapi"
"cuelang.org/go/cue"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/codegen/generators"
"github.com/grafana/cog"
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
)
@@ -30,20 +31,22 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
hasBackend := decl.PluginMeta.Backend
// We skip elasticsearch since we have problems with the generated file.
// This is temporal until we migrate to the new system.
if hasBackend == nil || !*hasBackend || decl.PluginMeta.Id == "elasticsearch" {
if hasBackend == nil || !*hasBackend {
return nil, nil
}
slotname := strings.ToLower(decl.SchemaInterface.Name)
byt, err := generators.GenerateTypesGo(decl.CueFile, &generators.GoConfig{
Config: &generators.OpenApiConfig{
Config: &copenapi.Config{
MaxCycleDepth: 10,
},
IsGroup: decl.SchemaInterface.IsGroup,
},
PackageName: slotname,
})
slotName := strings.ToLower(decl.SchemaInterface.Name)
cueValue := decl.CueFile.LookupPath(cue.ParsePath("lineage.schemas[0].schema"))
name, err := decl.CueFile.LookupPath(cue.MakePath(cue.Str("name"))).String()
if err != nil {
return nil, err
}
byt, err := cog.TypesFromSchema().
CUEValue(slotName, cueValue, cog.ForceEnvelope(name)).
Golang(cog.GoConfig{}).
Run(context.Background())
if err != nil {
return nil, err
}
@@ -54,6 +57,6 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
if pluginfolder == "testdata" {
pluginfolder = "testdatasource"
}
filename := fmt.Sprintf("types_%s_gen.go", slotname)
return codejen.NewFile(filepath.Join(j.root, pluginfolder, "kinds", slotname, filename), byt, j), nil
filename := fmt.Sprintf("types_%s_gen.go", slotName)
return codejen.NewFile(filepath.Join(j.root, pluginfolder, "kinds", slotName, filename), byt[0].Data, j), nil
}

View File

@@ -632,8 +632,8 @@ github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=

View File

@@ -7,436 +7,558 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for AppInsightsGroupByQueryKind.
const (
AppInsightsGroupByQueryKindAppInsightsGroupByQuery AppInsightsGroupByQueryKind = "AppInsightsGroupByQuery"
import (
json "encoding/json"
errors "errors"
fmt "fmt"
)
// Defines values for AppInsightsMetricNameQueryKind.
const (
AppInsightsMetricNameQueryKindAppInsightsMetricNameQuery AppInsightsMetricNameQueryKind = "AppInsightsMetricNameQuery"
)
// Defines values for AzureQueryType.
const (
AzureQueryTypeAzureLogAnalytics AzureQueryType = "Azure Log Analytics"
AzureQueryTypeAzureMetricNames AzureQueryType = "Azure Metric Names"
AzureQueryTypeAzureMonitor AzureQueryType = "Azure Monitor"
AzureQueryTypeAzureNamespaces AzureQueryType = "Azure Namespaces"
AzureQueryTypeAzureRegions AzureQueryType = "Azure Regions"
AzureQueryTypeAzureResourceGraph AzureQueryType = "Azure Resource Graph"
AzureQueryTypeAzureResourceGroups AzureQueryType = "Azure Resource Groups"
AzureQueryTypeAzureResourceNames AzureQueryType = "Azure Resource Names"
AzureQueryTypeAzureSubscriptions AzureQueryType = "Azure Subscriptions"
AzureQueryTypeAzureTraces AzureQueryType = "Azure Traces"
AzureQueryTypeAzureWorkspaces AzureQueryType = "Azure Workspaces"
AzureQueryTypeGrafanaTemplateVariableFunction AzureQueryType = "Grafana Template Variable Function"
AzureQueryTypeTraceql AzureQueryType = "traceql"
)
// Defines values for GrafanaTemplateVariableQueryType.
const (
GrafanaTemplateVariableQueryTypeAppInsightsGroupByQuery GrafanaTemplateVariableQueryType = "AppInsightsGroupByQuery"
GrafanaTemplateVariableQueryTypeAppInsightsMetricNameQuery GrafanaTemplateVariableQueryType = "AppInsightsMetricNameQuery"
GrafanaTemplateVariableQueryTypeMetricNamesQuery GrafanaTemplateVariableQueryType = "MetricNamesQuery"
GrafanaTemplateVariableQueryTypeMetricNamespaceQuery GrafanaTemplateVariableQueryType = "MetricNamespaceQuery"
GrafanaTemplateVariableQueryTypeResourceGroupsQuery GrafanaTemplateVariableQueryType = "ResourceGroupsQuery"
GrafanaTemplateVariableQueryTypeResourceNamesQuery GrafanaTemplateVariableQueryType = "ResourceNamesQuery"
GrafanaTemplateVariableQueryTypeSubscriptionsQuery GrafanaTemplateVariableQueryType = "SubscriptionsQuery"
GrafanaTemplateVariableQueryTypeUnknownQuery GrafanaTemplateVariableQueryType = "UnknownQuery"
GrafanaTemplateVariableQueryTypeWorkspacesQuery GrafanaTemplateVariableQueryType = "WorkspacesQuery"
)
// Defines values for MetricDefinitionsQueryKind.
const (
MetricDefinitionsQueryKindMetricDefinitionsQuery MetricDefinitionsQueryKind = "MetricDefinitionsQuery"
)
// Defines values for MetricNamesQueryKind.
const (
MetricNamesQueryKindMetricNamesQuery MetricNamesQueryKind = "MetricNamesQuery"
)
// Defines values for MetricNamespaceQueryKind.
const (
MetricNamespaceQueryKindMetricNamespaceQuery MetricNamespaceQueryKind = "MetricNamespaceQuery"
)
// Defines values for ResourceGroupsQueryKind.
const (
ResourceGroupsQueryKindResourceGroupsQuery ResourceGroupsQueryKind = "ResourceGroupsQuery"
)
// Defines values for ResourceNamesQueryKind.
const (
ResourceNamesQueryKindResourceNamesQuery ResourceNamesQueryKind = "ResourceNamesQuery"
)
// Defines values for ResultFormat.
const (
ResultFormatLogs ResultFormat = "logs"
ResultFormatTable ResultFormat = "table"
ResultFormatTimeSeries ResultFormat = "time_series"
ResultFormatTrace ResultFormat = "trace"
)
// Defines values for SubscriptionsQueryKind.
const (
SubscriptionsQueryKindSubscriptionsQuery SubscriptionsQueryKind = "SubscriptionsQuery"
)
// Defines values for UnknownQueryKind.
const (
UnknownQueryKindUnknownQuery UnknownQueryKind = "UnknownQuery"
)
// Defines values for WorkspacesQueryKind.
const (
WorkspacesQueryKindWorkspacesQuery WorkspacesQueryKind = "WorkspacesQuery"
)
// AppInsightsGroupByQuery defines model for AppInsightsGroupByQuery.
type AppInsightsGroupByQuery struct {
Kind *AppInsightsGroupByQueryKind `json:"kind,omitempty"`
MetricName *string `json:"metricName,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
}
// AppInsightsGroupByQueryKind defines model for AppInsightsGroupByQuery.Kind.
type AppInsightsGroupByQueryKind string
// AppInsightsMetricNameQuery defines model for AppInsightsMetricNameQuery.
type AppInsightsMetricNameQuery struct {
Kind *AppInsightsMetricNameQueryKind `json:"kind,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
}
// AppInsightsMetricNameQueryKind defines model for AppInsightsMetricNameQuery.Kind.
type AppInsightsMetricNameQueryKind string
// Azure Monitor Logs sub-query properties
type AzureLogsQuery struct {
// If set to true the query will be run as a basic logs query
BasicLogsQuery *bool `json:"basicLogsQuery,omitempty"`
// If set to true the dashboard time range will be used as a filter for the query. Otherwise the query time ranges will be used. Defaults to false.
DashboardTime *bool `json:"dashboardTime,omitempty"`
// @deprecated Use dashboardTime instead
IntersectTime *bool `json:"intersectTime,omitempty"`
// KQL query to be executed.
Query *string `json:"query,omitempty"`
// @deprecated Use resources instead
Resource *string `json:"resource,omitempty"`
// Array of resource URIs to be queried.
Resources []string `json:"resources,omitempty"`
ResultFormat *ResultFormat `json:"resultFormat,omitempty"`
// If dashboardTime is set to true this value dictates which column the time filter will be applied to. Defaults to the first tables timeSpan column, the first datetime column found, or TimeGenerated
TimeColumn *string `json:"timeColumn,omitempty"`
// Workspace ID. This was removed in Grafana 8, but remains for backwards compat.
Workspace *string `json:"workspace,omitempty"`
}
// AzureMetricDimension defines model for AzureMetricDimension.
type AzureMetricDimension struct {
// Name of Dimension to be filtered on.
Dimension *string `json:"dimension,omitempty"`
// @deprecated filter is deprecated in favour of filters to support multiselect.
Filter *string `json:"filter,omitempty"`
// Values to match with the filter.
Filters []string `json:"filters,omitempty"`
// String denoting the filter operation. Supports 'eq' - equals,'ne' - not equals, 'sw' - starts with. Note that some dimensions may not support all operators.
Operator *string `json:"operator,omitempty"`
}
// AzureMetricQuery defines model for AzureMetricQuery.
type AzureMetricQuery struct {
// The aggregation to be used within the query. Defaults to the primaryAggregationType defined by the metric.
Aggregation *string `json:"aggregation,omitempty"`
// Aliases can be set to modify the legend labels. e.g. {{ resourceGroup }}. See docs for more detail.
Alias *string `json:"alias,omitempty"`
// Time grains that are supported by the metric.
AllowedTimeGrainsMs []int64 `json:"allowedTimeGrainsMs,omitempty"`
// Used as the value for the metricNamespace property when it's different from the resource namespace.
CustomNamespace *string `json:"customNamespace,omitempty"`
// @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration
Dimension *string `json:"dimension,omitempty"`
// @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration
DimensionFilter *string `json:"dimensionFilter,omitempty"`
// Filters to reduce the set of data returned. Dimensions that can be filtered on are defined by the metric.
DimensionFilters []AzureMetricDimension `json:"dimensionFilters,omitempty"`
// @deprecated Use metricNamespace instead
MetricDefinition *string `json:"metricDefinition,omitempty"`
// The metric to query data for within the specified metricNamespace. e.g. UsedCapacity
MetricName *string `json:"metricName,omitempty"`
// metricNamespace is used as the resource type (or resource namespace).
// It's usually equal to the target metric namespace. e.g. microsoft.storage/storageaccounts
// Kept the name of the variable as metricNamespace to avoid backward incompatibility issues.
MetricNamespace *string `json:"metricNamespace,omitempty"`
// The Azure region containing the resource(s).
Region *string `json:"region,omitempty"`
// @deprecated Use resources instead
ResourceGroup *string `json:"resourceGroup,omitempty"`
// @deprecated Use resources instead
ResourceName *string `json:"resourceName,omitempty"`
// @deprecated Use resourceGroup, resourceName and metricNamespace instead
ResourceUri *string `json:"resourceUri,omitempty"`
// Array of resource URIs to be queried.
Resources []AzureMonitorResource `json:"resources,omitempty"`
// The granularity of data points to be queried. Defaults to auto.
TimeGrain *string `json:"timeGrain,omitempty"`
// TimeGrainUnit @deprecated
TimeGrainUnit *string `json:"timeGrainUnit,omitempty"`
// Maximum number of records to return. Defaults to 10.
Top *string `json:"top,omitempty"`
}
// AzureMonitorDataQuery defines model for AzureMonitorDataQuery.
type AzureMonitorDataQuery = map[string]any
// AzureMonitorQuery defines model for AzureMonitorQuery.
type AzureMonitorQuery struct {
// Azure Monitor Logs sub-query properties
AzureLogAnalytics *AzureLogsQuery `json:"azureLogAnalytics,omitempty"`
AzureMonitor *AzureMetricQuery `json:"azureMonitor,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// Azure subscription containing the resource(s) to be queried.
Subscription *string `json:"subscription,omitempty"`
// Subscriptions to be queried via Azure Resource Graph.
Subscriptions []string `json:"subscriptions,omitempty"`
// Azure Monitor Metrics sub-query properties.
AzureMonitor *AzureMetricQuery `json:"azureMonitor,omitempty"`
// Azure Monitor Logs sub-query properties.
AzureLogAnalytics *AzureLogsQuery `json:"azureLogAnalytics,omitempty"`
// Azure Resource Graph sub-query properties.
AzureResourceGraph *AzureResourceGraphQuery `json:"azureResourceGraph,omitempty"`
// Application Insights Traces sub-query properties
// Application Insights Traces sub-query properties.
AzureTraces *AzureTracesQuery `json:"azureTraces,omitempty"`
// @deprecated Legacy template variable support.
GrafanaTemplateVariableFn *GrafanaTemplateVariableQuery `json:"grafanaTemplateVariableFn,omitempty"`
// Template variables params. These exist for backwards compatiblity with legacy template variables.
ResourceGroup *string `json:"resourceGroup,omitempty"`
Namespace *string `json:"namespace,omitempty"`
Resource *string `json:"resource,omitempty"`
Region *string `json:"region,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
GrafanaTemplateVariableFn *any `json:"grafanaTemplateVariableFn,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
Namespace *string `json:"namespace,omitempty"`
Datasource any `json:"datasource,omitempty"`
// Used only for exemplar queries from Prometheus
Query *string `json:"query,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
Region *string `json:"region,omitempty"`
Resource *string `json:"resource,omitempty"`
// Template variables params. These exist for backwards compatiblity with legacy template variables.
ResourceGroup *string `json:"resourceGroup,omitempty"`
// Azure subscription containing the resource(s) to be queried.
Subscription *string `json:"subscription,omitempty"`
// Subscriptions to be queried via Azure Resource Graph.
Subscriptions []string `json:"subscriptions,omitempty"`
}
// AzureMonitorResource defines model for AzureMonitorResource.
type AzureMonitorResource struct {
MetricNamespace *string `json:"metricNamespace,omitempty"`
Region *string `json:"region,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
Subscription *string `json:"subscription,omitempty"`
// NewAzureMonitorQuery creates a new AzureMonitorQuery object.
func NewAzureMonitorQuery() *AzureMonitorQuery {
return &AzureMonitorQuery{}
}
// Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated
type AzureQueryType string
// AzureResourceGraphQuery defines model for AzureResourceGraphQuery.
type AzureResourceGraphQuery struct {
// Azure Resource Graph KQL query to be executed.
Query *string `json:"query,omitempty"`
const (
AzureQueryTypeAzureMonitor AzureQueryType = "Azure Monitor"
AzureQueryTypeLogAnalytics AzureQueryType = "Azure Log Analytics"
AzureQueryTypeAzureResourceGraph AzureQueryType = "Azure Resource Graph"
AzureQueryTypeAzureTraces AzureQueryType = "Azure Traces"
AzureQueryTypeSubscriptionsQuery AzureQueryType = "Azure Subscriptions"
AzureQueryTypeResourceGroupsQuery AzureQueryType = "Azure Resource Groups"
AzureQueryTypeNamespacesQuery AzureQueryType = "Azure Namespaces"
AzureQueryTypeResourceNamesQuery AzureQueryType = "Azure Resource Names"
AzureQueryTypeMetricNamesQuery AzureQueryType = "Azure Metric Names"
AzureQueryTypeWorkspacesQuery AzureQueryType = "Azure Workspaces"
AzureQueryTypeLocationsQuery AzureQueryType = "Azure Regions"
AzureQueryTypeGrafanaTemplateVariableFn AzureQueryType = "Grafana Template Variable Function"
AzureQueryTypeTraceExemplar AzureQueryType = "traceql"
)
// Specifies the format results should be returned as. Defaults to table.
ResultFormat *string `json:"resultFormat,omitempty"`
type AzureMetricQuery struct {
// Array of resource URIs to be queried.
Resources []AzureMonitorResource `json:"resources,omitempty"`
// metricNamespace is used as the resource type (or resource namespace).
// It's usually equal to the target metric namespace. e.g. microsoft.storage/storageaccounts
// Kept the name of the variable as metricNamespace to avoid backward incompatibility issues.
MetricNamespace *string `json:"metricNamespace,omitempty"`
// Used as the value for the metricNamespace property when it's different from the resource namespace.
CustomNamespace *string `json:"customNamespace,omitempty"`
// The metric to query data for within the specified metricNamespace. e.g. UsedCapacity
MetricName *string `json:"metricName,omitempty"`
// The Azure region containing the resource(s).
Region *string `json:"region,omitempty"`
// The granularity of data points to be queried. Defaults to auto.
TimeGrain *string `json:"timeGrain,omitempty"`
// The aggregation to be used within the query. Defaults to the primaryAggregationType defined by the metric.
Aggregation *string `json:"aggregation,omitempty"`
// Filters to reduce the set of data returned. Dimensions that can be filtered on are defined by the metric.
DimensionFilters []AzureMetricDimension `json:"dimensionFilters,omitempty"`
// Maximum number of records to return. Defaults to 10.
Top *string `json:"top,omitempty"`
// Time grains that are supported by the metric.
AllowedTimeGrainsMs []int64 `json:"allowedTimeGrainsMs,omitempty"`
// Aliases can be set to modify the legend labels. e.g. {{ resourceGroup }}. See docs for more detail.
Alias *string `json:"alias,omitempty"`
// @deprecated
TimeGrainUnit *string `json:"timeGrainUnit,omitempty"`
// @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration
Dimension *string `json:"dimension,omitempty"`
// @deprecated This property was migrated to dimensionFilters and should only be accessed in the migration
DimensionFilter *string `json:"dimensionFilter,omitempty"`
// @deprecated Use metricNamespace instead
MetricDefinition *string `json:"metricDefinition,omitempty"`
// @deprecated Use resourceGroup, resourceName and metricNamespace instead
ResourceUri *string `json:"resourceUri,omitempty"`
// @deprecated Use resources instead
ResourceGroup *string `json:"resourceGroup,omitempty"`
// @deprecated Use resources instead
ResourceName *string `json:"resourceName,omitempty"`
}
// AzureTracesFilter defines model for AzureTracesFilter.
type AzureTracesFilter struct {
// Values to filter by.
Filters []string `json:"filters"`
// NewAzureMetricQuery creates a new AzureMetricQuery object.
func NewAzureMetricQuery() *AzureMetricQuery {
return &AzureMetricQuery{}
}
// Comparison operator to use. Either equals or not equals.
Operation string `json:"operation"`
// Azure Monitor Logs sub-query properties
type AzureLogsQuery struct {
// KQL query to be executed.
Query *string `json:"query,omitempty"`
// Specifies the format results should be returned as.
ResultFormat *ResultFormat `json:"resultFormat,omitempty"`
// Array of resource URIs to be queried.
Resources []string `json:"resources,omitempty"`
// If set to true the dashboard time range will be used as a filter for the query. Otherwise the query time ranges will be used. Defaults to false.
DashboardTime *bool `json:"dashboardTime,omitempty"`
// If dashboardTime is set to true this value dictates which column the time filter will be applied to. Defaults to the first tables timeSpan column, the first datetime column found, or TimeGenerated
TimeColumn *string `json:"timeColumn,omitempty"`
// If set to true the query will be run as a basic logs query
BasicLogsQuery *bool `json:"basicLogsQuery,omitempty"`
// Workspace ID. This was removed in Grafana 8, but remains for backwards compat.
Workspace *string `json:"workspace,omitempty"`
// @deprecated Use resources instead
Resource *string `json:"resource,omitempty"`
// @deprecated Use dashboardTime instead
IntersectTime *bool `json:"intersectTime,omitempty"`
}
// Property name, auto-populated based on available traces.
Property string `json:"property"`
// NewAzureLogsQuery creates a new AzureLogsQuery object.
func NewAzureLogsQuery() *AzureLogsQuery {
return &AzureLogsQuery{}
}
// Application Insights Traces sub-query properties
type AzureTracesQuery struct {
// Filters for property values.
Filters []AzureTracesFilter `json:"filters,omitempty"`
// Specifies the format results should be returned as.
ResultFormat *ResultFormat `json:"resultFormat,omitempty"`
// Array of resource URIs to be queried.
Resources []string `json:"resources,omitempty"`
// Operation ID. Used only for Traces queries.
OperationId *string `json:"operationId,omitempty"`
// KQL query to be executed.
Query *string `json:"query,omitempty"`
// Array of resource URIs to be queried.
Resources []string `json:"resources,omitempty"`
ResultFormat *ResultFormat `json:"resultFormat,omitempty"`
// Types of events to filter by.
TraceTypes []string `json:"traceTypes,omitempty"`
// Filters for property values.
Filters []AzureTracesFilter `json:"filters,omitempty"`
// KQL query to be executed.
Query *string `json:"query,omitempty"`
}
// BaseGrafanaTemplateVariableQuery defines model for BaseGrafanaTemplateVariableQuery.
// NewAzureTracesQuery creates a new AzureTracesQuery object.
func NewAzureTracesQuery() *AzureTracesQuery {
return &AzureTracesQuery{}
}
type AzureTracesFilter struct {
// Property name, auto-populated based on available traces.
Property string `json:"property"`
// Comparison operator to use. Either equals or not equals.
Operation string `json:"operation"`
// Values to filter by.
Filters []string `json:"filters"`
}
// NewAzureTracesFilter creates a new AzureTracesFilter object.
func NewAzureTracesFilter() *AzureTracesFilter {
return &AzureTracesFilter{}
}
type ResultFormat string
const (
ResultFormatTable ResultFormat = "table"
ResultFormatTimeSeries ResultFormat = "time_series"
ResultFormatTrace ResultFormat = "trace"
ResultFormatLogs ResultFormat = "logs"
)
type AzureResourceGraphQuery struct {
// Azure Resource Graph KQL query to be executed.
Query *string `json:"query,omitempty"`
// Specifies the format results should be returned as. Defaults to table.
ResultFormat *string `json:"resultFormat,omitempty"`
}
// NewAzureResourceGraphQuery creates a new AzureResourceGraphQuery object.
func NewAzureResourceGraphQuery() *AzureResourceGraphQuery {
return &AzureResourceGraphQuery{}
}
type AzureMonitorResource struct {
Subscription *string `json:"subscription,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
Region *string `json:"region,omitempty"`
}
// NewAzureMonitorResource creates a new AzureMonitorResource object.
func NewAzureMonitorResource() *AzureMonitorResource {
return &AzureMonitorResource{}
}
type AzureMetricDimension struct {
// Name of Dimension to be filtered on.
Dimension *string `json:"dimension,omitempty"`
// String denoting the filter operation. Supports 'eq' - equals,'ne' - not equals, 'sw' - starts with. Note that some dimensions may not support all operators.
Operator *string `json:"operator,omitempty"`
// Values to match with the filter.
Filters []string `json:"filters,omitempty"`
// @deprecated filter is deprecated in favour of filters to support multiselect.
Filter *string `json:"filter,omitempty"`
}
// NewAzureMetricDimension creates a new AzureMetricDimension object.
func NewAzureMetricDimension() *AzureMetricDimension {
return &AzureMetricDimension{}
}
type GrafanaTemplateVariableQueryType string
const (
GrafanaTemplateVariableQueryTypeAppInsightsMetricNameQuery GrafanaTemplateVariableQueryType = "AppInsightsMetricNameQuery"
GrafanaTemplateVariableQueryTypeAppInsightsGroupByQuery GrafanaTemplateVariableQueryType = "AppInsightsGroupByQuery"
GrafanaTemplateVariableQueryTypeSubscriptionsQuery GrafanaTemplateVariableQueryType = "SubscriptionsQuery"
GrafanaTemplateVariableQueryTypeResourceGroupsQuery GrafanaTemplateVariableQueryType = "ResourceGroupsQuery"
GrafanaTemplateVariableQueryTypeResourceNamesQuery GrafanaTemplateVariableQueryType = "ResourceNamesQuery"
GrafanaTemplateVariableQueryTypeMetricNamespaceQuery GrafanaTemplateVariableQueryType = "MetricNamespaceQuery"
GrafanaTemplateVariableQueryTypeMetricNamesQuery GrafanaTemplateVariableQueryType = "MetricNamesQuery"
GrafanaTemplateVariableQueryTypeWorkspacesQuery GrafanaTemplateVariableQueryType = "WorkspacesQuery"
GrafanaTemplateVariableQueryTypeUnknownQuery GrafanaTemplateVariableQueryType = "UnknownQuery"
)
type BaseGrafanaTemplateVariableQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
}
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
// NewBaseGrafanaTemplateVariableQuery creates a new BaseGrafanaTemplateVariableQuery object.
func NewBaseGrafanaTemplateVariableQuery() *BaseGrafanaTemplateVariableQuery {
return &BaseGrafanaTemplateVariableQuery{}
}
// GrafanaTemplateVariableQueryType defines model for GrafanaTemplateVariableQueryType.
type GrafanaTemplateVariableQueryType string
type UnknownQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
}
// NewUnknownQuery creates a new UnknownQuery object.
func NewUnknownQuery() *UnknownQuery {
return &UnknownQuery{
Kind: "UnknownQuery",
}
}
type AppInsightsMetricNameQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
}
// NewAppInsightsMetricNameQuery creates a new AppInsightsMetricNameQuery object.
func NewAppInsightsMetricNameQuery() *AppInsightsMetricNameQuery {
return &AppInsightsMetricNameQuery{
Kind: "AppInsightsMetricNameQuery",
}
}
type AppInsightsGroupByQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
MetricName string `json:"metricName"`
}
// NewAppInsightsGroupByQuery creates a new AppInsightsGroupByQuery object.
func NewAppInsightsGroupByQuery() *AppInsightsGroupByQuery {
return &AppInsightsGroupByQuery{
Kind: "AppInsightsGroupByQuery",
}
}
type SubscriptionsQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
}
// NewSubscriptionsQuery creates a new SubscriptionsQuery object.
func NewSubscriptionsQuery() *SubscriptionsQuery {
return &SubscriptionsQuery{
Kind: "SubscriptionsQuery",
}
}
type ResourceGroupsQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
}
// NewResourceGroupsQuery creates a new ResourceGroupsQuery object.
func NewResourceGroupsQuery() *ResourceGroupsQuery {
return &ResourceGroupsQuery{
Kind: "ResourceGroupsQuery",
}
}
type ResourceNamesQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
ResourceGroup string `json:"resourceGroup"`
MetricNamespace string `json:"metricNamespace"`
}
// NewResourceNamesQuery creates a new ResourceNamesQuery object.
func NewResourceNamesQuery() *ResourceNamesQuery {
return &ResourceNamesQuery{
Kind: "ResourceNamesQuery",
}
}
type MetricNamespaceQuery struct {
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
ResourceGroup string `json:"resourceGroup"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
}
// NewMetricNamespaceQuery creates a new MetricNamespaceQuery object.
func NewMetricNamespaceQuery() *MetricNamespaceQuery {
return &MetricNamespaceQuery{
Kind: "MetricNamespaceQuery",
}
}
// @deprecated Use MetricNamespaceQuery instead
type MetricDefinitionsQuery struct {
Kind *MetricDefinitionsQueryKind `json:"kind,omitempty"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
Subscription *string `json:"subscription,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
ResourceGroup string `json:"resourceGroup"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
}
// MetricDefinitionsQueryKind defines model for MetricDefinitionsQuery.Kind.
type MetricDefinitionsQueryKind string
// NewMetricDefinitionsQuery creates a new MetricDefinitionsQuery object.
func NewMetricDefinitionsQuery() *MetricDefinitionsQuery {
return &MetricDefinitionsQuery{
Kind: "MetricDefinitionsQuery",
}
}
// MetricNamesQuery defines model for MetricNamesQuery.
type MetricNamesQuery struct {
Kind *MetricNamesQueryKind `json:"kind,omitempty"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
Subscription *string `json:"subscription,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
ResourceGroup string `json:"resourceGroup"`
ResourceName string `json:"resourceName"`
MetricNamespace string `json:"metricNamespace"`
}
// MetricNamesQueryKind defines model for MetricNamesQuery.Kind.
type MetricNamesQueryKind string
// MetricNamespaceQuery defines model for MetricNamespaceQuery.
type MetricNamespaceQuery struct {
Kind *MetricNamespaceQueryKind `json:"kind,omitempty"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
ResourceName *string `json:"resourceName,omitempty"`
Subscription *string `json:"subscription,omitempty"`
// NewMetricNamesQuery creates a new MetricNamesQuery object.
func NewMetricNamesQuery() *MetricNamesQuery {
return &MetricNamesQuery{
Kind: "MetricNamesQuery",
}
}
// MetricNamespaceQueryKind defines model for MetricNamespaceQuery.Kind.
type MetricNamespaceQueryKind string
// ResourceGroupsQuery defines model for ResourceGroupsQuery.
type ResourceGroupsQuery struct {
Kind *ResourceGroupsQueryKind `json:"kind,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
Subscription *string `json:"subscription,omitempty"`
}
// ResourceGroupsQueryKind defines model for ResourceGroupsQuery.Kind.
type ResourceGroupsQueryKind string
// ResourceNamesQuery defines model for ResourceNamesQuery.
type ResourceNamesQuery struct {
Kind *ResourceNamesQueryKind `json:"kind,omitempty"`
MetricNamespace *string `json:"metricNamespace,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty"`
Subscription *string `json:"subscription,omitempty"`
}
// ResourceNamesQueryKind defines model for ResourceNamesQuery.Kind.
type ResourceNamesQueryKind string
// ResultFormat defines model for ResultFormat.
type ResultFormat string
// SubscriptionsQuery defines model for SubscriptionsQuery.
type SubscriptionsQuery struct {
Kind *SubscriptionsQueryKind `json:"kind,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
}
// SubscriptionsQueryKind defines model for SubscriptionsQuery.Kind.
type SubscriptionsQueryKind string
// UnknownQuery defines model for UnknownQuery.
type UnknownQuery struct {
Kind *UnknownQueryKind `json:"kind,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
}
// UnknownQueryKind defines model for UnknownQuery.Kind.
type UnknownQueryKind string
// WorkspacesQuery defines model for WorkspacesQuery.
type WorkspacesQuery struct {
Kind *WorkspacesQueryKind `json:"kind,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
Subscription *string `json:"subscription,omitempty"`
RawQuery *string `json:"rawQuery,omitempty"`
Kind string `json:"kind"`
Subscription string `json:"subscription"`
}
// WorkspacesQueryKind defines model for WorkspacesQuery.Kind.
type WorkspacesQueryKind string
// NewWorkspacesQuery creates a new WorkspacesQuery object.
func NewWorkspacesQuery() *WorkspacesQuery {
return &WorkspacesQuery{
Kind: "WorkspacesQuery",
}
}
type GrafanaTemplateVariableQuery = AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery
// NewGrafanaTemplateVariableQuery creates a new GrafanaTemplateVariableQuery object.
func NewGrafanaTemplateVariableQuery() *GrafanaTemplateVariableQuery {
return NewAppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery()
}
type AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery struct {
AppInsightsMetricNameQuery *AppInsightsMetricNameQuery `json:"AppInsightsMetricNameQuery,omitempty"`
AppInsightsGroupByQuery *AppInsightsGroupByQuery `json:"AppInsightsGroupByQuery,omitempty"`
SubscriptionsQuery *SubscriptionsQuery `json:"SubscriptionsQuery,omitempty"`
ResourceGroupsQuery *ResourceGroupsQuery `json:"ResourceGroupsQuery,omitempty"`
ResourceNamesQuery *ResourceNamesQuery `json:"ResourceNamesQuery,omitempty"`
MetricNamespaceQuery *MetricNamespaceQuery `json:"MetricNamespaceQuery,omitempty"`
MetricDefinitionsQuery *MetricDefinitionsQuery `json:"MetricDefinitionsQuery,omitempty"`
MetricNamesQuery *MetricNamesQuery `json:"MetricNamesQuery,omitempty"`
WorkspacesQuery *WorkspacesQuery `json:"WorkspacesQuery,omitempty"`
UnknownQuery *UnknownQuery `json:"UnknownQuery,omitempty"`
}
// NewAppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery creates a new AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery object.
func NewAppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery() *AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery {
return &AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery{}
}
// MarshalJSON implements a custom JSON marshalling logic to encode `AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery` as JSON.
func (resource AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery) MarshalJSON() ([]byte, error) {
if resource.AppInsightsMetricNameQuery != nil {
return json.Marshal(resource.AppInsightsMetricNameQuery)
}
if resource.AppInsightsGroupByQuery != nil {
return json.Marshal(resource.AppInsightsGroupByQuery)
}
if resource.SubscriptionsQuery != nil {
return json.Marshal(resource.SubscriptionsQuery)
}
if resource.ResourceGroupsQuery != nil {
return json.Marshal(resource.ResourceGroupsQuery)
}
if resource.ResourceNamesQuery != nil {
return json.Marshal(resource.ResourceNamesQuery)
}
if resource.MetricNamespaceQuery != nil {
return json.Marshal(resource.MetricNamespaceQuery)
}
if resource.MetricDefinitionsQuery != nil {
return json.Marshal(resource.MetricDefinitionsQuery)
}
if resource.MetricNamesQuery != nil {
return json.Marshal(resource.MetricNamesQuery)
}
if resource.WorkspacesQuery != nil {
return json.Marshal(resource.WorkspacesQuery)
}
if resource.UnknownQuery != nil {
return json.Marshal(resource.UnknownQuery)
}
return nil, fmt.Errorf("no value for disjunction of refs")
}
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode `AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery` from JSON.
func (resource *AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery) UnmarshalJSON(raw []byte) error {
if raw == nil {
return nil
}
// FIXME: this is wasteful, we need to find a more efficient way to unmarshal this.
parsedAsMap := make(map[string]any)
if err := json.Unmarshal(raw, &parsedAsMap); err != nil {
return err
}
discriminator, found := parsedAsMap["kind"]
if !found {
return errors.New("discriminator field 'kind' not found in payload")
}
switch discriminator {
case "AppInsightsGroupByQuery":
var appInsightsGroupByQuery AppInsightsGroupByQuery
if err := json.Unmarshal(raw, &appInsightsGroupByQuery); err != nil {
return err
}
resource.AppInsightsGroupByQuery = &appInsightsGroupByQuery
return nil
case "AppInsightsMetricNameQuery":
var appInsightsMetricNameQuery AppInsightsMetricNameQuery
if err := json.Unmarshal(raw, &appInsightsMetricNameQuery); err != nil {
return err
}
resource.AppInsightsMetricNameQuery = &appInsightsMetricNameQuery
return nil
case "MetricDefinitionsQuery":
var metricDefinitionsQuery MetricDefinitionsQuery
if err := json.Unmarshal(raw, &metricDefinitionsQuery); err != nil {
return err
}
resource.MetricDefinitionsQuery = &metricDefinitionsQuery
return nil
case "MetricNamesQuery":
var metricNamesQuery MetricNamesQuery
if err := json.Unmarshal(raw, &metricNamesQuery); err != nil {
return err
}
resource.MetricNamesQuery = &metricNamesQuery
return nil
case "MetricNamespaceQuery":
var metricNamespaceQuery MetricNamespaceQuery
if err := json.Unmarshal(raw, &metricNamespaceQuery); err != nil {
return err
}
resource.MetricNamespaceQuery = &metricNamespaceQuery
return nil
case "ResourceGroupsQuery":
var resourceGroupsQuery ResourceGroupsQuery
if err := json.Unmarshal(raw, &resourceGroupsQuery); err != nil {
return err
}
resource.ResourceGroupsQuery = &resourceGroupsQuery
return nil
case "ResourceNamesQuery":
var resourceNamesQuery ResourceNamesQuery
if err := json.Unmarshal(raw, &resourceNamesQuery); err != nil {
return err
}
resource.ResourceNamesQuery = &resourceNamesQuery
return nil
case "SubscriptionsQuery":
var subscriptionsQuery SubscriptionsQuery
if err := json.Unmarshal(raw, &subscriptionsQuery); err != nil {
return err
}
resource.SubscriptionsQuery = &subscriptionsQuery
return nil
case "UnknownQuery":
var unknownQuery UnknownQuery
if err := json.Unmarshal(raw, &unknownQuery); err != nil {
return err
}
resource.UnknownQuery = &unknownQuery
return nil
case "WorkspacesQuery":
var workspacesQuery WorkspacesQuery
if err := json.Unmarshal(raw, &workspacesQuery); err != nil {
return err
}
resource.WorkspacesQuery = &workspacesQuery
return nil
}
return fmt.Errorf("could not unmarshal resource with `kind = %v`", discriminator)
}

View File

@@ -80,7 +80,7 @@ func (e *AzureLogAnalyticsDatasource) GetBasicLogsUsage(ctx context.Context, url
},
TimeColumn: "TimeGenerated",
Resources: []string{payload.Resource},
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
URL: getApiURL(payload.Resource, false, false),
}
@@ -170,7 +170,7 @@ func buildLogAnalyticsQuery(query backend.DataQuery, dsInfo types.DatasourceInfo
basicLogsQuery := false
basicLogsEnabled := false
resultFormat := ParseResultFormat(azureLogAnalyticsTarget.ResultFormat, dataquery.AzureQueryTypeAzureLogAnalytics)
resultFormat := ParseResultFormat(azureLogAnalyticsTarget.ResultFormat, dataquery.AzureQueryTypeLogAnalytics)
basicLogsQueryFlag := false
if azureLogAnalyticsTarget.BasicLogsQuery != nil {
@@ -238,7 +238,7 @@ func (e *AzureLogAnalyticsDatasource) buildQuery(ctx context.Context, query back
return nil, fmt.Errorf("failed to compile Application Insights regex")
}
if query.QueryType == string(dataquery.AzureQueryTypeAzureLogAnalytics) {
if query.QueryType == string(dataquery.AzureQueryTypeLogAnalytics) {
azureLogAnalyticsQuery, err = buildLogAnalyticsQuery(query, dsInfo, appInsightsRegExp, fromAlert)
if err != nil {
errorMessage := fmt.Errorf("failed to build azure log analytics query: %w", err)
@@ -246,8 +246,8 @@ func (e *AzureLogAnalyticsDatasource) buildQuery(ctx context.Context, query back
}
}
if query.QueryType == string(dataquery.AzureQueryTypeAzureTraces) || query.QueryType == string(dataquery.AzureQueryTypeTraceql) {
if query.QueryType == string(dataquery.AzureQueryTypeTraceql) {
if query.QueryType == string(dataquery.AzureQueryTypeAzureTraces) || query.QueryType == string(dataquery.AzureQueryTypeTraceExemplar) {
if query.QueryType == string(dataquery.AzureQueryTypeTraceExemplar) {
cfg := backend.GrafanaConfigFromContext(ctx)
hasPromExemplarsToggle := cfg.FeatureToggles().IsEnabled("azureMonitorPrometheusExemplars")
if !hasPromExemplarsToggle {
@@ -346,7 +346,7 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, query *A
// Set the preferred visualization
switch query.ResultFormat {
case dataquery.ResultFormatTrace:
if query.QueryType == dataquery.AzureQueryTypeAzureTraces || query.QueryType == dataquery.AzureQueryTypeTraceql {
if query.QueryType == dataquery.AzureQueryTypeAzureTraces || query.QueryType == dataquery.AzureQueryTypeTraceExemplar {
frame.Meta.PreferredVisualization = data.VisTypeTrace
}
case dataquery.ResultFormatTable:
@@ -427,7 +427,7 @@ func addTraceDataLinksToFields(query *AzureLogAnalyticsQuery, azurePortalBaseUrl
queryJSONModel.AzureTraces.OperationId = &traceIdVariable
}
logsQueryType := string(dataquery.AzureQueryTypeAzureLogAnalytics)
logsQueryType := string(dataquery.AzureQueryTypeLogAnalytics)
logsJSONModel := dataquery.AzureMonitorQuery{
QueryType: &logsQueryType,
AzureLogAnalytics: &dataquery.AzureLogsQuery{
@@ -501,7 +501,7 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, queryUR
body["query_datetimescope_column"] = query.TimeColumn
}
if len(query.Resources) > 1 && query.QueryType == dataquery.AzureQueryTypeAzureLogAnalytics && !query.AppInsightsQuery {
if len(query.Resources) > 1 && query.QueryType == dataquery.AzureQueryTypeLogAnalytics && !query.AppInsightsQuery {
str := strings.ToLower(query.Resources[0])
if strings.Contains(str, "microsoft.operationalinsights/workspaces") {

View File

@@ -111,7 +111,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -129,7 +129,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf | where ['TimeGenerated'] >= datetime('2018-03-15T13:00:00Z') and ['TimeGenerated'] <= datetime('2018-03-15T13:34:00Z') | where ['Computer'] in ('comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, 34000ms), Computer",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/AppInsightsTestDataWorkspace"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
}),
@@ -148,7 +148,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -164,7 +164,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
Query: "Perf",
Resources: []string{},
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
}),
@@ -183,7 +183,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -199,7 +199,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
Query: "Perf",
Resources: []string{},
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
}),
@@ -219,7 +219,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -236,7 +236,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
Query: "Perf",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/AppInsightsTestDataWorkspace"},
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
}),
@@ -257,7 +257,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -275,7 +275,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/AppInsightsTestDataWorkspace", "/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/AppInsightsTestDataWorkspace2"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
}),
@@ -297,7 +297,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -316,7 +316,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/AppInsightsTestDataWorkspace"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: true,
TimeColumn: "TimeGenerated",
@@ -341,7 +341,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -361,7 +361,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.OperationalInsights/workspaces/TestDataWorkspace"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: true,
BasicLogs: true,
@@ -387,7 +387,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: nil,
Err: require.Error,
@@ -410,7 +410,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: nil,
Err: require.Error,
@@ -433,7 +433,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: nil,
Err: require.Error,
@@ -456,7 +456,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: nil,
Err: require.Error,
@@ -477,7 +477,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -495,7 +495,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf | where ['TimeGenerated'] >= datetime('2018-03-15T13:00:00Z') and ['TimeGenerated'] <= datetime('2018-03-15T13:34:00Z') | where ['Computer'] in ('comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, 34000ms), Computer",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.Insights/components/AppInsightsTestDataWorkspace"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: true,
DashboardTime: false,
}),
@@ -516,7 +516,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
}`, dataquery.ResultFormatTimeSeries)),
RefID: "A",
TimeRange: timeRange,
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
QueryType: string(dataquery.AzureQueryTypeLogAnalytics),
},
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
RefID: "A",
@@ -534,7 +534,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
Query: "Perf | where ['TimeGenerated'] >= datetime('2018-03-15T13:00:00Z') and ['TimeGenerated'] <= datetime('2018-03-15T13:34:00Z') | where ['Computer'] in ('comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, 34000ms), Computer",
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/microsoft.insights/components/AppInsightsTestDataWorkspace"},
TimeRange: timeRange,
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: true,
DashboardTime: false,
}),
@@ -595,7 +595,7 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
req, err := ds.createRequest(ctx, url, &AzureLogAnalyticsQuery{
Resources: []string{"/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.OperationalInsights/workspaces/r1", "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.OperationalInsights/workspaces/r2"},
Query: "Perf",
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
})
@@ -615,7 +615,7 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
req, err := ds.createRequest(ctx, url, &AzureLogAnalyticsQuery{
Resources: []string{"/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.OperationalInsights/workspaces/r1", "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.OperationalInsights/workspaces/r2"},
Query: "Perf",
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
TimeRange: backend.TimeRange{
From: from,
To: to,
@@ -662,7 +662,7 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
req, err := ds.createRequest(ctx, url, &AzureLogAnalyticsQuery{
Resources: []string{"/subscriptions/test-sub/resourceGroups/test-rg/providers/microsoft.operationalInsights/workSpaces/ws1", "microsoft.operationalInsights/workspaces/ws2"}, // Note different casings and partial paths
Query: "Perf",
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
})
@@ -680,7 +680,7 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
req, err := ds.createRequest(ctx, url, &AzureLogAnalyticsQuery{
Resources: []string{"/subscriptions/test-sub/resourceGroups/test-rg/providers/SomeOtherService/serviceInstances/r1", "/subscriptions/test-sub/resourceGroups/test-rg/providers/SomeOtherService/serviceInstances/r2"},
Query: "Perf",
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
QueryType: dataquery.AzureQueryTypeLogAnalytics,
AppInsightsQuery: false,
DashboardTime: false,
})
@@ -767,7 +767,7 @@ func Test_exemplarsFeatureToggle(t *testing.T) {
"query": "traceid"
}`),
RefID: "A",
QueryType: string(dataquery.AzureQueryTypeTraceql),
QueryType: string(dataquery.AzureQueryTypeTraceExemplar),
}
_, err := ds.buildQuery(ctx, query, dsInfo, false)
@@ -787,7 +787,7 @@ func Test_exemplarsFeatureToggle(t *testing.T) {
"query": "traceid"
}`),
RefID: "A",
QueryType: string(dataquery.AzureQueryTypeTraceql),
QueryType: string(dataquery.AzureQueryTypeTraceExemplar),
}
_, err := ds.buildQuery(ctx, query, dsInfo, false)

View File

@@ -78,7 +78,7 @@ func converterFrameForTable(t *types.AzureResponseTable, queryType dataquery.Azu
if !ok {
return nil, fmt.Errorf("unsupported analytics column type %v", col.Type)
}
if (queryType == dataquery.AzureQueryTypeAzureTraces || queryType == dataquery.AzureQueryTypeTraceql) && resultFormat == dataquery.ResultFormatTrace && (col.Name == "serviceTags" || col.Name == "tags") {
if (queryType == dataquery.AzureQueryTypeAzureTraces || queryType == dataquery.AzureQueryTypeTraceExemplar) && resultFormat == dataquery.ResultFormatTrace && (col.Name == "serviceTags" || col.Name == "tags") {
converter = tagsConverter
}
converters = append(converters, converter)

View File

@@ -56,7 +56,7 @@ func TestLogTableToFrame(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := loadTestFileWithNumber(t, tt.testFile)
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeAzureLogAnalytics, dataquery.ResultFormatTable, false)
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeLogAnalytics, dataquery.ResultFormatTable, false)
appendErrorNotice(frame, res.Error)
require.NoError(t, err)
@@ -107,7 +107,7 @@ func TestTraceTableToFrame(t *testing.T) {
name: "single trace as trace format from exemplars query",
testFile: "traces/2-traces-single-table.json",
resultFormat: dataquery.ResultFormatTrace,
queryType: dataquery.AzureQueryTypeTraceql,
queryType: dataquery.AzureQueryTypeTraceExemplar,
},
}
@@ -142,7 +142,7 @@ func TestLargeLogsResponse(t *testing.T) {
}
res.Tables[0].Rows = rows
resultFormat := dataquery.ResultFormatLogs
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeAzureLogAnalytics, resultFormat, false)
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeLogAnalytics, resultFormat, false)
appendErrorNotice(frame, res.Error)
require.NoError(t, err)
require.Equal(t, frame.Rows(), 30000)
@@ -171,7 +171,7 @@ func TestLargeLogsResponse(t *testing.T) {
}
res.Tables[0].Rows = rows
resultFormat := dataquery.ResultFormatLogs
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeAzureLogAnalytics, resultFormat, true)
frame, err := ResponseTableToFrame(&res.Tables[0], "A", "query", dataquery.AzureQueryTypeLogAnalytics, resultFormat, true)
appendErrorNotice(frame, res.Error)
require.NoError(t, err)
require.Equal(t, frame.Rows(), 40000)

View File

@@ -198,7 +198,7 @@ func buildAppInsightsQuery(ctx context.Context, query backend.DataQuery, dsInfo
resultFormat := ParseResultFormat(azureTracesTarget.ResultFormat, dataquery.AzureQueryTypeAzureTraces)
resources := azureTracesTarget.Resources
if query.QueryType == string(dataquery.AzureQueryTypeTraceql) {
if query.QueryType == string(dataquery.AzureQueryTypeTraceExemplar) {
subscription, err := utils.GetFirstSubscriptionOrDefault(ctx, dsInfo, logger)
if err != nil {
errorMessage := fmt.Errorf("failed to retrieve subscription for trace exemplars query: %w", err)
@@ -234,7 +234,7 @@ func buildAppInsightsQuery(ctx context.Context, query backend.DataQuery, dsInfo
}
sort.Strings(queryResources)
if query.QueryType == string(dataquery.AzureQueryTypeTraceql) {
if query.QueryType == string(dataquery.AzureQueryTypeTraceExemplar) {
resources = queryResources
resourceOrWorkspace = resources[0]
}

View File

@@ -69,7 +69,7 @@ func ParseResultFormat(queryResultFormat *dataquery.ResultFormat, queryType data
if queryResultFormat != nil && *queryResultFormat != "" {
return *queryResultFormat
}
if queryType == dataquery.AzureQueryTypeAzureLogAnalytics {
if queryType == dataquery.AzureQueryTypeLogAnalytics {
// Default to time series format for logs queries. It was time series before this change
return dataquery.ResultFormatTimeSeries
}

View File

@@ -19,7 +19,7 @@ func TestParseResultFormat(t *testing.T) {
{
name: "returns the time series format as default for logs queries if input format is nil",
queryResultFormat: nil,
queryType: dataquery.AzureQueryTypeAzureLogAnalytics,
queryType: dataquery.AzureQueryTypeLogAnalytics,
expectedResultFormat: dataquery.ResultFormatTimeSeries,
},
{
@@ -31,7 +31,7 @@ func TestParseResultFormat(t *testing.T) {
{
name: "returns the logs format as default for logs queries if input format is empty",
queryResultFormat: &emptyResultFormat,
queryType: dataquery.AzureQueryTypeAzureLogAnalytics,
queryType: dataquery.AzureQueryTypeLogAnalytics,
expectedResultFormat: dataquery.ResultFormatTimeSeries,
},
{

View File

@@ -51,11 +51,11 @@ var (
const (
gceAuthentication = "gce"
jwtAuthentication = "jwt"
annotationQueryType = dataquery.QueryTypeAnnotation
timeSeriesListQueryType = dataquery.QueryTypeTimeSeriesList
timeSeriesQueryQueryType = dataquery.QueryTypeTimeSeriesQuery
sloQueryType = dataquery.QueryTypeSlo
promQLQueryType = dataquery.QueryTypePromQL
annotationQueryType = dataquery.QueryTypeANNOTATION
timeSeriesListQueryType = dataquery.QueryTypeTIMESERIESLIST
timeSeriesQueryQueryType = dataquery.QueryTypeTIMESERIESQUERY
sloQueryType = dataquery.QueryTypeSLO
promQLQueryType = dataquery.QueryTypePROMQL
crossSeriesReducerDefault = "REDUCE_NONE"
perSeriesAlignerDefault = "ALIGN_MEAN"
)
@@ -217,10 +217,6 @@ func migrateMetricTypeFilter(metricTypeFilter string, prevFilters any) []string
return metricTypeFilterArray
}
func strPtr(s string) *string {
return &s
}
func migrateRequest(req *backend.QueryDataRequest) error {
for i, q := range req.Queries {
var rawQuery map[string]any
@@ -239,7 +235,7 @@ func migrateRequest(req *backend.QueryDataRequest) error {
if err != nil {
return err
}
q.QueryType = string(dataquery.QueryTypeTimeSeriesList)
q.QueryType = string(dataquery.QueryTypeTIMESERIESLIST)
gq := grafanaQuery{
TimeSeriesList: &mq,
}
@@ -260,7 +256,7 @@ func migrateRequest(req *backend.QueryDataRequest) error {
// Migrate type to queryType, which is only used for annotations
if rawQuery["type"] != nil && rawQuery["type"].(string) == "annotationQuery" {
q.QueryType = string(dataquery.QueryTypeAnnotation)
q.QueryType = string(dataquery.QueryTypeANNOTATION)
}
if rawQuery["queryType"] != nil {
q.QueryType = rawQuery["queryType"].(string)
@@ -274,9 +270,9 @@ func migrateRequest(req *backend.QueryDataRequest) error {
rawQuery["timeSeriesQuery"] = &dataquery.TimeSeriesQuery{
ProjectName: toString(metricQuery["projectName"]),
Query: toString(metricQuery["query"]),
GraphPeriod: strPtr(toString(metricQuery["graphPeriod"])),
GraphPeriod: toString(metricQuery["graphPeriod"]),
}
q.QueryType = string(dataquery.QueryTypeTimeSeriesQuery)
q.QueryType = string(dataquery.QueryTypeTIMESERIESQUERY)
} else {
tslb, err := json.Marshal(metricQuery)
if err != nil {
@@ -292,7 +288,7 @@ func migrateRequest(req *backend.QueryDataRequest) error {
tsl.Filters = migrateMetricTypeFilter(metricQuery["metricType"].(string), metricQuery["filters"])
}
rawQuery["timeSeriesList"] = tsl
q.QueryType = string(dataquery.QueryTypeTimeSeriesList)
q.QueryType = string(dataquery.QueryTypeTIMESERIESLIST)
}
// AliasBy is now a top level property
if metricQuery["aliasBy"] != nil {
@@ -305,7 +301,7 @@ func migrateRequest(req *backend.QueryDataRequest) error {
q.JSON = b
}
if rawQuery["sloQuery"] != nil && q.QueryType == string(dataquery.QueryTypeSlo) {
if rawQuery["sloQuery"] != nil && q.QueryType == string(dataquery.QueryTypeSLO) {
sloQuery := rawQuery["sloQuery"].(map[string]any)
// AliasBy is now a top level property
if sloQuery["aliasBy"] != nil {
@@ -349,7 +345,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
}
switch req.Queries[0].QueryType {
case string(dataquery.QueryTypeAnnotation):
case string(dataquery.QueryTypeANNOTATION):
return s.executeAnnotationQuery(ctx, req, *dsInfo, queries, logger)
default:
return s.executeTimeSeriesQuery(ctx, req, *dsInfo, queries, logger)
@@ -403,7 +399,7 @@ func (s *Service) buildQueryExecutors(logger log.Logger, req *backend.QueryDataR
var queryInterface cloudMonitoringQueryExecutor
switch query.QueryType {
case string(dataquery.QueryTypeTimeSeriesList), string(dataquery.QueryTypeAnnotation):
case string(dataquery.QueryTypeTIMESERIESLIST), string(dataquery.QueryTypeANNOTATION):
cmtsf := &cloudMonitoringTimeSeriesList{
refID: query.RefID,
aliasBy: q.AliasBy,
@@ -415,7 +411,7 @@ func (s *Service) buildQueryExecutors(logger log.Logger, req *backend.QueryDataR
cmtsf.parameters = q.TimeSeriesList
cmtsf.setParams(startTime, endTime, durationSeconds, query.Interval.Milliseconds())
queryInterface = cmtsf
case string(dataquery.QueryTypeTimeSeriesQuery):
case string(dataquery.QueryTypeTIMESERIESQUERY):
queryInterface = &cloudMonitoringTimeSeriesQuery{
refID: query.RefID,
aliasBy: q.AliasBy,
@@ -424,7 +420,7 @@ func (s *Service) buildQueryExecutors(logger log.Logger, req *backend.QueryDataR
timeRange: req.Queries[0].TimeRange,
logger: logger,
}
case string(dataquery.QueryTypeSlo):
case string(dataquery.QueryTypeSLO):
cmslo := &cloudMonitoringSLO{
refID: query.RefID,
aliasBy: q.AliasBy,
@@ -432,7 +428,7 @@ func (s *Service) buildQueryExecutors(logger log.Logger, req *backend.QueryDataR
}
cmslo.setParams(startTime, endTime, durationSeconds, query.Interval.Milliseconds())
queryInterface = cmslo
case string(dataquery.QueryTypePromQL):
case string(dataquery.QueryTypePROMQL):
cmp := &cloudMonitoringProm{
refID: query.RefID,
aliasBy: q.AliasBy,
@@ -629,7 +625,7 @@ func unmarshalResponse(res *http.Response, logger log.Logger) (cloudMonitoringRe
return data, nil
}
func addConfigData(frames data.Frames, dl string, unit string, period *string, logger log.Logger) data.Frames {
func addConfigData(frames data.Frames, dl string, unit string, period string, logger log.Logger) data.Frames {
for i := range frames {
if frames[i].Fields[1].Config == nil {
frames[i].Fields[1].Config = &data.FieldConfig{}
@@ -650,8 +646,8 @@ func addConfigData(frames data.Frames, dl string, unit string, period *string, l
if frames[i].Fields[0].Config == nil {
frames[i].Fields[0].Config = &data.FieldConfig{}
}
if period != nil && *period != "" {
err := addInterval(*period, frames[i].Fields[0])
if period != "" {
err := addInterval(period, frames[i].Fields[0])
if err != nil {
logger.Error("Failed to add interval: %s", err, "statusSource", backend.ErrorSourceDownstream)
}

View File

@@ -1104,7 +1104,7 @@ func baseTimeSeriesList() *backend.QueryDataRequest {
From: fromStart,
To: fromStart.Add(34 * time.Minute),
},
QueryType: string(dataquery.QueryTypeTimeSeriesList),
QueryType: string(dataquery.QueryTypeTIMESERIESLIST),
JSON: json.RawMessage(`{
"timeSeriesList": {
"filters": ["metric.type=\"a/metric/type\""],
@@ -1128,7 +1128,7 @@ func baseTimeSeriesQuery() *backend.QueryDataRequest {
From: fromStart,
To: fromStart.Add(34 * time.Minute),
},
QueryType: string(dataquery.QueryTypeTimeSeriesQuery),
QueryType: string(dataquery.QueryTypeTIMESERIESQUERY),
JSON: json.RawMessage(`{
"queryType": "metrics",
"timeSeriesQuery": {

View File

@@ -7,338 +7,294 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for AlignmentTypes.
const (
AlignmentTypesALIGNCOUNT AlignmentTypes = "ALIGN_COUNT"
AlignmentTypesALIGNCOUNTFALSE AlignmentTypes = "ALIGN_COUNT_FALSE"
AlignmentTypesALIGNCOUNTTRUE AlignmentTypes = "ALIGN_COUNT_TRUE"
AlignmentTypesALIGNDELTA AlignmentTypes = "ALIGN_DELTA"
AlignmentTypesALIGNFRACTIONTRUE AlignmentTypes = "ALIGN_FRACTION_TRUE"
AlignmentTypesALIGNINTERPOLATE AlignmentTypes = "ALIGN_INTERPOLATE"
AlignmentTypesALIGNMAX AlignmentTypes = "ALIGN_MAX"
AlignmentTypesALIGNMEAN AlignmentTypes = "ALIGN_MEAN"
AlignmentTypesALIGNMIN AlignmentTypes = "ALIGN_MIN"
AlignmentTypesALIGNNEXTOLDER AlignmentTypes = "ALIGN_NEXT_OLDER"
AlignmentTypesALIGNNONE AlignmentTypes = "ALIGN_NONE"
AlignmentTypesALIGNPERCENTCHANGE AlignmentTypes = "ALIGN_PERCENT_CHANGE"
AlignmentTypesALIGNPERCENTILE05 AlignmentTypes = "ALIGN_PERCENTILE_05"
AlignmentTypesALIGNPERCENTILE50 AlignmentTypes = "ALIGN_PERCENTILE_50"
AlignmentTypesALIGNPERCENTILE95 AlignmentTypes = "ALIGN_PERCENTILE_95"
AlignmentTypesALIGNPERCENTILE99 AlignmentTypes = "ALIGN_PERCENTILE_99"
AlignmentTypesALIGNRATE AlignmentTypes = "ALIGN_RATE"
AlignmentTypesALIGNSTDDEV AlignmentTypes = "ALIGN_STDDEV"
AlignmentTypesALIGNSUM AlignmentTypes = "ALIGN_SUM"
)
// Defines values for MetricFindQueryTypes.
const (
MetricFindQueryTypesAggregations MetricFindQueryTypes = "aggregations"
MetricFindQueryTypesAligners MetricFindQueryTypes = "aligners"
MetricFindQueryTypesAlignmentPeriods MetricFindQueryTypes = "alignmentPeriods"
MetricFindQueryTypesDefaultProject MetricFindQueryTypes = "defaultProject"
MetricFindQueryTypesLabelKeys MetricFindQueryTypes = "labelKeys"
MetricFindQueryTypesLabelValues MetricFindQueryTypes = "labelValues"
MetricFindQueryTypesMetricTypes MetricFindQueryTypes = "metricTypes"
MetricFindQueryTypesProjects MetricFindQueryTypes = "projects"
MetricFindQueryTypesResourceTypes MetricFindQueryTypes = "resourceTypes"
MetricFindQueryTypesSelectors MetricFindQueryTypes = "selectors"
MetricFindQueryTypesServices MetricFindQueryTypes = "services"
MetricFindQueryTypesSlo MetricFindQueryTypes = "slo"
MetricFindQueryTypesSloServices MetricFindQueryTypes = "sloServices"
)
// Defines values for MetricKind.
const (
MetricKindCUMULATIVE MetricKind = "CUMULATIVE"
MetricKindDELTA MetricKind = "DELTA"
MetricKindGAUGE MetricKind = "GAUGE"
MetricKindMETRICKINDUNSPECIFIED MetricKind = "METRIC_KIND_UNSPECIFIED"
)
// Defines values for PreprocessorType.
const (
PreprocessorTypeDelta PreprocessorType = "delta"
PreprocessorTypeNone PreprocessorType = "none"
PreprocessorTypeRate PreprocessorType = "rate"
)
// Defines values for QueryType.
const (
QueryTypeAnnotation QueryType = "annotation"
QueryTypePromQL QueryType = "promQL"
QueryTypeSlo QueryType = "slo"
QueryTypeTimeSeriesList QueryType = "timeSeriesList"
QueryTypeTimeSeriesQuery QueryType = "timeSeriesQuery"
)
// Defines values for ValueTypes.
const (
ValueTypesBOOL ValueTypes = "BOOL"
ValueTypesDISTRIBUTION ValueTypes = "DISTRIBUTION"
ValueTypesDOUBLE ValueTypes = "DOUBLE"
ValueTypesINT64 ValueTypes = "INT64"
ValueTypesMONEY ValueTypes = "MONEY"
ValueTypesSTRING ValueTypes = "STRING"
ValueTypesVALUETYPEUNSPECIFIED ValueTypes = "VALUE_TYPE_UNSPECIFIED"
)
// AlignmentTypes defines model for AlignmentTypes.
type AlignmentTypes string
// CloudMonitoringQuery defines model for CloudMonitoringQuery.
type CloudMonitoringQuery struct {
// Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail.
AliasBy *string `json:"aliasBy,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Time interval in milliseconds.
IntervalMs *float32 `json:"intervalMs,omitempty"`
// PromQL sub-query properties.
PromQLQuery *PromQLQuery `json:"promQLQuery,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
// SLO sub-query properties.
SloQuery *SLOQuery `json:"sloQuery,omitempty"`
RefId string `json:"refId"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail.
AliasBy *string `json:"aliasBy,omitempty"`
// GCM query type.
// queryType: #QueryType
// Time Series List sub-query properties.
TimeSeriesList *TimeSeriesList `json:"timeSeriesList,omitempty"`
// Time Series sub-query properties.
TimeSeriesQuery *TimeSeriesQuery `json:"timeSeriesQuery,omitempty"`
}
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// SLO sub-query properties.
SloQuery *SLOQuery `json:"sloQuery,omitempty"`
// PromQL sub-query properties.
PromQLQuery *PromQLQuery `json:"promQLQuery,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
Datasource any `json:"datasource,omitempty"`
// Time interval in milliseconds.
IntervalMs *float64 `json:"intervalMs,omitempty"`
}
// Query filter representation.
type Filter struct {
// Filter condition.
Condition *string `json:"condition,omitempty"`
// Filter key.
Key string `json:"key"`
// Filter operator.
Operator string `json:"operator"`
// Filter value.
Value string `json:"value"`
}
// GoogleCloudMonitoringDataQuery defines model for GoogleCloudMonitoringDataQuery.
type GoogleCloudMonitoringDataQuery = map[string]any
// @deprecated Use TimeSeriesList instead. Legacy annotation query properties for migration purposes.
type LegacyCloudMonitoringAnnotationQuery struct {
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters"`
MetricKind MetricKind `json:"metricKind"`
MetricType string `json:"metricType"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// Query refId.
RefId string `json:"refId"`
// Annotation text.
Text string `json:"text"`
// Annotation title.
Title string `json:"title"`
ValueType string `json:"valueType"`
}
// MetricFindQueryTypes defines model for MetricFindQueryTypes.
type MetricFindQueryTypes string
// MetricKind defines model for MetricKind.
type MetricKind string
// @deprecated This type is for migration purposes only. Replaced by TimeSeriesList Metric sub-query properties.
type MetricQuery struct {
// Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail.
AliasBy *string `json:"aliasBy,omitempty"`
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
CrossSeriesReducer string `json:"crossSeriesReducer"`
EditorMode string `json:"editorMode"`
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters,omitempty"`
// To disable the graphPeriod, it should explictly be set to 'disabled'.
GraphPeriod *string `json:"graphPeriod,omitempty"`
// Array of labels to group data by.
GroupBys []string `json:"groupBys,omitempty"`
MetricKind *MetricKind `json:"metricKind,omitempty"`
MetricType string `json:"metricType"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// Types of pre-processor available. Defined by the metric.
Preprocessor *PreprocessorType `json:"preprocessor,omitempty"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// MQL query to be executed.
Query string `json:"query"`
ValueType *string `json:"valueType,omitempty"`
View *string `json:"view,omitempty"`
}
// Types of pre-processor available. Defined by the metric.
type PreprocessorType string
// PromQL sub-query properties.
type PromQLQuery struct {
// PromQL expression/query to be executed.
Expr string `json:"expr"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// PromQL min step
Step string `json:"step"`
// NewCloudMonitoringQuery creates a new CloudMonitoringQuery object.
func NewCloudMonitoringQuery() *CloudMonitoringQuery {
return &CloudMonitoringQuery{}
}
// Defines the supported queryTypes.
type QueryType string
// SLO sub-query properties.
type SLOQuery struct {
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// SLO goal value.
Goal *float32 `json:"goal,omitempty"`
// Specific lookback period for the SLO.
LookbackPeriod *string `json:"lookbackPeriod,omitempty"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// SLO selector.
SelectorName string `json:"selectorName"`
// ID for the service the SLO is in.
ServiceId string `json:"serviceId"`
// Name for the service the SLO is in.
ServiceName string `json:"serviceName"`
// ID for the SLO.
SloId string `json:"sloId"`
// Name of the SLO.
SloName string `json:"sloName"`
}
const (
QueryTypeTIMESERIESLIST QueryType = "timeSeriesList"
QueryTypeTIMESERIESQUERY QueryType = "timeSeriesQuery"
QueryTypeSLO QueryType = "slo"
QueryTypeANNOTATION QueryType = "annotation"
QueryTypePROMQL QueryType = "promQL"
)
// Time Series List sub-query properties.
type TimeSeriesList struct {
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
CrossSeriesReducer string `json:"crossSeriesReducer"`
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters,omitempty"`
// Array of labels to group data by.
GroupBys []string `json:"groupBys,omitempty"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// Types of pre-processor available. Defined by the metric.
Preprocessor *PreprocessorType `json:"preprocessor,omitempty"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
SecondaryAlignmentPeriod *string `json:"secondaryAlignmentPeriod,omitempty"`
// Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
SecondaryCrossSeriesReducer *string `json:"secondaryCrossSeriesReducer,omitempty"`
// Only present if a preprocessor is selected. Array of labels to group data by.
SecondaryGroupBys []string `json:"secondaryGroupBys,omitempty"`
// Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN.
SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"`
// Annotation text.
Text *string `json:"text,omitempty"`
// Annotation title.
Title *string `json:"title,omitempty"`
// Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
CrossSeriesReducer string `json:"crossSeriesReducer"`
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// Array of labels to group data by.
GroupBys []string `json:"groupBys,omitempty"`
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters,omitempty"`
// Data view, defaults to FULL.
View *string `json:"view,omitempty"`
// Annotation title.
Title *string `json:"title,omitempty"`
// Annotation text.
Text *string `json:"text,omitempty"`
// Only present if a preprocessor is selected. Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
SecondaryCrossSeriesReducer *string `json:"secondaryCrossSeriesReducer,omitempty"`
// Only present if a preprocessor is selected. Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
SecondaryAlignmentPeriod *string `json:"secondaryAlignmentPeriod,omitempty"`
// Only present if a preprocessor is selected. Alignment function to be used. Defaults to ALIGN_MEAN.
SecondaryPerSeriesAligner *string `json:"secondaryPerSeriesAligner,omitempty"`
// Only present if a preprocessor is selected. Array of labels to group data by.
SecondaryGroupBys []string `json:"secondaryGroupBys,omitempty"`
// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters
Preprocessor *PreprocessorType `json:"preprocessor,omitempty"`
}
// NewTimeSeriesList creates a new TimeSeriesList object.
func NewTimeSeriesList() *TimeSeriesList {
return &TimeSeriesList{}
}
// Types of pre-processor available. Defined by the metric.
type PreprocessorType string
const (
PreprocessorTypeNone PreprocessorType = "none"
PreprocessorTypeRate PreprocessorType = "rate"
PreprocessorTypeDelta PreprocessorType = "delta"
)
// Time Series sub-query properties.
type TimeSeriesQuery struct {
// To disable the graphPeriod, it should explictly be set to 'disabled'.
GraphPeriod *string `json:"graphPeriod,omitempty"`
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// MQL query to be executed.
Query string `json:"query"`
// To disable the graphPeriod, it should explictly be set to 'disabled'.
GraphPeriod string `json:"graphPeriod,omitempty"`
}
// ValueTypes defines model for ValueTypes.
// NewTimeSeriesQuery creates a new TimeSeriesQuery object.
func NewTimeSeriesQuery() *TimeSeriesQuery {
return &TimeSeriesQuery{}
}
// SLO sub-query properties.
type SLOQuery struct {
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// SLO selector.
SelectorName string `json:"selectorName"`
// ID for the service the SLO is in.
ServiceId string `json:"serviceId"`
// Name for the service the SLO is in.
ServiceName string `json:"serviceName"`
// ID for the SLO.
SloId string `json:"sloId"`
// Name of the SLO.
SloName string `json:"sloName"`
// SLO goal value.
Goal *float64 `json:"goal,omitempty"`
// Specific lookback period for the SLO.
LookbackPeriod *string `json:"lookbackPeriod,omitempty"`
}
// NewSLOQuery creates a new SLOQuery object.
func NewSLOQuery() *SLOQuery {
return &SLOQuery{}
}
// PromQL sub-query properties.
type PromQLQuery struct {
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// PromQL expression/query to be executed.
Expr string `json:"expr"`
// PromQL min step
Step string `json:"step"`
}
// NewPromQLQuery creates a new PromQLQuery object.
func NewPromQLQuery() *PromQLQuery {
return &PromQLQuery{}
}
// @deprecated This type is for migration purposes only. Replaced by TimeSeriesList Metric sub-query properties.
type MetricQuery struct {
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
// Alignment function to be used. Defaults to ALIGN_MEAN.
PerSeriesAligner *string `json:"perSeriesAligner,omitempty"`
// Alignment period to use when regularizing data. Defaults to cloud-monitoring-auto.
AlignmentPeriod *string `json:"alignmentPeriod,omitempty"`
// Aliases can be set to modify the legend labels. e.g. {{metric.label.xxx}}. See docs for more detail.
AliasBy *string `json:"aliasBy,omitempty"`
EditorMode string `json:"editorMode"`
MetricType string `json:"metricType"`
// Reducer applied across a set of time-series values. Defaults to REDUCE_NONE.
CrossSeriesReducer string `json:"crossSeriesReducer"`
// Array of labels to group data by.
GroupBys []string `json:"groupBys,omitempty"`
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters,omitempty"`
MetricKind *MetricKind `json:"metricKind,omitempty"`
ValueType *string `json:"valueType,omitempty"`
View *string `json:"view,omitempty"`
// MQL query to be executed.
Query string `json:"query"`
// Preprocessor is not part of the API, but is used to store the preprocessor and not affect the UI for the rest of parameters
Preprocessor *PreprocessorType `json:"preprocessor,omitempty"`
// To disable the graphPeriod, it should explictly be set to 'disabled'.
GraphPeriod string `json:"graphPeriod,omitempty"`
}
// NewMetricQuery creates a new MetricQuery object.
func NewMetricQuery() *MetricQuery {
return &MetricQuery{}
}
type MetricKind string
const (
MetricKindMETRICKINDUNSPECIFIED MetricKind = "METRIC_KIND_UNSPECIFIED"
MetricKindGAUGE MetricKind = "GAUGE"
MetricKindDELTA MetricKind = "DELTA"
MetricKindCUMULATIVE MetricKind = "CUMULATIVE"
)
type ValueTypes string
const (
ValueTypesVALUETYPEUNSPECIFIED ValueTypes = "VALUE_TYPE_UNSPECIFIED"
ValueTypesBOOL ValueTypes = "BOOL"
ValueTypesINT64 ValueTypes = "INT64"
ValueTypesDOUBLE ValueTypes = "DOUBLE"
ValueTypesSTRING ValueTypes = "STRING"
ValueTypesDISTRIBUTION ValueTypes = "DISTRIBUTION"
ValueTypesMONEY ValueTypes = "MONEY"
)
type AlignmentTypes string
const (
AlignmentTypesALIGNDELTA AlignmentTypes = "ALIGN_DELTA"
AlignmentTypesALIGNRATE AlignmentTypes = "ALIGN_RATE"
AlignmentTypesALIGNINTERPOLATE AlignmentTypes = "ALIGN_INTERPOLATE"
AlignmentTypesALIGNNEXTOLDER AlignmentTypes = "ALIGN_NEXT_OLDER"
AlignmentTypesALIGNMIN AlignmentTypes = "ALIGN_MIN"
AlignmentTypesALIGNMAX AlignmentTypes = "ALIGN_MAX"
AlignmentTypesALIGNMEAN AlignmentTypes = "ALIGN_MEAN"
AlignmentTypesALIGNCOUNT AlignmentTypes = "ALIGN_COUNT"
AlignmentTypesALIGNSUM AlignmentTypes = "ALIGN_SUM"
AlignmentTypesALIGNSTDDEV AlignmentTypes = "ALIGN_STDDEV"
AlignmentTypesALIGNCOUNTTRUE AlignmentTypes = "ALIGN_COUNT_TRUE"
AlignmentTypesALIGNCOUNTFALSE AlignmentTypes = "ALIGN_COUNT_FALSE"
AlignmentTypesALIGNFRACTIONTRUE AlignmentTypes = "ALIGN_FRACTION_TRUE"
AlignmentTypesALIGNPERCENTILE99 AlignmentTypes = "ALIGN_PERCENTILE_99"
AlignmentTypesALIGNPERCENTILE95 AlignmentTypes = "ALIGN_PERCENTILE_95"
AlignmentTypesALIGNPERCENTILE50 AlignmentTypes = "ALIGN_PERCENTILE_50"
AlignmentTypesALIGNPERCENTILE05 AlignmentTypes = "ALIGN_PERCENTILE_05"
AlignmentTypesALIGNPERCENTCHANGE AlignmentTypes = "ALIGN_PERCENT_CHANGE"
AlignmentTypesALIGNNONE AlignmentTypes = "ALIGN_NONE"
)
// @deprecated Use TimeSeriesList instead. Legacy annotation query properties for migration purposes.
type LegacyCloudMonitoringAnnotationQuery struct {
// GCP project to execute the query against.
ProjectName string `json:"projectName"`
MetricType string `json:"metricType"`
// Query refId.
RefId string `json:"refId"`
// Array of filters to query data by. Labels that can be filtered on are defined by the metric.
Filters []string `json:"filters"`
MetricKind MetricKind `json:"metricKind"`
ValueType string `json:"valueType"`
// Annotation title.
Title string `json:"title"`
// Annotation text.
Text string `json:"text"`
}
// NewLegacyCloudMonitoringAnnotationQuery creates a new LegacyCloudMonitoringAnnotationQuery object.
func NewLegacyCloudMonitoringAnnotationQuery() *LegacyCloudMonitoringAnnotationQuery {
return &LegacyCloudMonitoringAnnotationQuery{}
}
// Query filter representation.
type Filter struct {
// Filter key.
Key string `json:"key"`
// Filter operator.
Operator string `json:"operator"`
// Filter value.
Value string `json:"value"`
// Filter condition.
Condition *string `json:"condition,omitempty"`
}
// NewFilter creates a new Filter object.
func NewFilter() *Filter {
return &Filter{}
}
type MetricFindQueryTypes string
const (
MetricFindQueryTypesProjects MetricFindQueryTypes = "projects"
MetricFindQueryTypesServices MetricFindQueryTypes = "services"
MetricFindQueryTypesDefaultProject MetricFindQueryTypes = "defaultProject"
MetricFindQueryTypesMetricTypes MetricFindQueryTypes = "metricTypes"
MetricFindQueryTypesLabelKeys MetricFindQueryTypes = "labelKeys"
MetricFindQueryTypesLabelValues MetricFindQueryTypes = "labelValues"
MetricFindQueryTypesResourceTypes MetricFindQueryTypes = "resourceTypes"
MetricFindQueryTypesAggregations MetricFindQueryTypes = "aggregations"
MetricFindQueryTypesAligners MetricFindQueryTypes = "aligners"
MetricFindQueryTypesAlignmentPeriods MetricFindQueryTypes = "alignmentPeriods"
MetricFindQueryTypesSelectors MetricFindQueryTypes = "selectors"
MetricFindQueryTypesSLOServices MetricFindQueryTypes = "sloServices"
MetricFindQueryTypesSLO MetricFindQueryTypes = "slo"
)

View File

@@ -50,7 +50,7 @@ func parseTimeSeriesResponse(queryRes *backend.DataResponse,
if len(response.TimeSeries) > 0 {
dl := query.buildDeepLink()
aggregationAlignmentString := params.Get("aggregation.alignmentPeriod")
frames = addConfigData(frames, dl, response.Unit, &aggregationAlignmentString, logger)
frames = addConfigData(frames, dl, response.Unit, aggregationAlignmentString, logger)
}
queryRes.Frames = frames

View File

@@ -410,7 +410,7 @@ func TestTimeSeriesFilter(t *testing.T) {
parameters: &dataquery.TimeSeriesQuery{
Query: "fetch gce_instance::compute.googleapis.com/instance/cpu/utilization | sum",
ProjectName: "test",
GraphPeriod: strPtr("60s"),
GraphPeriod: "60s",
},
}
err = query.parseResponse(res, data, "", service.logger)

View File

@@ -15,13 +15,13 @@ import (
func (timeSeriesQuery *cloudMonitoringTimeSeriesQuery) appendGraphPeriod(req *backend.QueryDataRequest) string {
// GraphPeriod needs to be explicitly disabled.
// If not set, the default behavior is to set an automatic value
if timeSeriesQuery.parameters.GraphPeriod == nil || *timeSeriesQuery.parameters.GraphPeriod != "disabled" {
if timeSeriesQuery.parameters.GraphPeriod == nil || *timeSeriesQuery.parameters.GraphPeriod == "auto" || *timeSeriesQuery.parameters.GraphPeriod == "" {
if timeSeriesQuery.parameters.GraphPeriod != "disabled" {
if timeSeriesQuery.parameters.GraphPeriod == "auto" || timeSeriesQuery.parameters.GraphPeriod == "" {
intervalCalculator := gcmTime.NewCalculator(gcmTime.CalculatorOptions{})
interval := intervalCalculator.Calculate(req.Queries[0].TimeRange, time.Duration(timeSeriesQuery.IntervalMS/1000)*time.Second, req.Queries[0].MaxDataPoints)
timeSeriesQuery.parameters.GraphPeriod = &interval.Text
timeSeriesQuery.parameters.GraphPeriod = interval.Text
}
return fmt.Sprintf(" | graph_period %s", *timeSeriesQuery.parameters.GraphPeriod)
return fmt.Sprintf(" | graph_period %s", timeSeriesQuery.parameters.GraphPeriod)
}
return ""
}

View File

@@ -125,7 +125,7 @@ func TestTimeSeriesQuery(t *testing.T) {
parameters: &dataquery.TimeSeriesQuery{
ProjectName: "test-proj",
Query: "test-query",
GraphPeriod: strPtr("60s"),
GraphPeriod: "60s",
},
timeRange: backend.TimeRange{
From: fromStart,
@@ -145,7 +145,7 @@ func TestTimeSeriesQuery(t *testing.T) {
})
t.Run("skips graph_period if disabled", func(t *testing.T) {
query := &cloudMonitoringTimeSeriesQuery{parameters: &dataquery.TimeSeriesQuery{GraphPeriod: strPtr("disabled")}}
query := &cloudMonitoringTimeSeriesQuery{parameters: &dataquery.TimeSeriesQuery{GraphPeriod: "disabled"}}
assert.Equal(t, query.appendGraphPeriod(&backend.QueryDataRequest{Queries: []backend.DataQuery{{}}}), "")
})

View File

@@ -12,7 +12,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
type annotationEvent struct {
@@ -51,12 +50,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
actionPrefix := model.ActionPrefix
alarmNamePrefix := model.AlarmNamePrefix
region := ""
if model.Region != nil {
region = *model.Region
}
cli, err := e.getCWClient(ctx, pluginCtx, region)
cli, err := e.getCWClient(ctx, pluginCtx, model.Region)
if err != nil {
result.Responses[query.RefID] = backend.ErrorResponseWithErrorSource(fmt.Errorf("%v: %w", "failed to get client", err))
return result, nil
@@ -84,27 +78,23 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
result.Responses[query.RefID] = backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarms", err)))
return result, nil
}
alarmNames = filterAlarms(resp, utils.Depointerizer(model.Namespace), metricName, dimensions, statistic, period)
alarmNames = filterAlarms(resp, model.Namespace, metricName, dimensions, statistic, period)
} else {
if model.Region == nil || model.Namespace == nil || metricName == "" || statistic == "" {
if model.Region == "" || model.Namespace == "" || metricName == "" || statistic == "" {
return result, backend.DownstreamError(errors.New("invalid annotations query"))
}
var qd []*cloudwatch.Dimension
for k, v := range dimensions {
if vv, ok := v.([]any); ok {
for _, vvv := range vv {
if vvvv, ok := vvv.(string); ok {
qd = append(qd, &cloudwatch.Dimension{
Name: aws.String(k),
Value: aws.String(vvvv),
})
}
}
for _, vvv := range v.ArrayOfString {
qd = append(qd, &cloudwatch.Dimension{
Name: aws.String(k),
Value: aws.String(vvv),
})
}
}
params := &cloudwatch.DescribeAlarmsForMetricInput{
Namespace: aws.String(utils.Depointerizer(model.Namespace)),
Namespace: aws.String(model.Namespace),
MetricName: aws.String(metricName),
Dimensions: qd,
Statistic: aws.String(statistic),
@@ -172,7 +162,7 @@ func transformAnnotationToTable(annotations []*annotationEvent, query backend.Da
}
func filterAlarms(alarms *cloudwatch.DescribeAlarmsOutput, namespace string, metricName string,
dimensions map[string]any, statistic string, period int64) []*string {
dimensions dataquery.Dimensions, statistic string, period int64) []*string {
alarmNames := make([]*string, 0)
for _, alarm := range alarms.MetricAlarms {

View File

@@ -211,8 +211,8 @@ func (e *cloudWatchExecutor) QueryData(ctx context.Context, req *backend.QueryDa
// Since `model.Type` is set during execution on the frontend by the query runner and isn't saved with the query, we are checking here is
// missing the `model.Type` property and if it is a log query in order to determine if it is a public dashboard query.
queryMode := ""
if model.QueryMode != nil {
queryMode = string(*model.QueryMode)
if model.QueryMode != "" {
queryMode = string(model.QueryMode)
}
fromPublicDashboard := model.Type == "" && queryMode == logsQueryMode
isSyncLogQuery := ((fromAlert || fromExpression) && queryMode == logsQueryMode) || fromPublicDashboard

File diff suppressed because it is too large Load Diff

View File

@@ -141,8 +141,8 @@ func (e *cloudWatchExecutor) executeLogAction(ctx context.Context, logsQuery mod
}
region := instance.Settings.Region
if logsQuery.Region != nil {
region = *logsQuery.Region
if logsQuery.Region != "" {
region = logsQuery.Region
}
logsClient, err := e.getCWLogsClient(ctx, pluginCtx, region)
@@ -305,8 +305,8 @@ func (e *cloudWatchExecutor) handleStartQuery(ctx context.Context, logsClient cl
dataFrame.RefID = refID
region := "default"
if logsQuery.Region != nil {
region = *logsQuery.Region
if logsQuery.Region != "" {
region = logsQuery.Region
}
dataFrame.Meta = &data.FrameMeta{

View File

@@ -13,7 +13,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
const initialAlertPollPeriod = time.Second
@@ -39,9 +38,9 @@ var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *
logsQuery.QueryString = *logsQuery.Expression
}
region := utils.Depointerizer(logsQuery.Region)
region := logsQuery.Region
if region == "" || region == defaultRegion {
logsQuery.Region = utils.Pointer(instance.Settings.Region)
logsQuery.Region = instance.Settings.Region
}
logsClient, err := e.getCWLogsClient(ctx, req.PluginContext, region)

View File

@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
type (
@@ -27,13 +26,13 @@ type (
)
const (
MetricEditorModeBuilder = dataquery.MetricEditorModeN0
MetricEditorModeRaw = dataquery.MetricEditorModeN1
MetricEditorModeBuilder = dataquery.MetricEditorModeBuilder
MetricEditorModeRaw = dataquery.MetricEditorModeCode
)
const (
MetricQueryTypeSearch = dataquery.MetricQueryTypeN0
MetricQueryTypeQuery = dataquery.MetricQueryTypeN1
MetricQueryTypeSearch = dataquery.MetricQueryTypeSearch
MetricQueryTypeQuery = dataquery.MetricQueryTypeInsights
)
const (
@@ -256,9 +255,9 @@ func ParseMetricDataQueries(dataQueries []backend.DataQuery, startTime time.Time
StartTime: startTime,
EndTime: endTime,
RefId: refId,
Id: utils.Depointerizer(mdq.Id),
Region: utils.Depointerizer(mdq.Region),
Namespace: utils.Depointerizer(mdq.Namespace),
Id: mdq.Id,
Region: mdq.Region,
Namespace: mdq.Namespace,
TimezoneUTCOffset: mdq.TimezoneUTCOffset,
}
@@ -335,7 +334,7 @@ func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery
q.AccountId = metricsDataQuery.AccountId
}
if utils.Depointerizer(metricsDataQuery.Id) == "" {
if metricsDataQuery.Id == "" {
// Why not just use refId if id is not specified in the frontend? When specifying an id in the editor,
// and alphabetical must be used. The id must be unique, so if an id like for example a, b or c would be used,
// it would likely collide with some ref id. That's why the `query` prefix is used.
@@ -488,16 +487,14 @@ func getRetainedPeriods(timeSince time.Duration) []int {
}
}
func parseDimensions(dimensions map[string]any) (map[string][]string, error) {
func parseDimensions(dimensions dataquery.Dimensions) (map[string][]string, error) {
parsedDimensions := make(map[string][]string)
for k, v := range dimensions {
// This is for backwards compatibility. Before 6.5 dimensions values were stored as strings and not arrays
if value, ok := v.(string); ok {
parsedDimensions[k] = []string{value}
} else if values, ok := v.([]any); ok {
for _, value := range values {
parsedDimensions[k] = append(parsedDimensions[k], value.(string))
}
if v.String != nil {
parsedDimensions[k] = []string{*v.String}
} else if len(v.ArrayOfString) > 0 {
parsedDimensions[k] = append(parsedDimensions[k], v.ArrayOfString...)
} else {
return nil, errors.New("unknown type as dimension value")
}

View File

@@ -435,7 +435,8 @@ func TestRequestParser(t *testing.T) {
_, err := ParseMetricDataQueries(query, time.Now().Add(-2*time.Hour), time.Now().Add(-time.Hour), "us-east-2", logger, false)
require.Error(t, err)
assert.Equal(t, `error parsing query "", failed to parse dimensions: unknown type as dimension value`, err.Error())
assert.Equal(t, `error parsing query "", json: cannot unmarshal number into Go value of type string
json: cannot unmarshal number into Go value of type []string`, err.Error())
})
}
@@ -935,12 +936,12 @@ func Test_migrateAliasToDynamicLabel_single_query_preserves_old_alias_and_create
queryToMigrate := metricsDataQuery{
CloudWatchMetricsQuery: dataquery.CloudWatchMetricsQuery{
Region: utils.Pointer("us-east-1"),
Namespace: utils.Pointer("ec2"),
Region: "us-east-1",
Namespace: "ec2",
MetricName: utils.Pointer("CPUUtilization"),
Alias: utils.Pointer(tc.inputAlias),
Dimensions: &dataquery.Dimensions{
"InstanceId": []any{"test"},
"InstanceId": dataquery.StringOrArrayOfString{ArrayOfString: []string{"test"}},
},
Statistic: &average,
Period: utils.Pointer("600"),

View File

@@ -4,15 +4,6 @@ import "github.com/go-stack/stack"
func Pointer[T any](arg T) *T { return &arg }
func Depointerizer[T any](v *T) T {
var emptyValue T
if v != nil {
emptyValue = *v
}
return emptyValue
}
// Stack is copied from grafana/pkg/infra/log
// TODO: maybe this should live in grafana-plugin-sdk-go?
func Stack(skip int) string {

File diff suppressed because it is too large Load Diff

View File

@@ -7,76 +7,50 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for PyroscopeQueryType.
type PyroscopeQueryType string
const (
PyroscopeQueryTypeBoth PyroscopeQueryType = "both"
PyroscopeQueryTypeMetrics PyroscopeQueryType = "metrics"
PyroscopeQueryTypeProfile PyroscopeQueryType = "profile"
PyroscopeQueryTypeBoth PyroscopeQueryType = "both"
)
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
type GrafanaPyroscopeDataQuery struct {
// Specifies the query label selectors.
LabelSelector string `json:"labelSelector"`
// Specifies the query span selectors.
SpanSelector []string `json:"spanSelector,omitempty"`
// Specifies the type of profile to query.
ProfileTypeId string `json:"profileTypeId"`
// Allows to group the results.
GroupBy []string `json:"groupBy"`
// Sets the maximum number of time series.
Limit *int64 `json:"limit,omitempty"`
// Sets the maximum number of nodes in the flamegraph.
MaxNodes *int64 `json:"maxNodes,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
}
// GrafanaPyroscopeDataQuery defines model for GrafanaPyroscopeDataQuery.
type GrafanaPyroscopeDataQuery struct {
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// Allows to group the results.
GroupBy []string `json:"groupBy,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specifies the query label selectors.
LabelSelector *string `json:"labelSelector,omitempty"`
// Sets the maximum number of time series.
Limit *int64 `json:"limit,omitempty"`
// Sets the maximum number of nodes in the flamegraph.
MaxNodes *int64 `json:"maxNodes,omitempty"`
// Specifies the type of profile to query.
ProfileTypeId *string `json:"profileTypeId,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
// Specifies the query span selectors.
SpanSelector []string `json:"spanSelector,omitempty"`
Datasource any `json:"datasource,omitempty"`
}
// PyroscopeQueryType defines model for PyroscopeQueryType.
type PyroscopeQueryType string
// NewGrafanaPyroscopeDataQuery creates a new GrafanaPyroscopeDataQuery object.
func NewGrafanaPyroscopeDataQuery() *GrafanaPyroscopeDataQuery {
return &GrafanaPyroscopeDataQuery{
LabelSelector: "{}",
}
}

View File

@@ -52,8 +52,8 @@ func (d *PyroscopeDatasource) query(ctx context.Context, pCtx backend.PluginCont
return response
}
profileTypeId := depointerizer(qm.ProfileTypeId)
labelSelector := depointerizer(qm.LabelSelector)
profileTypeId := qm.ProfileTypeId
labelSelector := qm.LabelSelector
responseMutex := sync.Mutex{}
g, gCtx := errgroup.WithContext(ctx)
@@ -454,12 +454,3 @@ func seriesToDataFrames(resp *SeriesResponse) []*data.Frame {
}
return frames
}
func depointerizer[T any](v *T) T {
var emptyValue T
if v != nil {
emptyValue = *v
}
return emptyValue
}

View File

@@ -11,7 +11,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana/pkg/tsdb/loki/kinds/dataquery"
"github.com/grafana/grafana/pkg/util"
)
const (
@@ -40,7 +39,7 @@ func healthcheck(ctx context.Context, req *backend.CheckHealthRequest, s *Servic
step := "1s"
qt := "instant"
qm := dataquery.LokiDataQuery{
Expr: util.Pointer("vector(1)+vector(1)"),
Expr: "vector(1)+vector(1)",
Step: &step,
QueryType: &qt,
}

View File

@@ -7,110 +7,75 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for LokiQueryDirection.
type QueryEditorMode string
const (
LokiQueryDirectionBackward LokiQueryDirection = "backward"
LokiQueryDirectionForward LokiQueryDirection = "forward"
LokiQueryDirectionScan LokiQueryDirection = "scan"
QueryEditorModeCode QueryEditorMode = "code"
QueryEditorModeBuilder QueryEditorMode = "builder"
)
// Defines values for LokiQueryType.
type LokiQueryType string
const (
LokiQueryTypeInstant LokiQueryType = "instant"
LokiQueryTypeRange LokiQueryType = "range"
LokiQueryTypeInstant LokiQueryType = "instant"
LokiQueryTypeStream LokiQueryType = "stream"
)
// Defines values for QueryEditorMode.
const (
QueryEditorModeBuilder QueryEditorMode = "builder"
QueryEditorModeCode QueryEditorMode = "code"
)
type SupportingQueryType string
// Defines values for SupportingQueryType.
const (
SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume"
SupportingQueryTypeLogsSample SupportingQueryType = "logsSample"
SupportingQueryTypeDataSample SupportingQueryType = "dataSample"
SupportingQueryTypeInfiniteScroll SupportingQueryType = "infiniteScroll"
SupportingQueryTypeLogsSample SupportingQueryType = "logsSample"
SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume"
)
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
type LokiQueryDirection string
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
const (
LokiQueryDirectionForward LokiQueryDirection = "forward"
LokiQueryDirectionBackward LokiQueryDirection = "backward"
LokiQueryDirectionScan LokiQueryDirection = "scan"
)
type LokiDataQuery struct {
// The LogQL query.
Expr string `json:"expr"`
// Used to override the name of the series.
LegendFormat *string `json:"legendFormat,omitempty"`
// Used to limit the number of log rows returned.
MaxLines *int64 `json:"maxLines,omitempty"`
// @deprecated, now use step.
Resolution *int64 `json:"resolution,omitempty"`
EditorMode *QueryEditorMode `json:"editorMode,omitempty"`
// @deprecated, now use queryType.
Range *bool `json:"range,omitempty"`
// @deprecated, now use queryType.
Instant *bool `json:"instant,omitempty"`
// Used to set step value for range queries.
Step *string `json:"step,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
}
// LokiDataQuery defines model for LokiDataQuery.
type LokiDataQuery struct {
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
EditorMode *QueryEditorMode `json:"editorMode,omitempty"`
// The LogQL query.
Expr *string `json:"expr,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// @deprecated, now use queryType.
Instant *bool `json:"instant,omitempty"`
// Used to override the name of the series.
LegendFormat *string `json:"legendFormat,omitempty"`
// Used to limit the number of log rows returned.
MaxLines *int64 `json:"maxLines,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// @deprecated, now use queryType.
Range *bool `json:"range,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
// @deprecated, now use step.
Resolution *int64 `json:"resolution,omitempty"`
// Used to set step value for range queries.
Step *string `json:"step,omitempty"`
Datasource any `json:"datasource,omitempty"`
}
// LokiQueryDirection defines model for LokiQueryDirection.
type LokiQueryDirection string
// LokiQueryType defines model for LokiQueryType.
type LokiQueryType string
// QueryEditorMode defines model for QueryEditorMode.
type QueryEditorMode string
// SupportingQueryType defines model for SupportingQueryType.
type SupportingQueryType string
// NewLokiDataQuery creates a new LokiDataQuery object.
func NewLokiDataQuery() *LokiDataQuery {
return &LokiDataQuery{}
}

View File

@@ -154,7 +154,7 @@ func parseQuery(queryContext *backend.QueryDataRequest, logqlScopesEnabled bool)
return nil, err
}
expr := interpolateVariables(depointerizer(model.Expr), interval, timeRange, queryType, step)
expr := interpolateVariables(model.Expr, interval, timeRange, queryType, step)
direction, err := parseDirection(model.Direction)
if err != nil {
@@ -197,12 +197,3 @@ func parseQuery(queryContext *backend.QueryDataRequest, logqlScopesEnabled bool)
return qs, nil
}
func depointerizer[T any](v *T) T {
var emptyValue T
if v != nil {
emptyValue = *v
}
return emptyValue
}

View File

@@ -34,7 +34,7 @@ func (s *Service) SubscribeStream(ctx context.Context, req *backend.SubscribeStr
if err != nil {
return nil, err
}
if query.Expr == nil || *query.Expr == "" {
if query.Expr == "" {
return &backend.SubscribeStreamResponse{
Status: backend.SubscribeStreamStatusNotFound,
}, fmt.Errorf("missing expr in channel (subscribe)")
@@ -69,7 +69,7 @@ func (s *Service) RunStream(ctx context.Context, req *backend.RunStreamRequest,
if err != nil {
return err
}
if query.Expr == nil || *query.Expr == "" {
if query.Expr == "" {
return fmt.Errorf("missing expr in cuannel")
}
@@ -80,7 +80,7 @@ func (s *Service) RunStream(ctx context.Context, req *backend.RunStreamRequest,
signal.Notify(interrupt, os.Interrupt)
params := url.Values{}
params.Add("query", *query.Expr)
params.Add("query", query.Expr)
wsurl, _ := url.Parse(dsInfo.URL)

View File

@@ -7,64 +7,42 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for ParcaQueryType.
type ParcaQueryType string
const (
ParcaQueryTypeBoth ParcaQueryType = "both"
ParcaQueryTypeMetrics ParcaQueryType = "metrics"
ParcaQueryTypeProfile ParcaQueryType = "profile"
ParcaQueryTypeBoth ParcaQueryType = "both"
)
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
type ParcaDataQuery struct {
// Specifies the query label selectors.
LabelSelector string `json:"labelSelector"`
// Specifies the type of profile to query.
ProfileTypeId string `json:"profileTypeId"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
}
// ParcaDataQuery defines model for ParcaDataQuery.
type ParcaDataQuery struct {
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specifies the query label selectors.
LabelSelector *string `json:"labelSelector,omitempty"`
// Specifies the type of profile to query.
ProfileTypeId *string `json:"profileTypeId,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
Datasource any `json:"datasource,omitempty"`
}
// ParcaQueryType defines model for ParcaQueryType.
type ParcaQueryType string
// NewParcaDataQuery creates a new ParcaDataQuery object.
func NewParcaDataQuery() *ParcaDataQuery {
return &ParcaDataQuery{
LabelSelector: "{}",
}
}

View File

@@ -22,7 +22,6 @@ import (
"go.opentelemetry.io/otel/trace"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
"github.com/grafana/grafana/pkg/tsdb/parca/kinds/dataquery"
)
@@ -64,7 +63,7 @@ func (d *ParcaDatasource) query(ctx context.Context, pCtx backend.PluginContext,
return response
}
response.Frames = append(response.Frames, seriesToDataFrame(seriesResp, utils.Depointerizer(qm.ProfileTypeId))...)
response.Frames = append(response.Frames, seriesToDataFrame(seriesResp, qm.ProfileTypeId)...)
}
if query.QueryType == queryTypeProfile || query.QueryType == queryTypeBoth {
@@ -102,7 +101,7 @@ func makeProfileRequest(qm queryModel, query backend.DataQuery) *connect.Request
Mode: v1alpha1.QueryRequest_MODE_MERGE,
Options: &v1alpha1.QueryRequest_Merge{
Merge: &v1alpha1.MergeProfile{
Query: fmt.Sprintf("%s%s", utils.Depointerizer(qm.ProfileTypeId), utils.Depointerizer(qm.LabelSelector)),
Query: fmt.Sprintf("%s%s", qm.ProfileTypeId, qm.LabelSelector),
Start: &timestamppb.Timestamp{
Seconds: query.TimeRange.From.Unix(),
},
@@ -120,7 +119,7 @@ func makeProfileRequest(qm queryModel, query backend.DataQuery) *connect.Request
func makeMetricRequest(qm queryModel, query backend.DataQuery) *connect.Request[v1alpha1.QueryRangeRequest] {
return &connect.Request[v1alpha1.QueryRangeRequest]{
Msg: &v1alpha1.QueryRangeRequest{
Query: fmt.Sprintf("%s%s", utils.Depointerizer(qm.ProfileTypeId), utils.Depointerizer(qm.LabelSelector)),
Query: fmt.Sprintf("%s%s", qm.ProfileTypeId, qm.LabelSelector),
Start: &timestamppb.Timestamp{
Seconds: query.TimeRange.From.Unix(),
},

View File

@@ -7,164 +7,181 @@
//
// Run 'make gen-cue' from repository root to regenerate.
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package dataquery
// Defines values for SearchStreamingState.
const (
SearchStreamingStateDone SearchStreamingState = "done"
SearchStreamingStateError SearchStreamingState = "error"
SearchStreamingStatePending SearchStreamingState = "pending"
SearchStreamingStateStreaming SearchStreamingState = "streaming"
import (
json "encoding/json"
errors "errors"
fmt "fmt"
)
// Defines values for SearchTableType.
const (
SearchTableTypeRaw SearchTableType = "raw"
SearchTableTypeSpans SearchTableType = "spans"
SearchTableTypeTraces SearchTableType = "traces"
)
// Defines values for TempoQueryType.
const (
TempoQueryTypeClear TempoQueryType = "clear"
TempoQueryTypeNativeSearch TempoQueryType = "nativeSearch"
TempoQueryTypeServiceMap TempoQueryType = "serviceMap"
TempoQueryTypeTraceId TempoQueryType = "traceId"
TempoQueryTypeTraceql TempoQueryType = "traceql"
TempoQueryTypeTraceqlSearch TempoQueryType = "traceqlSearch"
TempoQueryTypeUpload TempoQueryType = "upload"
)
// Defines values for TraceqlSearchScope.
const (
TraceqlSearchScopeEvent TraceqlSearchScope = "event"
TraceqlSearchScopeInstrumentation TraceqlSearchScope = "instrumentation"
TraceqlSearchScopeIntrinsic TraceqlSearchScope = "intrinsic"
TraceqlSearchScopeLink TraceqlSearchScope = "link"
TraceqlSearchScopeResource TraceqlSearchScope = "resource"
TraceqlSearchScopeSpan TraceqlSearchScope = "span"
TraceqlSearchScopeUnscoped TraceqlSearchScope = "unscoped"
)
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
type DataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
type TempoQuery struct {
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId string `json:"refId"`
}
// The state of the TraceQL streaming search query
type SearchStreamingState string
// The type of the table that is used to display the search results
type SearchTableType string
// TempoDataQuery defines model for TempoDataQuery.
type TempoDataQuery = map[string]any
// TempoQuery defines model for TempoQuery.
type TempoQuery struct {
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// TraceQL query or trace ID
Query *string `json:"query,omitempty"`
// @deprecated Logfmt query to filter traces by their tags. Example: http.status_code=200 error=true
Search *string `json:"search,omitempty"`
// @deprecated Query traces by service name
ServiceName *string `json:"serviceName,omitempty"`
// @deprecated Query traces by span name
SpanName *string `json:"spanName,omitempty"`
// @deprecated Define the minimum duration to select traces. Use duration format, for example: 1.2s, 100ms
MinDuration *string `json:"minDuration,omitempty"`
// @deprecated Define the maximum duration to select traces. Use duration format, for example: 1.2s, 100ms
MaxDuration *string `json:"maxDuration,omitempty"`
// Filters to be included in a PromQL query to select data for the service graph. Example: {client="app",service="app"}. Providing multiple values will produce union of results for each filter, using PromQL OR operator internally.
ServiceMapQuery *StringOrArrayOfString `json:"serviceMapQuery,omitempty"`
// Use service.namespace in addition to service.name to uniquely identify a service.
ServiceMapIncludeNamespace *bool `json:"serviceMapIncludeNamespace,omitempty"`
// Defines the maximum number of traces that are returned from Tempo
Limit *int64 `json:"limit,omitempty"`
// Defines the maximum number of spans per spanset that are returned from Tempo
Spss *int64 `json:"spss,omitempty"`
Filters []TraceqlFilter `json:"filters"`
// Filters that are used to query the metrics summary
GroupBy []TraceqlFilter `json:"groupBy,omitempty"`
// The type of the table that is used to display the search results
TableType *SearchTableType `json:"tableType,omitempty"`
// For metric queries, the step size to use
Step *string `json:"step,omitempty"`
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *any `json:"datasource,omitempty"`
Datasource any `json:"datasource,omitempty"`
// For metric queries, how many exemplars to request, 0 means no exemplars
Exemplars *int64 `json:"exemplars,omitempty"`
Filters []TraceqlFilter `json:"filters,omitempty"`
// Filters that are used to query the metrics summary
GroupBy []TraceqlFilter `json:"groupBy,omitempty"`
// If hide is set to true, Grafana will filter out the response(s) associated with this query before returning it to the panel.
Hide *bool `json:"hide,omitempty"`
// Defines the maximum number of traces that are returned from Tempo
Limit *int64 `json:"limit,omitempty"`
// @deprecated Define the maximum duration to select traces. Use duration format, for example: 1.2s, 100ms
MaxDuration *string `json:"maxDuration,omitempty"`
// @deprecated Define the minimum duration to select traces. Use duration format, for example: 1.2s, 100ms
MinDuration *string `json:"minDuration,omitempty"`
// TraceQL query or trace ID
Query *string `json:"query,omitempty"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A unique identifier for the query within the list of targets.
// In server side expressions, the refId is used as a variable name to identify results.
// By default, the UI will assign A->Z; however setting meaningful names may be useful.
RefId *string `json:"refId,omitempty"`
// @deprecated Logfmt query to filter traces by their tags. Example: http.status_code=200 error=true
Search *string `json:"search,omitempty"`
// Use service.namespace in addition to service.name to uniquely identify a service.
ServiceMapIncludeNamespace *bool `json:"serviceMapIncludeNamespace,omitempty"`
// Filters to be included in a PromQL query to select data for the service graph. Example: {client="app",service="app"}. Providing multiple values will produce union of results for each filter, using PromQL OR operator internally.
ServiceMapQuery *any `json:"serviceMapQuery,omitempty"`
// @deprecated Query traces by service name
ServiceName *string `json:"serviceName,omitempty"`
// @deprecated Query traces by span name
SpanName *string `json:"spanName,omitempty"`
// Defines the maximum number of spans per spanset that are returned from Tempo
Spss *int64 `json:"spss,omitempty"`
// For metric queries, the step size to use
Step *string `json:"step,omitempty"`
// The type of the table that is used to display the search results
TableType *SearchTableType `json:"tableType,omitempty"`
Exemplars *int64 `json:"exemplars,omitempty"`
}
// NewTempoQuery creates a new TempoQuery object.
func NewTempoQuery() *TempoQuery {
return &TempoQuery{}
}
// TempoQueryType defines model for TempoQueryType.
type TempoQueryType string
// TraceqlFilter defines model for TraceqlFilter.
const (
TempoQueryTypeTraceql TempoQueryType = "traceql"
TempoQueryTypeTraceqlSearch TempoQueryType = "traceqlSearch"
TempoQueryTypeServiceMap TempoQueryType = "serviceMap"
TempoQueryTypeUpload TempoQueryType = "upload"
TempoQueryTypeNativeSearch TempoQueryType = "nativeSearch"
TempoQueryTypeTraceId TempoQueryType = "traceId"
TempoQueryTypeClear TempoQueryType = "clear"
)
// The state of the TraceQL streaming search query
type SearchStreamingState string
const (
SearchStreamingStatePending SearchStreamingState = "pending"
SearchStreamingStateStreaming SearchStreamingState = "streaming"
SearchStreamingStateDone SearchStreamingState = "done"
SearchStreamingStateError SearchStreamingState = "error"
)
// The type of the table that is used to display the search results
type SearchTableType string
const (
SearchTableTypeTraces SearchTableType = "traces"
SearchTableTypeSpans SearchTableType = "spans"
SearchTableTypeRaw SearchTableType = "raw"
)
// static fields are pre-set in the UI, dynamic fields are added by the user
type TraceqlSearchScope string
const (
TraceqlSearchScopeIntrinsic TraceqlSearchScope = "intrinsic"
TraceqlSearchScopeUnscoped TraceqlSearchScope = "unscoped"
TraceqlSearchScopeEvent TraceqlSearchScope = "event"
TraceqlSearchScopeInstrumentation TraceqlSearchScope = "instrumentation"
TraceqlSearchScopeLink TraceqlSearchScope = "link"
TraceqlSearchScopeResource TraceqlSearchScope = "resource"
TraceqlSearchScopeSpan TraceqlSearchScope = "span"
)
type TraceqlFilter struct {
// Uniquely identify the filter, will not be used in the query generation
Id string `json:"id"`
// The operator that connects the tag to the value, for example: =, >, !=, =~
Operator *string `json:"operator,omitempty"`
// Scope static fields are pre-set in the UI, dynamic fields are added by the user
Scope *TraceqlSearchScope `json:"scope,omitempty"`
// The tag for the search filter, for example: .http.status_code, .service.name, status
Tag *string `json:"tag,omitempty"`
// The operator that connects the tag to the value, for example: =, >, !=, =~
Operator *string `json:"operator,omitempty"`
// The value for the search filter
Value *any `json:"value,omitempty"`
Value *StringOrArrayOfString `json:"value,omitempty"`
// The type of the value, used for example to check whether we need to wrap the value in quotes when generating the query
ValueType *string `json:"valueType,omitempty"`
// The scope of the filter, can either be unscoped/all scopes, resource or span
Scope *TraceqlSearchScope `json:"scope,omitempty"`
}
// TraceqlSearchScope static fields are pre-set in the UI, dynamic fields are added by the user
type TraceqlSearchScope string
// NewTraceqlFilter creates a new TraceqlFilter object.
func NewTraceqlFilter() *TraceqlFilter {
return &TraceqlFilter{}
}
type StringOrArrayOfString struct {
String *string `json:"String,omitempty"`
ArrayOfString []string `json:"ArrayOfString,omitempty"`
}
// NewStringOrArrayOfString creates a new StringOrArrayOfString object.
func NewStringOrArrayOfString() *StringOrArrayOfString {
return &StringOrArrayOfString{}
}
// MarshalJSON implements a custom JSON marshalling logic to encode `StringOrArrayOfString` as JSON.
func (resource StringOrArrayOfString) MarshalJSON() ([]byte, error) {
if resource.String != nil {
return json.Marshal(resource.String)
}
if resource.ArrayOfString != nil {
return json.Marshal(resource.ArrayOfString)
}
return nil, fmt.Errorf("no value for disjunction of scalars")
}
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode `StringOrArrayOfString` from JSON.
func (resource *StringOrArrayOfString) UnmarshalJSON(raw []byte) error {
if raw == nil {
return nil
}
var errList []error
// String
var String string
if err := json.Unmarshal(raw, &String); err != nil {
errList = append(errList, err)
resource.String = nil
} else {
resource.String = &String
return nil
}
// ArrayOfString
var ArrayOfString []string
if err := json.Unmarshal(raw, &ArrayOfString); err != nil {
errList = append(errList, err)
resource.ArrayOfString = nil
} else {
resource.ArrayOfString = ArrayOfString
return nil
}
return errors.Join(errList...)
}

View File

@@ -13083,7 +13083,6 @@
},
"AnnotationPanelFilter": {
"type": "object",
"title": "AnnotationPanelFilter defines model for AnnotationPanelFilter.",
"properties": {
"exclude": {
"description": "Should the specified panels be included or excluded",
@@ -13094,7 +13093,7 @@
"type": "array",
"items": {
"type": "integer",
"format": "int64"
"format": "uint8"
}
}
}
@@ -13117,7 +13116,7 @@
"builtIn": {
"description": "Set to 1 for the standard annotation query all dashboards have by default.",
"type": "number",
"format": "float"
"format": "double"
},
"datasource": {
"$ref": "#/definitions/DataSourceRef"
@@ -13877,20 +13876,10 @@
},
"CookiePreferences": {
"type": "object",
"title": "CookiePreferences defines model for CookiePreferences.",
"properties": {
"analytics": {
"type": "object",
"additionalProperties": {}
},
"functional": {
"type": "object",
"additionalProperties": {}
},
"performance": {
"type": "object",
"additionalProperties": {}
}
"analytics": {},
"functional": {},
"performance": {}
}
},
"CookieType": {
@@ -16899,7 +16888,6 @@
},
"LibraryElementDTOMetaUser": {
"type": "object",
"title": "LibraryElementDTOMetaUser defines model for LibraryElementDTOMetaUser.",
"properties": {
"avatarUrl": {
"type": "string"
@@ -17289,7 +17277,6 @@
},
"NavbarPreference": {
"type": "object",
"title": "NavbarPreference defines model for NavbarPreference.",
"properties": {
"bookmarkUrls": {
"type": "array",
@@ -18494,7 +18481,7 @@
"$ref": "#/definitions/QueryHistoryPreference"
},
"theme": {
"description": "Theme light, dark, empty is default",
"description": "light, dark, empty is default",
"type": "string"
},
"timezone": {
@@ -18502,7 +18489,7 @@
"type": "string"
},
"weekStart": {
"description": "WeekStart day of the week (sunday, monday, etc)",
"description": "day of the week (sunday, monday, etc)",
"type": "string"
}
}
@@ -18965,10 +18952,9 @@
},
"QueryHistoryPreference": {
"type": "object",
"title": "QueryHistoryPreference defines model for QueryHistoryPreference.",
"properties": {
"homeTab": {
"description": "HomeTab one of: '' | 'query' | 'starred';",
"description": "one of: '' | 'query' | 'starred';",
"type": "string"
}
}

View File

@@ -3165,13 +3165,12 @@
"ids": {
"description": "Panel IDs that should be included or excluded",
"items": {
"format": "int64",
"format": "uint8",
"type": "integer"
},
"type": "array"
}
},
"title": "AnnotationPanelFilter defines model for AnnotationPanelFilter.",
"type": "object"
},
"AnnotationPermission": {
@@ -3190,7 +3189,7 @@
"properties": {
"builtIn": {
"description": "Set to 1 for the standard annotation query all dashboards have by default.",
"format": "float",
"format": "double",
"type": "number"
},
"datasource": {
@@ -3952,20 +3951,10 @@
},
"CookiePreferences": {
"properties": {
"analytics": {
"additionalProperties": {},
"type": "object"
},
"functional": {
"additionalProperties": {},
"type": "object"
},
"performance": {
"additionalProperties": {},
"type": "object"
}
"analytics": {},
"functional": {},
"performance": {}
},
"title": "CookiePreferences defines model for CookiePreferences.",
"type": "object"
},
"CookieType": {
@@ -6985,7 +6974,6 @@
"type": "string"
}
},
"title": "LibraryElementDTOMetaUser defines model for LibraryElementDTOMetaUser.",
"type": "object"
},
"LibraryElementResponse": {
@@ -7371,7 +7359,6 @@
"type": "array"
}
},
"title": "NavbarPreference defines model for NavbarPreference.",
"type": "object"
},
"NewApiKeyResult": {
@@ -8568,7 +8555,7 @@
"$ref": "#/components/schemas/QueryHistoryPreference"
},
"theme": {
"description": "Theme light, dark, empty is default",
"description": "light, dark, empty is default",
"type": "string"
},
"timezone": {
@@ -8576,7 +8563,7 @@
"type": "string"
},
"weekStart": {
"description": "WeekStart day of the week (sunday, monday, etc)",
"description": "day of the week (sunday, monday, etc)",
"type": "string"
}
},
@@ -9041,11 +9028,10 @@
"QueryHistoryPreference": {
"properties": {
"homeTab": {
"description": "HomeTab one of: '' | 'query' | 'starred';",
"description": "one of: '' | 'query' | 'starred';",
"type": "string"
}
},
"title": "QueryHistoryPreference defines model for QueryHistoryPreference.",
"type": "object"
},
"QueryHistoryResponse": {