Schemas: Reduce duplicated jenny code (#84061)

* Remove jenny_ts_resources and use jenny_ts_types for all cases

* Unify TS generated files into one jenny

* Add missing imports to versioned files

* Update Parca plugin

* Fix loki

* Use LokiQuery

* Fix pyroscope tests

* Fix prettier

* 😒 fix default pyroscope value name

* Set the LokiQuery

* Update Elasticsearch and TestData

* Missed files from testdata

* Order imports
This commit is contained in:
Selene 2024-03-11 12:51:44 +01:00 committed by GitHub
parent bd9f9c9eb0
commit 275ccf994b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
97 changed files with 320 additions and 429 deletions

View File

@ -19,6 +19,8 @@ import (
"cuelang.org/go/cue/errors"
"github.com/grafana/codejen"
"github.com/grafana/cuetsy"
"github.com/grafana/cuetsy/ts"
"github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/kindsys"
"github.com/grafana/grafana/pkg/codegen"
@ -44,8 +46,7 @@ func main() {
codegen.BaseCoreRegistryJenny(filepath.Join("pkg", "registry", "corekind"), cuectx.GoCoreKindParentPath),
codegen.LatestMajorsOrXJenny(
cuectx.TSCoreKindParentPath,
true, // forcing group so that we ignore the top level resource (for now)
codegen.TSResourceJenny{}),
codegen.TSTypesJenny{ApplyFuncs: []codegen.ApplyFunc{renameSpecNode}}),
codegen.TSVeneerIndexJenny(filepath.Join("packages", "grafana-schema", "src")),
)
@ -232,3 +233,48 @@ func loadCueFiles(dirs []os.DirEntry) []cue.Value {
return values
}
// renameSpecNode rename spec node from the TS file result
func renameSpecNode(sfg codegen.SchemaForGen, tf *ast.File) {
specidx, specdefidx := -1, -1
for idx, def := range tf.Nodes {
// Peer through export keywords
if ex, is := def.(ast.ExportKeyword); is {
def = ex.Decl
}
switch x := def.(type) {
case ast.TypeDecl:
if x.Name.Name == "spec" {
specidx = idx
x.Name.Name = sfg.Name
tf.Nodes[idx] = x
}
case ast.VarDecl:
// Before:
// export const defaultspec: Partial<spec> = {
// After:
// / export const defaultPlaylist: Partial<Playlist> = {
if x.Names.Idents[0].Name == "defaultspec" {
specdefidx = idx
x.Names.Idents[0].Name = "default" + sfg.Name
tt := x.Type.(ast.TypeTransformExpr)
tt.Expr = ts.Ident(sfg.Name)
x.Type = tt
tf.Nodes[idx] = x
}
}
}
if specidx != -1 {
decl := tf.Nodes[specidx]
tf.Nodes = append(append(tf.Nodes[:specidx], tf.Nodes[specidx+1:]...), decl)
}
if specdefidx != -1 {
if specdefidx > specidx {
specdefidx--
}
decl := tf.Nodes[specdefidx]
tf.Nodes = append(append(tf.Nodes[:specdefidx], tf.Nodes[specdefidx+1:]...), decl)
}
}

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,8 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// LatestMajorsOrXJenny
// PluginEachMajorJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -3,7 +3,7 @@
// Generated by:
// kinds/gen.go
// Using jennies:
// TSResourceJenny
// TSTypesJenny
// LatestMajorsOrXJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -11,22 +11,20 @@ import (
// LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version.
//
// TODO remove forceGroup option, it's a temporary hack to accommodate core kinds
func LatestMajorsOrXJenny(parentdir string, forceGroup bool, inner codejen.OneToOne[SchemaForGen]) OneToMany {
func LatestMajorsOrXJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToMany {
if inner == nil {
panic("inner jenny must not be nil")
}
return &lmox{
parentdir: parentdir,
inner: inner,
forceGroup: forceGroup,
parentdir: parentdir,
inner: inner,
}
}
type lmox struct {
parentdir string
inner codejen.OneToOne[SchemaForGen]
forceGroup bool
parentdir string
inner codejen.OneToOne[SchemaForGen]
}
func (j *lmox) JennyName() string {
@ -42,49 +40,19 @@ func (j *lmox) Generate(kind kindsys.Kind) (codejen.Files, error) {
comm := kind.Props().Common()
sfg := SchemaForGen{
Name: comm.Name,
IsGroup: comm.LineageIsGroup,
IsGroup: true,
Schema: kind.Lineage().Latest(),
}
if j.forceGroup {
sfg.IsGroup = true
f, err := j.inner.Generate(sfg)
if err != nil {
return nil, fmt.Errorf("%s jenny failed on %s schema for %s: %w", j.inner.JennyName(), sfg.Schema.Version(), kind.Props().Common().Name, err)
}
if f == nil || !f.Exists() {
return nil, nil
}
do := func(sfg SchemaForGen, infix string) (codejen.Files, error) {
f, err := j.inner.Generate(sfg)
if err != nil {
return nil, fmt.Errorf("%s jenny failed on %s schema for %s: %w", j.inner.JennyName(), sfg.Schema.Version(), kind.Props().Common().Name, err)
}
if f == nil || !f.Exists() {
return nil, nil
}
f.RelativePath = filepath.Join(j.parentdir, comm.MachineName, infix, f.RelativePath)
f.From = append(f.From, j)
return codejen.Files{*f}, nil
}
if comm.Maturity.Less(kindsys.MaturityStable) {
sfg.Schema = kind.Lineage().Latest()
return do(sfg, "x")
}
var fl codejen.Files
major := -1
for sch := kind.Lineage().First(); sch != nil; sch = sch.Successor() {
if int(sch.Version()[0]) == major {
continue
}
major = int(sch.Version()[0])
sfg.Schema = sch.LatestInMajor()
files, err := do(sfg, fmt.Sprintf("v%v", sch.Version()[0]))
if err != nil {
return nil, err
}
fl = append(fl, files...)
}
if fl.Validate() != nil {
return nil, fl.Validate()
}
return fl, nil
f.RelativePath = filepath.Join(j.parentdir, comm.MachineName, "x", f.RelativePath)
f.From = append(f.From, j)
return codejen.Files{*f}, nil
}

View File

@ -1,85 +0,0 @@
package codegen
import (
"github.com/grafana/codejen"
"github.com/grafana/cuetsy"
"github.com/grafana/cuetsy/ts"
"github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/thema/encoding/typescript"
)
// TSResourceJenny is a [OneToOne] that produces TypeScript types and
// defaults for a Thema schema.
//
// Thema's generic TS jenny will be able to replace this one once
// https://github.com/grafana/thema/issues/89 is complete.
type TSResourceJenny struct{}
var _ codejen.OneToOne[SchemaForGen] = &TSResourceJenny{}
func (j TSResourceJenny) JennyName() string {
return "TSResourceJenny"
}
func (j TSResourceJenny) Generate(sfg SchemaForGen) (*codejen.File, error) {
// TODO allow using name instead of machine name in thema generator
f, err := typescript.GenerateTypes(sfg.Schema, &typescript.TypeConfig{
RootName: sfg.Name,
Group: sfg.IsGroup,
CuetsyConfig: &cuetsy.Config{
Export: true,
ImportMapper: cuectx.MapCUEImportToTS,
},
})
if err != nil {
return nil, err
}
renameSpecNode(sfg.Name, f)
return codejen.NewFile(sfg.Schema.Lineage().Name()+"_types.gen.ts", []byte(f.String()), j), nil
}
func renameSpecNode(name string, tf *ast.File) {
specidx, specdefidx := -1, -1
for idx, def := range tf.Nodes {
// Peer through export keywords
if ex, is := def.(ast.ExportKeyword); is {
def = ex.Decl
}
switch x := def.(type) {
case ast.TypeDecl:
if x.Name.Name == "spec" {
specidx = idx
x.Name.Name = name
tf.Nodes[idx] = x
}
case ast.VarDecl:
// Before:
// export const defaultspec: Partial<spec> = {
// After:
/// export const defaultPlaylist: Partial<Playlist> = {
if x.Names.Idents[0].Name == "defaultspec" {
specdefidx = idx
x.Names.Idents[0].Name = "default" + name
tt := x.Type.(ast.TypeTransformExpr)
tt.Expr = ts.Ident(name)
x.Type = tt
tf.Nodes[idx] = x
}
}
}
if specidx != -1 {
decl := tf.Nodes[specidx]
tf.Nodes = append(append(tf.Nodes[:specidx], tf.Nodes[specidx+1:]...), decl)
}
if specdefidx != -1 {
if specdefidx > specidx {
specdefidx--
}
decl := tf.Nodes[specdefidx]
tf.Nodes = append(append(tf.Nodes[:specdefidx], tf.Nodes[specdefidx+1:]...), decl)
}
}

View File

@ -3,16 +3,21 @@ package codegen
import (
"github.com/grafana/codejen"
"github.com/grafana/cuetsy"
"github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/thema/encoding/typescript"
)
type ApplyFunc func(sfg SchemaForGen, file *ast.File)
// TSTypesJenny is a [OneToOne] that produces TypeScript types and
// defaults for a Thema schema.
//
// Thema's generic TS jenny will be able to replace this one once
// https://github.com/grafana/thema/issues/89 is complete.
type TSTypesJenny struct{}
type TSTypesJenny struct {
ApplyFuncs []ApplyFunc
}
var _ codejen.OneToOne[SchemaForGen] = &TSTypesJenny{}
@ -30,6 +35,11 @@ func (j TSTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error) {
RootName: sfg.Name,
Group: sfg.IsGroup,
})
for _, renameFunc := range j.ApplyFuncs {
renameFunc(sfg, f)
}
if err != nil {
return nil, err
}

View File

@ -1,101 +0,0 @@
package codegen
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/grafana/codejen"
tsast "github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/grafana/pkg/build"
corecodegen "github.com/grafana/grafana/pkg/codegen"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/plugins/pfs"
"github.com/grafana/kindsys"
"github.com/grafana/thema"
)
func PluginTSEachMajor(rt *thema.Runtime) codejen.OneToMany[*pfs.PluginDecl] {
latestMajorsOrX := corecodegen.LatestMajorsOrXJenny(filepath.Join("packages", "grafana-schema", "src", "raw", "composable"), false, corecodegen.TSTypesJenny{})
return &pleJenny{
inner: kinds2pd(rt, latestMajorsOrX),
}
}
type pleJenny struct {
inner codejen.OneToMany[*pfs.PluginDecl]
}
func (*pleJenny) JennyName() string {
return "PluginEachMajorJenny"
}
func (j *pleJenny) Generate(decl *pfs.PluginDecl) (codejen.Files, error) {
if !decl.HasSchema() {
return nil, nil
}
jf, err := j.inner.Generate(decl)
if err != nil {
return nil, err
}
version := "export const pluginVersion = \"%s\";"
if decl.PluginMeta.Version != nil {
version = fmt.Sprintf(version, *decl.PluginMeta.Version)
} else {
version = fmt.Sprintf(version, getGrafanaVersion())
}
files := make(codejen.Files, len(jf))
for i, file := range jf {
tsf := &tsast.File{}
for _, im := range decl.Imports {
if tsim, err := cuectx.ConvertImport(im); err != nil {
return nil, err
} else if tsim.From.Value != "" {
tsf.Imports = append(tsf.Imports, tsim)
}
}
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
Data: version,
})
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
Data: string(file.Data),
})
data := []byte(tsf.String())
data = data[:len(data)-1] // remove the additional line break added by the inner jenny
files[i] = *codejen.NewFile(file.RelativePath, data, append(file.From, j)...)
}
return files, nil
}
func kinds2pd(rt *thema.Runtime, j codejen.OneToMany[kindsys.Kind]) codejen.OneToMany[*pfs.PluginDecl] {
return codejen.AdaptOneToMany(j, func(pd *pfs.PluginDecl) kindsys.Kind {
kd, err := kindsys.BindComposable(rt, pd.KindDecl)
if err != nil {
return nil
}
return kd
})
}
func getGrafanaVersion() string {
dir, err := os.Getwd()
if err != nil {
return ""
}
pkg, err := build.OpenPackageJSON(path.Join(dir, "../../../"))
if err != nil {
return ""
}
return pkg.Version
}

View File

@ -2,19 +2,25 @@ package codegen
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"github.com/grafana/codejen"
tsast "github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/grafana/pkg/build"
"github.com/grafana/grafana/pkg/codegen"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/plugins/pfs"
)
func PluginTSTypesJenny(root string, inner codejen.OneToOne[*pfs.PluginDecl]) codejen.OneToOne[*pfs.PluginDecl] {
var versionedPluginPath = filepath.Join("packages", "grafana-schema", "src", "raw", "composable")
func PluginTSTypesJenny(root string) codejen.OneToMany[*pfs.PluginDecl] {
return &ptsJenny{
root: root,
inner: inner,
inner: adaptToPipeline(codegen.TSTypesJenny{}),
}
}
@ -24,21 +30,23 @@ type ptsJenny struct {
}
func (j *ptsJenny) JennyName() string {
return "PluginTSTypesJenny"
return "PluginTsTypesJenny"
}
func (j *ptsJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
func (j *ptsJenny) Generate(decl *pfs.PluginDecl) (codejen.Files, error) {
if !decl.HasSchema() {
return nil, nil
}
tsf := &tsast.File{}
genFile := &tsast.File{}
versionedFile := &tsast.File{}
for _, im := range decl.Imports {
if tsim, err := cuectx.ConvertImport(im); err != nil {
return nil, err
} else if tsim.From.Value != "" {
tsf.Imports = append(tsf.Imports, tsim)
genFile.Imports = append(genFile.Imports, tsim)
versionedFile.Imports = append(versionedFile.Imports, tsim)
}
}
@ -47,13 +55,67 @@ func (j *ptsJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
return nil, err
}
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
Data: string(jf.Data),
})
rawData := tsast.Raw{Data: string(jf.Data)}
rawVersion := tsast.Raw{
Data: getPluginVersion(decl.PluginMeta.Version),
}
path := filepath.Join(j.root, decl.PluginPath, fmt.Sprintf("%s.gen.ts", strings.ToLower(decl.SchemaInterface.Name)))
data := []byte(tsf.String())
genFile.Nodes = append(genFile.Nodes, rawData)
genPath := filepath.Join(j.root, decl.PluginPath, fmt.Sprintf("%s.gen.ts", strings.ToLower(decl.SchemaInterface.Name)))
data := []byte(genFile.String())
data = data[:len(data)-1] // remove the additional line break added by the inner jenny
return codejen.NewFile(path, data, append(jf.From, j)...), nil
files := make(codejen.Files, 2)
files[0] = *codejen.NewFile(genPath, data, append(jf.From, j)...)
versionedFile.Nodes = append(versionedFile.Nodes, rawVersion, rawData)
versionedData := []byte(versionedFile.String())
versionedData = versionedData[:len(versionedData)-1]
pluginFolder := strings.ReplaceAll(strings.ToLower(decl.PluginMeta.Name), " ", "")
versionedPath := filepath.Join(versionedPluginPath, pluginFolder, strings.ToLower(decl.SchemaInterface.Name), "x", jf.RelativePath)
files[1] = *codejen.NewFile(versionedPath, versionedData, append(jf.From, j)...)
return files, nil
}
func getPluginVersion(pluginVersion *string) string {
version := "export const pluginVersion = \"%s\";"
if pluginVersion != nil {
version = fmt.Sprintf(version, *pluginVersion)
} else {
version = fmt.Sprintf(version, getGrafanaVersion())
}
return version
}
func adaptToPipeline(j codejen.OneToOne[codegen.SchemaForGen]) codejen.OneToOne[*pfs.PluginDecl] {
return codejen.AdaptOneToOne(j, func(pd *pfs.PluginDecl) codegen.SchemaForGen {
name := strings.ReplaceAll(pd.PluginMeta.Name, " ", "")
if pd.SchemaInterface.Name == "DataQuery" {
name = name + "DataQuery"
}
return codegen.SchemaForGen{
Name: name,
Schema: pd.Lineage.Latest(),
IsGroup: pd.SchemaInterface.IsGroup,
}
})
}
func getGrafanaVersion() string {
dir, err := os.Getwd()
if err != nil {
return ""
}
pkg, err := build.OpenPackageJSON(path.Join(dir, "../../../"))
if err != nil {
return ""
}
return pkg.Version
}

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -372,4 +372,4 @@ export interface WorkspacesQuery extends BaseGrafanaTemplateVariableQuery {
export type GrafanaTemplateVariableQuery = (AppInsightsMetricNameQuery | AppInsightsGroupByQuery | SubscriptionsQuery | ResourceGroupsQuery | ResourceNamesQuery | MetricNamespaceQuery | MetricDefinitionsQuery | MetricNamesQuery | WorkspacesQuery | UnknownQuery);
export interface AzureMonitor {}
export interface AzureMonitorDataQuery {}

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -375,4 +375,4 @@ export enum MetricFindQueryTypes {
Services = 'services',
}
export interface GoogleCloudMonitoring {}
export interface GoogleCloudMonitoringDataQuery {}

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -304,4 +304,4 @@ export interface CloudWatchAnnotationQuery extends common.DataQuery, MetricStat
queryMode: CloudWatchQueryMode;
}
export interface CloudWatch {}
export interface CloudWatchDataQuery {}

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -376,7 +376,7 @@ export type PipelineMetricAggregation = (MovingAverage | Derivative | Cumulative
export type MetricAggregationWithSettings = (BucketScript | CumulativeSum | Derivative | SerialDiff | RawData | RawDocument | UniqueCount | Percentiles | ExtendedStats | Min | Max | Sum | Average | MovingAverage | MovingFunction | Logs | Rate | TopMetrics);
export interface Elasticsearch extends common.DataQuery {
export interface ElasticsearchDataQuery extends common.DataQuery {
/**
* Alias pattern
*/
@ -399,7 +399,7 @@ export interface Elasticsearch extends common.DataQuery {
timeField?: string;
}
export const defaultElasticsearch: Partial<Elasticsearch> = {
export const defaultElasticsearchDataQuery: Partial<ElasticsearchDataQuery> = {
bucketAggs: [],
metrics: [],
};

View File

@ -15,11 +15,11 @@ import {
MovingAverage as SchemaMovingAverage,
BucketAggregation,
Logs as SchemaLogs,
Elasticsearch,
ElasticsearchDataQuery,
} from './dataquery.gen';
export * from './dataquery.gen';
export { Elasticsearch as ElasticsearchQuery } from './dataquery.gen';
export { ElasticsearchDataQuery as ElasticsearchQuery } from './dataquery.gen';
// We want to extend the settings of the Logs query with additional properties that
// are not part of the schema. This is a workaround, because exporting LogsSettings
@ -127,7 +127,7 @@ export type DataLinkConfig = {
};
export interface ElasticsearchAnnotationQuery {
target: Elasticsearch;
target: ElasticsearchDataQuery;
timeField?: string;
titleField?: string;
timeEndField?: string;

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -14,7 +14,7 @@ export type PyroscopeQueryType = ('metrics' | 'profile' | 'both');
export const defaultPyroscopeQueryType: PyroscopeQueryType = 'both';
export interface GrafanaPyroscope extends common.DataQuery {
export interface GrafanaPyroscopeDataQuery extends common.DataQuery {
/**
* Allows to group the results.
*/
@ -37,7 +37,7 @@ export interface GrafanaPyroscope extends common.DataQuery {
spanSelector?: Array<string>;
}
export const defaultGrafanaPyroscope: Partial<GrafanaPyroscope> = {
export const defaultGrafanaPyroscopeDataQuery: Partial<GrafanaPyroscopeDataQuery> = {
groupBy: [],
labelSelector: '{}',
spanSelector: [],

View File

@ -12,7 +12,7 @@ import {
import { DataSourceWithBackend, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { VariableSupport } from './VariableSupport';
import { defaultGrafanaPyroscope, defaultPyroscopeQueryType } from './dataquery.gen';
import { defaultGrafanaPyroscopeDataQuery, defaultPyroscopeQueryType } from './dataquery.gen';
import { PyroscopeDataSourceOptions, Query, ProfileTypeMessage } from './types';
import { extractLabelMatchers, toPromLikeExpr } from './utils';
@ -115,7 +115,7 @@ export class PyroscopeDataSource extends DataSourceWithBackend<Query, PyroscopeD
}
export const defaultQuery: Partial<Query> = {
...defaultGrafanaPyroscope,
...defaultGrafanaPyroscopeDataQuery,
queryType: defaultPyroscopeQueryType,
};

View File

@ -1,8 +1,8 @@
import { DataSourceJsonData } from '@grafana/data';
import { GrafanaPyroscope, PyroscopeQueryType } from './dataquery.gen';
import { GrafanaPyroscopeDataQuery, PyroscopeQueryType } from './dataquery.gen';
export interface Query extends GrafanaPyroscope {
export interface Query extends GrafanaPyroscopeDataQuery {
queryType: PyroscopeQueryType;
}

View File

@ -3,10 +3,10 @@ import React from 'react';
import { MetadataInspectorProps } from '@grafana/data';
import { Stack } from '@grafana/ui';
import { TestData } from './dataquery.gen';
import { TestDataDataQuery } from './dataquery.gen';
import { TestDataDataSource } from './datasource';
export type Props = MetadataInspectorProps<TestDataDataSource, TestData>;
export type Props = MetadataInspectorProps<TestDataDataSource, TestDataDataQuery>;
export function MetaDataInspector({ data }: Props) {
return (

View File

@ -17,7 +17,7 @@ import { RawFrameEditor } from './components/RawFrameEditor';
import { SimulationQueryEditor } from './components/SimulationQueryEditor';
import { USAQueryEditor, usaQueryModes } from './components/USAQueryEditor';
import { defaultCSVWaveQuery, defaultPulseQuery, defaultQuery } from './constants';
import { CSVWave, NodesQuery, TestData, TestDataQueryType, USAQuery } from './dataquery.gen';
import { CSVWave, NodesQuery, TestDataDataQuery, TestDataQueryType, USAQuery } from './dataquery.gen';
import { TestDataDataSource } from './datasource';
import { defaultStreamQuery } from './runStreams';
@ -31,11 +31,11 @@ const selectors = editorSelectors.components.DataSource.TestData.QueryTab;
export interface EditorProps {
onChange: (value: any) => void;
query: TestData;
query: TestDataDataQuery;
ds: TestDataDataSource;
}
export type Props = QueryEditorProps<TestDataDataSource, TestData>;
export type Props = QueryEditorProps<TestDataDataSource, TestDataDataQuery>;
export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) => {
query = { ...defaultQuery, ...query };
@ -63,7 +63,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
}));
}, []);
const onUpdate = (query: TestData) => {
const onUpdate = (query: TestDataDataQuery) => {
onChange(query);
onRunQuery();
};
@ -83,7 +83,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
}
// Clear model from existing props that belong to other scenarios
const update: TestData = {
const update: TestDataDataQuery = {
scenarioId: item.value! as TestDataQueryType,
refId: query.refId,
alias: query.alias,

View File

@ -2,11 +2,11 @@ import React from 'react';
import { Input, InlineFieldRow, InlineField, Select } from '@grafana/ui';
import { NodesQuery, TestData } from '../dataquery.gen';
import { NodesQuery, TestDataDataQuery } from '../dataquery.gen';
export interface Props {
onChange: (value: NodesQuery) => void;
query: TestData;
query: TestDataDataQuery;
}
export function NodeGraphEditor({ query, onChange }: Props) {
const type = query.nodes?.type || 'random';

View File

@ -4,7 +4,7 @@ import { selectors } from '@grafana/e2e-selectors';
import { InlineField, InlineFieldRow, Input } from '@grafana/ui';
import { EditorProps } from '../QueryEditor';
import { TestData } from '../dataquery.gen';
import { TestDataDataQuery } from '../dataquery.gen';
const randomWalkFields: Array<{
label: string;
@ -49,7 +49,7 @@ export const RandomWalkEditor = ({ onChange, query }: EditorProps) => {
id={`randomWalk-${id}-${query.refId}`}
min={min}
step={step}
value={(query as any)[id as keyof TestData] || placeholder}
value={(query as any)[id as keyof TestDataDataQuery] || placeholder}
placeholder={placeholder}
onChange={onChange}
/>

View File

@ -1,4 +1,4 @@
import { CSVWave, PulseWaveQuery, TestData, TestDataQueryType } from './dataquery.gen';
import { CSVWave, PulseWaveQuery, TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
export const defaultPulseQuery: PulseWaveQuery = {
timeStep: 60,
@ -15,7 +15,7 @@ export const defaultCSVWaveQuery: CSVWave[] = [
},
];
export const defaultQuery: TestData = {
export const defaultQuery: TestDataDataQuery = {
scenarioId: TestDataQueryType.RandomWalk,
refId: '',
};

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -106,7 +106,7 @@ export interface Scenario {
stringInput: string;
}
export interface TestData extends common.DataQuery {
export interface TestDataDataQuery extends common.DataQuery {
alias?: string;
channel?: string;
csvContent?: string;
@ -134,7 +134,7 @@ export interface TestData extends common.DataQuery {
usa?: USAQuery;
}
export const defaultTestData: Partial<TestData> = {
export const defaultTestDataDataQuery: Partial<TestDataDataQuery> = {
csvWave: [],
points: [],
scenarioId: TestDataQueryType.RandomWalk,

View File

@ -20,14 +20,14 @@ import {
} from '@grafana/data';
import { DataSourceWithBackend, getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { Scenario, TestData, TestDataQueryType } from './dataquery.gen';
import { Scenario, TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
import { queryMetricTree } from './metricTree';
import { generateRandomEdges, generateRandomNodes, savedNodesResponse } from './nodeGraphUtils';
import { runStream } from './runStreams';
import { flameGraphData, flameGraphDataDiff } from './testData/flameGraphResponse';
import { TestDataVariableSupport } from './variables';
export class TestDataDataSource extends DataSourceWithBackend<TestData> {
export class TestDataDataSource extends DataSourceWithBackend<TestDataDataQuery> {
scenariosCache?: Promise<Scenario[]>;
constructor(
@ -40,7 +40,7 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
getDefaultQuery: () => ({ scenarioId: TestDataQueryType.Annotations, lines: 10 }),
// Make sure annotations have scenarioId set
prepareAnnotation: (old: AnnotationQuery<TestData>) => {
prepareAnnotation: (old: AnnotationQuery<TestDataDataQuery>) => {
if (old.target?.scenarioId?.length) {
return old;
}
@ -56,15 +56,15 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
};
}
getDefaultQuery(): Partial<TestData> {
getDefaultQuery(): Partial<TestDataDataQuery> {
return {
scenarioId: TestDataQueryType.RandomWalk,
seriesCount: 1,
};
}
query(options: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
const backendQueries: TestData[] = [];
query(options: DataQueryRequest<TestDataDataQuery>): Observable<DataQueryResponse> {
const backendQueries: TestDataDataQuery[] = [];
const streams: Array<Observable<DataQueryResponse>> = [];
// Start streams and prepare queries
@ -141,7 +141,7 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return merge(...streams);
}
resolveTemplateVariables(query: TestData, scopedVars: ScopedVars) {
resolveTemplateVariables(query: TestDataDataQuery, scopedVars: ScopedVars) {
if (query.labels) {
query.labels = this.templateSrv.replace(query.labels, scopedVars);
}
@ -162,12 +162,15 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
}
}
applyTemplateVariables(query: TestData, scopedVars: ScopedVars): TestData {
applyTemplateVariables(query: TestDataDataQuery, scopedVars: ScopedVars): TestDataDataQuery {
this.resolveTemplateVariables(query, scopedVars);
return query;
}
annotationDataTopicTest(target: TestData, req: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
annotationDataTopicTest(
target: TestDataDataQuery,
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
const events = this.buildFakeAnnotationEvents(req.range, target.lines ?? 10);
const dataFrame = new ArrayDataFrame(events);
dataFrame.meta = { dataTopic: DataTopic.Annotations };
@ -192,7 +195,7 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return events;
}
getQueryDisplayText(query: TestData) {
getQueryDisplayText(query: TestDataDataQuery) {
const scenario = query.scenarioId ?? 'Default scenario';
if (query.alias) {
@ -217,7 +220,10 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return this.scenariosCache;
}
variablesQuery(target: TestData, options: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
variablesQuery(
target: TestDataDataQuery,
options: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
const query = target.stringInput ?? '';
const interpolatedQuery = this.templateSrv.replace(query, getSearchFilterScopedVar({ query, wildcardChar: '*' }));
const children = queryMetricTree(interpolatedQuery);
@ -227,7 +233,7 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return of({ data: [dataFrame] }).pipe(delay(100));
}
nodesQuery(target: TestData, options: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
nodesQuery(target: TestDataDataQuery, options: DataQueryRequest<TestDataDataQuery>): Observable<DataQueryResponse> {
const type = target.nodes?.type || 'random';
let frames: DataFrame[];
switch (type) {
@ -250,12 +256,12 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return of({ data: frames }).pipe(delay(100));
}
flameGraphQuery(target: TestData): Observable<DataQueryResponse> {
flameGraphQuery(target: TestDataDataQuery): Observable<DataQueryResponse> {
const data = target.flamegraphDiff ? flameGraphDataDiff : flameGraphData;
return of({ data: [{ ...data, refId: target.refId }] }).pipe(delay(100));
}
trace(options: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
trace(options: DataQueryRequest<TestDataDataQuery>): Observable<DataQueryResponse> {
const frame = new MutableDataFrame({
meta: {
preferredVisualisationType: 'trace',
@ -317,7 +323,10 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
return of({ data: [frame] }).pipe(delay(100));
}
rawFrameQuery(target: TestData, options: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
rawFrameQuery(
target: TestDataDataQuery,
options: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
try {
const data = JSON.parse(target.rawFrameContent ?? '[]').map((v: any) => {
const f = toDataFrame(v);
@ -333,7 +342,10 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
}
}
serverErrorQuery(target: TestData, options: DataQueryRequest<TestData>): Observable<DataQueryResponse> | null {
serverErrorQuery(
target: TestDataDataQuery,
options: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> | null {
const { errorType } = target;
if (errorType === 'server_panic') {
@ -353,7 +365,10 @@ export class TestDataDataSource extends DataSourceWithBackend<TestData> {
}
}
function runGrafanaAPI(target: TestData, req: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
function runGrafanaAPI(
target: TestDataDataQuery,
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
const url = `/api/${target.stringInput}`;
return from(
getBackendSrv()
@ -370,7 +385,10 @@ function runGrafanaAPI(target: TestData, req: DataQueryRequest<TestData>): Obser
let liveQueryCounter = 1000;
function runGrafanaLiveQuery(target: TestData, req: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
function runGrafanaLiveQuery(
target: TestDataDataQuery,
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
if (!target.channel) {
throw new Error(`Missing channel config`);
}

View File

@ -20,7 +20,7 @@ import {
} from '@grafana/data';
import { getRandomLine } from './LogIpsum';
import { TestData, StreamingQuery } from './dataquery.gen';
import { TestDataDataQuery, StreamingQuery } from './dataquery.gen';
export const defaultStreamQuery: StreamingQuery = {
type: 'signal',
@ -30,7 +30,10 @@ export const defaultStreamQuery: StreamingQuery = {
bands: 1,
};
export function runStream(target: TestData, req: DataQueryRequest<TestData>): Observable<DataQueryResponse> {
export function runStream(
target: TestDataDataQuery,
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
const query = defaults(target.stream, defaultStreamQuery);
switch (query.type) {
case 'signal':
@ -46,9 +49,9 @@ export function runStream(target: TestData, req: DataQueryRequest<TestData>): Ob
}
export function runSignalStream(
target: TestData,
target: TestDataDataQuery,
query: StreamingQuery,
req: DataQueryRequest<TestData>
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>((subscriber) => {
const streamId = `signal-${req.panelId || 'explore'}-${target.refId}`;
@ -128,9 +131,9 @@ export function runSignalStream(
}
export function runLogsStream(
target: TestData,
target: TestDataDataQuery,
query: StreamingQuery,
req: DataQueryRequest<TestData>
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>((subscriber) => {
const streamId = `logs-${req.panelId || 'explore'}-${target.refId}`;
@ -174,9 +177,9 @@ export function runLogsStream(
}
export function runFetchStream(
target: TestData,
target: TestDataDataQuery,
query: StreamingQuery,
req: DataQueryRequest<TestData>
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>((subscriber) => {
const streamId = `fetch-${req.panelId || 'explore'}-${target.refId}`;
@ -252,9 +255,9 @@ export function runFetchStream(
}
export function runTracesStream(
target: TestData,
target: TestDataDataQuery,
query: StreamingQuery,
req: DataQueryRequest<TestData>
req: DataQueryRequest<TestDataDataQuery>
): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>((subscriber) => {
const streamId = `traces-${req.panelId || 'explore'}-${target.refId}`;
@ -285,7 +288,7 @@ export function runTracesStream(
});
}
function createMainTraceFrame(target: TestData, maxDataPoints = 1000) {
function createMainTraceFrame(target: TestDataDataQuery, maxDataPoints = 1000) {
const data = new CircularDataFrame({
append: 'head',
capacity: maxDataPoints,

View File

@ -1,10 +1,10 @@
import { StandardVariableQuery, StandardVariableSupport } from '@grafana/data';
import { TestData, TestDataQueryType } from './dataquery.gen';
import { TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
import { TestDataDataSource } from './datasource';
export class TestDataVariableSupport extends StandardVariableSupport<TestDataDataSource> {
toDataQuery(query: StandardVariableQuery): TestData {
toDataQuery(query: StandardVariableQuery): TestDataDataQuery {
return {
refId: 'TestDataDataSource-QueryVariable',
stringInput: query.query,

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -33,7 +33,7 @@ export enum LokiQueryDirection {
Forward = 'forward',
}
export interface Loki extends common.DataQuery {
export interface LokiDataQuery extends common.DataQuery {
editorMode?: QueryEditorMode;
/**
* The LogQL query.

View File

@ -1,6 +1,11 @@
import { DataQuery, DataQueryRequest, DataSourceJsonData, TimeRange } from '@grafana/data';
import { Loki as LokiQueryFromSchema, LokiQueryType, SupportingQueryType, LokiQueryDirection } from './dataquery.gen';
import {
LokiDataQuery as LokiQueryFromSchema,
LokiQueryType,
SupportingQueryType,
LokiQueryDirection,
} from './dataquery.gen';
export { LokiQueryDirection, LokiQueryType, SupportingQueryType };

View File

@ -5,7 +5,7 @@ import { useMount } from 'react-use';
import { CoreApp, QueryEditorProps } from '@grafana/data';
import { ButtonCascader, CascaderOption } from '@grafana/ui';
import { defaultParca, defaultParcaQueryType, Parca } from '../dataquery.gen';
import { defaultParcaDataQuery, defaultParcaQueryType, ParcaDataQuery as Parca } from '../dataquery.gen';
import { ParcaDataSource } from '../datasource';
import { ParcaDataSourceOptions, ProfileTypeMessage, Query } from '../types';
@ -17,7 +17,7 @@ import { QueryOptions } from './QueryOptions';
export type Props = QueryEditorProps<ParcaDataSource, Query, ParcaDataSourceOptions>;
export const defaultQuery: Partial<Parca> = {
...defaultParca,
...defaultParcaDataQuery,
queryType: defaultParcaQueryType,
};

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -14,7 +14,7 @@ export type ParcaQueryType = ('metrics' | 'profile' | 'both');
export const defaultParcaQueryType: ParcaQueryType = 'both';
export interface Parca extends common.DataQuery {
export interface ParcaDataQuery extends common.DataQuery {
/**
* Specifies the query label selectors.
*/
@ -25,6 +25,6 @@ export interface Parca extends common.DataQuery {
profileTypeId: string;
}
export const defaultParca: Partial<Parca> = {
export const defaultParcaDataQuery: Partial<ParcaDataQuery> = {
labelSelector: '{}',
};

View File

@ -1,6 +1,6 @@
import { DataSourceJsonData } from '@grafana/data';
import { Parca as ParcaBase, ParcaQueryType } from './dataquery.gen';
import { ParcaDataQuery as ParcaBase, ParcaQueryType } from './dataquery.gen';
export interface Query extends ParcaBase {
queryType: ParcaQueryType;

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
@ -127,4 +127,4 @@ export interface TraceqlFilter {
valueType?: string;
}
export interface Tempo {}
export interface TempoDataQuery {}

View File

@ -49,8 +49,7 @@ func main() {
pluginKindGen.Append(
codegen.PluginTreeListJenny(),
codegen.PluginGoTypesJenny("pkg/tsdb"),
codegen.PluginTSTypesJenny("public/app/plugins", adaptToPipeline(corecodegen.TSTypesJenny{})),
codegen.PluginTSEachMajor(rt),
codegen.PluginTSTypesJenny("public/app/plugins"),
)
schifs := kindsys.SchemaInterfaces(rt.Context())

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.

View File

@ -4,7 +4,7 @@
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
// PluginTsTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.