diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 95e72101f1c..78cc5a5a35e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1210,7 +1210,6 @@ embed.go @grafana/grafana-as-code /pkg/codegen/ @grafana/grafana-as-code /pkg/codegen/generators @grafana/grafana-as-code /pkg/kinds/*/*_gen.go @grafana/grafana-as-code -/pkg/registry/schemas/ @grafana/grafana-as-code /public/app/plugins/*gen.go @grafana/grafana-as-code /cue.mod/ @grafana/grafana-as-code @@ -1276,10 +1275,7 @@ embed.go @grafana/grafana-as-code /.github/workflows/scripts/json-file-to-job-output.js @grafana/grafana-frontend-platform /.github/workflows/stale.yml @grafana/grafana-developer-enablement-squad /.github/workflows/storybook-a11y.yml @grafana/grafana-frontend-platform -/.github/workflows/scripts/kinds/verify-kinds.go @grafana/grafana-app-platform-squad /.github/workflows/scripts/create-security-branch/create-security-branch.sh @grafana/grafana-developer-enablement-squad -/.github/workflows/publish-kinds-next.yml @grafana/grafana-app-platform-squad -/.github/workflows/publish-kinds-release.yml @grafana/grafana-app-platform-squad /.github/workflows/verify-kinds.yml @grafana/grafana-app-platform-squad /.github/workflows/dashboards-issue-add-label.yml @grafana/dashboards-squad /.github/workflows/run-schema-v2-e2e.yml @grafana/dashboards-squad diff --git a/.github/workflows/publish-kinds-next.yml b/.github/workflows/publish-kinds-next.yml deleted file mode 100644 index dc52f9d25e4..00000000000 --- a/.github/workflows/publish-kinds-next.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: "publish-kinds-next" - -on: - push: - branches: - - "main" - paths: - - '**/*.cue' - workflow_dispatch: - -permissions: {} - -jobs: - main: - if: github.repository == 'grafana/grafana' - runs-on: "ubuntu-latest" - permissions: - contents: read # cloning repo - actions: read # reading .github/workflows/ dir - id-token: write # reading vault secrets - - steps: - - name: "Checkout Grafana repo" - uses: "actions/checkout@v5" - with: - fetch-depth: 0 - persist-credentials: false - - - name: "Setup Go" - uses: "actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00" - with: - go-version-file: go.mod - - - name: "Verify kinds" - run: go run .github/workflows/scripts/kinds/verify-kinds.go - - - name: "Get vault secrets" - id: vault-secrets - uses: grafana/shared-workflows/actions/get-vault-secrets@main - with: - # Secrets placed in the ci/data/repo/grafana/grafana/delivery-bot-app path in Vault - repo_secrets: | - GRAFANA_DELIVERY_BOT_APP_PEM=delivery-bot-app:PRIVATE_KEY - - name: "Generate token" - id: generate_token - uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a - with: - # App needs Actions: Read/Write for the grafana/security-patch-actions repo - app_id: ${{ vars.DELIVERY_BOT_APP_ID }} - private_key: ${{ env.GRAFANA_DELIVERY_BOT_APP_PEM }} - - - name: "Clone website-sync Action" - run: "git clone --single-branch --no-tags --depth 1 -b master https://grafana-delivery-bot:${{ steps.generate_token.outputs.token }}@github.com/grafana/website-sync ./.github/actions/website-sync" - - - name: "Publish to kind registry (next)" - uses: "./.github/actions/website-sync" - id: "publish-next" - with: - repository: "grafana/kind-registry" - branch: "main" - host: "github.com" - github_pat: "grafana-delivery-bot:${{ steps.generate_token.outputs.token }}" - source_folder: ".github/workflows/scripts/kinds/next" - target_folder: "grafana/next" diff --git a/.github/workflows/publish-kinds-release.yml b/.github/workflows/publish-kinds-release.yml deleted file mode 100644 index e0e4a89aa13..00000000000 --- a/.github/workflows/publish-kinds-release.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: "publish-kinds-release" - -on: - push: - branches: - - v[0-9]+.[0-9]+.x - tags: - - v[0-9]+.[0-9]+.[0-9]+ - paths: - - '**/*.cue' - workflow_dispatch: - -permissions: {} - -jobs: - main: - if: github.repository == 'grafana/grafana' - runs-on: "ubuntu-latest" - permissions: - contents: read # cloning repo - actions: read # reading .github/workflows/ dir - id-token: write # reading vault secrets - - steps: - - name: "Checkout Grafana repo" - uses: "actions/checkout@v5" - with: - # required for the `grafana/grafana-github-actions/has-matching-release-tag` action to work - fetch-depth: 0 - persist-credentials: false - - - name: "Setup Go" - uses: "actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00" - with: - go-version-file: go.mod - - - name: "Verify kinds" - run: go run .github/workflows/scripts/kinds/verify-kinds.go - - - name: "Checkout Actions library" - uses: "actions/checkout@v5" - with: - repository: "grafana/grafana-github-actions" - path: "./actions" - persist-credentials: false - - - name: "Install Actions from library" - run: "npm install --production --prefix ./actions" - - - name: "Determine if there is a matching release tag" - id: "has-matching-release-tag" - uses: "./actions/has-matching-release-tag" - with: - ref_name: "${{ github.ref_name }}" - release_tag_regexp: "^v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$" - release_branch_regexp: "^v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.x$" - - - name: "Get vault secrets" - id: vault-secrets - uses: grafana/shared-workflows/actions/get-vault-secrets@main - with: - # Secrets placed in the ci/data/repo/grafana/grafana/delivery-bot-app path in Vault - repo_secrets: | - GRAFANA_DELIVERY_BOT_APP_PEM=delivery-bot-app:PRIVATE_KEY - - name: "Generate token" - id: generate_token - uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a - with: - # App needs Actions: Read/Write for the grafana/security-patch-actions repo - app_id: ${{ vars.DELIVERY_BOT_APP_ID }} - private_key: ${{ env.GRAFANA_DELIVERY_BOT_APP_PEM }} - - - name: "Clone website-sync Action" - if: "steps.has-matching-release-tag.outputs.bool == 'true'" - run: "git clone --single-branch --no-tags --depth 1 -b master https://grafana-delivery-bot:${{ steps.generate_token.outputs.token }}@github.com/grafana/website-sync ./.github/actions/website-sync" - - - name: "Publish to kind registry (release)" - if: "steps.has-matching-release-tag.outputs.bool == 'true'" - uses: "./.github/actions/website-sync" - id: "publish-release" - with: - repository: "grafana/kind-registry" - branch: "main" - host: "github.com" - github_pat: "grafana-delivery-bot:${{ steps.generate_token.outputs.token }}" - source_folder: ".github/workflows/scripts/kinds/next" - target_folder: "grafana/${{ github.ref_name }}" diff --git a/.github/workflows/scripts/kinds/verify-kinds.go b/.github/workflows/scripts/kinds/verify-kinds.go deleted file mode 100644 index ab60a90bd3e..00000000000 --- a/.github/workflows/scripts/kinds/verify-kinds.go +++ /dev/null @@ -1,229 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "golang.org/x/text/cases" - "golang.org/x/text/language" - "os" - "path/filepath" - "regexp" - "strings" - - "cuelang.org/go/cue" - cueformat "cuelang.org/go/cue/format" - "github.com/grafana/codejen" - "github.com/grafana/grafana/pkg/registry/schemas" -) - -var nonAlphaNumRegex = regexp.MustCompile("[^a-zA-Z0-9 ]+") - -// main This script verifies that stable kinds are not updated once published (new schemas -// can be added but existing ones cannot be updated). -// It generates kind files into a local "next" folder, ready to be published in the kind-registry repo. -// If kind names are given as parameters, the script will make the above actions only for the -// given kinds. -func main() { - // File generation - jfs := codejen.NewFS() - outputPath := filepath.Join(".github", "workflows", "scripts", "kinds") - - corekinds, err := schemas.GetCoreKinds() - die(err) - - composableKinds, err := schemas.GetComposableKinds() - die(err) - - coreJennies := codejen.JennyList[schemas.CoreKind]{} - coreJennies.Append( - CoreKindRegistryJenny(outputPath), - ) - corefs, err := coreJennies.GenerateFS(corekinds...) - die(err) - die(jfs.Merge(corefs)) - - composableJennies := codejen.JennyList[schemas.ComposableKind]{} - composableJennies.Append( - ComposableKindRegistryJenny(outputPath), - ) - composablefs, err := composableJennies.GenerateFS(composableKinds...) - die(err) - die(jfs.Merge(composablefs)) - - if err = jfs.Write(context.Background(), ""); err != nil { - die(fmt.Errorf("error while writing generated code to disk:\n%s", err)) - } - - if err := copyCueSchemas("packages/grafana-schema/src/common", filepath.Join(outputPath, "next")); err != nil { - die(fmt.Errorf("error while copying the grafana-schema/common package:\n%s", err)) - } -} - -func copyCueSchemas(fromDir string, toDir string) error { - baseTargetDir := filepath.Base(fromDir) - - return filepath.Walk(fromDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - targetPath := filepath.Join( - toDir, - baseTargetDir, - strings.TrimPrefix(path, fromDir), - ) - - if info.IsDir() { - return ensureDirectoryExists(targetPath, info.Mode()) - } - - if !strings.HasSuffix(path, ".cue") { - return nil - } - - return copyFile(path, targetPath, info.Mode()) - }) -} - -func copyFile(from string, to string, mode os.FileMode) error { - input, err := os.ReadFile(from) - if err != nil { - return err - } - - return os.WriteFile(to, input, mode) -} - -func ensureDirectoryExists(directory string, mode os.FileMode) error { - _, err := os.Stat(directory) - if errors.Is(err, os.ErrNotExist) { - if err = os.Mkdir(directory, mode); err != nil { - return err - } - } else if err != nil { - return err - } - - return os.Chmod(directory, mode) -} - -func die(errs ...error) { - if len(errs) > 0 && errs[0] != nil { - for _, err := range errs { - fmt.Fprint(os.Stderr, err, "\n") - } - os.Exit(1) - } -} - -// CoreKindRegistryJenny generates kind files into the "next" folder of the local kind registry. -func CoreKindRegistryJenny(path string) codejen.OneToOne[schemas.CoreKind] { - return &kindregjenny{ - path: path, - } -} - -type kindregjenny struct { - path string -} - -func (j *kindregjenny) JennyName() string { - return "KindRegistryJenny" -} - -func (j *kindregjenny) Generate(kind schemas.CoreKind) (*codejen.File, error) { - newKindBytes, err := kindToBytes(kind.CueFile) - if err != nil { - return nil, err - } - - path := filepath.Join(j.path, "next", "core", kind.Name, kind.Name+".cue") - return codejen.NewFile(path, newKindBytes, j), nil -} - -// ComposableKindRegistryJenny generates kind files into the "next" folder of the local kind registry. -func ComposableKindRegistryJenny(path string) codejen.OneToOne[schemas.ComposableKind] { - return &ckrJenny{ - path: path, - } -} - -type ckrJenny struct { - path string -} - -func (j *ckrJenny) JennyName() string { - return "ComposableKindRegistryJenny" -} - -func (j *ckrJenny) Generate(k schemas.ComposableKind) (*codejen.File, error) { - name := strings.ToLower(fmt.Sprintf("%s/%s", k.Name, k.Filename)) - - v := fixComposableKindFormat(k) - - newKindBytes, err := kindToBytes(v) - if err != nil { - return nil, err - } - - newKindBytes = []byte(fmt.Sprintf("package grafanaplugin\n\n%s", newKindBytes)) - - return codejen.NewFile(filepath.Join(j.path, "next", "composable", name), newKindBytes, j), nil -} - -// kindToBytes converts a kind cue value to a .cue file content -func kindToBytes(kind cue.Value) ([]byte, error) { - node := kind.Syntax( - cue.All(), - cue.Schema(), - cue.Docs(true), - ) - - return cueformat.Node(node) -} - -func fixComposableKindFormat(schema schemas.ComposableKind) cue.Value { - variant := "PanelCfg" - if schema.CueFile.LookupPath(cue.ParsePath("composableKinds.DataQuery")).Exists() { - variant = "DataQuery" - } - - newCue := schema.CueFile.Context().CompileString( - fmt.Sprintf("schemaInterface: %q\n", variant) + - fmt.Sprintf("name: %q + %q\n\n", UpperCamelCase(schema.Name), variant) + - "lineage: _", - ) - - lineagePath := cue.MakePath(cue.Str("composableKinds"), cue.Str(variant), cue.Str("lineage")) - return newCue.FillPath(cue.MakePath(cue.Str("lineage")), schema.CueFile.LookupPath(lineagePath)) -} - -func UpperCamelCase(s string) string { - s = LowerCamelCase(s) - - // Uppercase the first letter - if len(s) > 0 { - s = strings.ToUpper(s[:1]) + s[1:] - } - - return s -} - -func LowerCamelCase(s string) string { - // Replace all non-alphanumeric characters by spaces - s = nonAlphaNumRegex.ReplaceAllString(s, " ") - - // Title case s - s = cases.Title(language.AmericanEnglish, cases.NoLower).String(s) - - // Remove all spaces - s = strings.ReplaceAll(s, " ", "") - - // Lowercase the first letter - if len(s) > 0 { - s = strings.ToLower(s[:1]) + s[1:] - } - - return s -} diff --git a/go.mod b/go.mod index 20c7cbf13ed..9aa1d9ff1c9 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( cloud.google.com/go/kms v1.22.0 // @grafana/grafana-backend-group cloud.google.com/go/storage v1.55.0 // @grafana/grafana-backend-group connectrpc.com/connect v1.19.1 // @grafana/observability-traces-and-profiling - cuelang.org/go v0.11.1 // @grafana/grafana-as-code + cuelang.org/go v0.11.1 // indirect; @grafana/grafana-as-code dario.cat/mergo v1.0.2 // @grafana/grafana-app-platform-squad filippo.io/age v1.2.1 // @grafana/identity-access-team github.com/1NCE-GmbH/grpc-go-pool v0.0.0-20231117122434-2a5bb974daa2 // @grafana/grafana-search-and-storage @@ -301,7 +301,6 @@ require ( cloud.google.com/go/iam v1.5.2 // indirect cloud.google.com/go/longrunning v0.6.7 // indirect cloud.google.com/go/monitoring v1.24.2 // indirect - cuelabs.dev/go/oci/ociregistry v0.0.0-20251212221603-3adeb8663819 // indirect github.com/Azure/azure-pipeline-go v0.2.3 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect @@ -411,7 +410,6 @@ require ( github.com/ebitengine/purego v0.8.2 // indirect github.com/edsrzf/mmap-go v1.2.0 // indirect github.com/elazarl/goproxy v1.8.0 // indirect - github.com/emicklei/proto v1.14.2 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/envoyproxy/go-control-plane/envoy v1.35.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect @@ -581,13 +579,11 @@ require ( github.com/prometheus/exporter-toolkit v0.15.1 // indirect github.com/prometheus/otlptranslator v1.0.0 // indirect github.com/prometheus/procfs v0.19.2 // indirect - github.com/protocolbuffers/txtpbfmt v0.0.0-20251124094003-fcb97cc64c7b // indirect github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect github.com/quagmt/udecimal v1.9.0 // indirect github.com/redis/rueidis v1.0.68 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/sagikazarmark/locafero v0.11.0 // indirect diff --git a/kinds/gen.go b/kinds/gen.go index ac7bd7e7d4e..087ba2b701f 100644 --- a/kinds/gen.go +++ b/kinds/gen.go @@ -49,7 +49,6 @@ func main() { coreKindsGen.Append( &codegen.GoSpecJenny{}, &codegen.K8ResourcesJenny{}, - &codegen.CoreRegistryJenny{}, codegen.LatestMajorsOrXJenny(TSCoreKindParentPath), codegen.TSVeneerIndexJenny(filepath.Join("packages", "grafana-schema", "src")), ) diff --git a/pkg/codegen/tmpl/core_registry.tmpl b/pkg/codegen/tmpl/core_registry.tmpl deleted file mode 100644 index 8fc8bb9b092..00000000000 --- a/pkg/codegen/tmpl/core_registry.tmpl +++ /dev/null @@ -1,46 +0,0 @@ -package schemas - -import ( - "os" - "path/filepath" - "runtime" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/cuecontext" -) - -type CoreKind struct { - Name string - CueFile cue.Value -} - -func GetCoreKinds() ([]CoreKind, error) { - ctx := cuecontext.New() - kinds := make([]CoreKind, 0) - - _, caller, _, _ := runtime.Caller(0) - root := filepath.Join(caller, "../../../..") - - {{- range .Schemas }} - - {{ .Name }}Cue, err := loadCueFile(ctx, filepath.Join(root, "{{ .FilePath }}")) - if err != nil { - return nil, err - } - kinds = append(kinds, CoreKind{ - Name: "{{ .Name }}", - CueFile: {{ .Name }}Cue, - }) - {{- end }} - - return kinds, nil -} - -func loadCueFile(ctx *cue.Context, path string) (cue.Value, error) { - cueFile, err := os.ReadFile(path) - if err != nil { - return cue.Value{}, err - } - - return ctx.CompileBytes(cueFile), nil -} diff --git a/pkg/plugins/codegen/jenny_plugin_registry.go b/pkg/plugins/codegen/jenny_plugin_registry.go deleted file mode 100644 index 9387c18ab34..00000000000 --- a/pkg/plugins/codegen/jenny_plugin_registry.go +++ /dev/null @@ -1,76 +0,0 @@ -package codegen - -import ( - "bytes" - "fmt" - "go/format" - "path/filepath" - "strings" - - "github.com/grafana/codejen" - "github.com/grafana/grafana/pkg/plugins/codegen/pfs" -) - -var registryPath = filepath.Join("pkg", "registry", "schemas") - -var renamedPlugins = map[string]string{ - "cloud-monitoring": "googlecloudmonitoring", - "grafana-pyroscope-datasource": "grafanapyroscope", - "annolist": "annotationslist", - "grafanatestdatadatasource": "testdata", - "dashlist": "dashboardlist", -} - -type PluginRegistryJenny struct { -} - -func (jenny *PluginRegistryJenny) JennyName() string { - return "PluginRegistryJenny" -} - -func (jenny *PluginRegistryJenny) Generate(decls ...*pfs.PluginDecl) (*codejen.File, error) { - if len(decls) == 0 { - return nil, nil - } - schemas := make([]Schema, len(decls)) - for i, decl := range decls { - variant := fmt.Sprintf("%s.cue", strings.ToLower(decl.SchemaInterface.Name)) - name, err := getSchemaName(decl.PluginPath) - if err != nil { - return nil, fmt.Errorf("unable to find schema name: %s", err) - } - - schemas[i] = Schema{ - Name: name, - Filename: variant, - FilePath: "./" + filepath.Join("public", "app", "plugins", decl.PluginPath, variant), - } - } - - buf := new(bytes.Buffer) - if err := tmpls.Lookup("composable_registry.tmpl").Execute(buf, tmpl_vars_plugin_registry{ - Schemas: schemas, - }); err != nil { - return nil, fmt.Errorf("failed executing kind registry template: %w", err) - } - - b, err := format.Source(buf.Bytes()) - if err != nil { - return nil, err - } - - return codejen.NewFile(filepath.Join(registryPath, "composable_kind.go"), b, jenny), nil -} - -func getSchemaName(path string) (string, error) { - parts := strings.Split(path, "/") - if len(parts) < 2 { - return "", fmt.Errorf("path should contain more than 2 elements") - } - folderName := parts[len(parts)-1] - if renamed, ok := renamedPlugins[folderName]; ok { - folderName = renamed - } - folderName = strings.ReplaceAll(folderName, "-", "") - return strings.ToLower(folderName), nil -} diff --git a/pkg/plugins/codegen/tmpl.go b/pkg/plugins/codegen/tmpl.go deleted file mode 100644 index 729072a440f..00000000000 --- a/pkg/plugins/codegen/tmpl.go +++ /dev/null @@ -1,34 +0,0 @@ -package codegen - -import ( - "embed" - "text/template" - "time" -) - -// All the parsed templates in the tmpl subdirectory -var tmpls *template.Template - -func init() { - base := template.New("codegen").Funcs(template.FuncMap{ - "now": time.Now, - }) - tmpls = template.Must(base.ParseFS(tmplFS, "tmpl/*.tmpl")) -} - -//go:embed tmpl/*.tmpl -var tmplFS embed.FS - -// The following group of types, beginning with templateVars_*, all contain the set -// of variables expected by the corresponding named template file under tmpl/ -type ( - tmpl_vars_plugin_registry struct { - Schemas []Schema - } - - Schema struct { - Name string - Filename string - FilePath string - } -) diff --git a/pkg/plugins/codegen/tmpl/composable_registry.tmpl b/pkg/plugins/codegen/tmpl/composable_registry.tmpl deleted file mode 100644 index 5ad6416a41a..00000000000 --- a/pkg/plugins/codegen/tmpl/composable_registry.tmpl +++ /dev/null @@ -1,132 +0,0 @@ -package schemas - -import ( - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - "runtime" - "testing/fstest" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/cuecontext" - "cuelang.org/go/cue/load" -) - -var cueImportsPath = filepath.Join("packages", "grafana-schema", "src", "common") -var importPath = "github.com/grafana/grafana/packages/grafana-schema/src/common" - -type ComposableKind struct { - Name string - Filename string - CueFile cue.Value -} - -func GetComposableKinds() ([]ComposableKind, error) { - kinds := make([]ComposableKind, 0) - - _, caller, _, _ := runtime.Caller(0) - root := filepath.Join(caller, "../../../..") - - {{- range .Schemas }} - - {{ .Name }}Cue, err := loadCueFileWithCommon(root, filepath.Join(root, "{{ .FilePath }}")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "{{ .Name }}", - Filename: "{{ .Filename }}", - CueFile: {{ .Name }}Cue, - }) - {{- end }} - - return kinds, nil -} - -func loadCueFileWithCommon(root string, entrypoint string) (cue.Value, error) { - commonFS, err := mockCommonFS(root) - if err != nil { - fmt.Printf("cannot load common cue files: %s\n", err) - return cue.Value{}, err - } - - overlay, err := buildOverlay(commonFS) - if err != nil { - fmt.Printf("Cannot build overlay: %s\n", err) - return cue.Value{}, err - } - - bis := load.Instances([]string{entrypoint}, &load.Config{ - ModuleRoot: "/", - Overlay: overlay, - }) - - values, err := cuecontext.New().BuildInstances(bis) - if err != nil { - fmt.Printf("Cannot build instance: %s\n", err) - return cue.Value{}, err - } - - return values[0], nil -} - -func mockCommonFS(root string) (fs.FS, error) { - path := filepath.Join(root, cueImportsPath) - dir, err := os.ReadDir(path) - if err != nil { - return nil, fmt.Errorf("cannot open common cue files directory: %s", err) - } - - prefix := "cue.mod/pkg/" + importPath - - commonFS := fstest.MapFS{} - for _, d := range dir { - if d.IsDir() { - continue - } - - readPath := filepath.Join(path, d.Name()) - b, err := os.ReadFile(filepath.Clean(readPath)) - if err != nil { - return nil, err - } - - commonFS[filepath.Join(prefix, d.Name())] = &fstest.MapFile{Data: b} - } - - return commonFS, nil -} - -// It loads common cue files into the schema to be able to make import works -func buildOverlay(commonFS fs.FS) (map[string]load.Source, error) { - overlay := make(map[string]load.Source) - - err := fs.WalkDir(commonFS, ".", func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - - if d.IsDir() { - return nil - } - - f, err := commonFS.Open(path) - if err != nil { - return err - } - defer func() { _ = f.Close() }() - - b, err := io.ReadAll(f) - if err != nil { - return err - } - - overlay[filepath.Join("/", path)] = load.FromBytes(b) - - return nil - }) - - return overlay, err -} diff --git a/pkg/registry/schemas/composable_kind.go b/pkg/registry/schemas/composable_kind.go deleted file mode 100644 index bfac8904fd0..00000000000 --- a/pkg/registry/schemas/composable_kind.go +++ /dev/null @@ -1,458 +0,0 @@ -// Code generated - EDITING IS FUTILE. DO NOT EDIT. -// -// Generated by: -// public/app/plugins/gen.go -// Using jennies: -// PluginRegistryJenny -// -// Run 'make gen-cue' from repository root to regenerate. - -package schemas - -import ( - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - "runtime" - "testing/fstest" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/cuecontext" - "cuelang.org/go/cue/load" -) - -var cueImportsPath = filepath.Join("packages", "grafana-schema", "src", "common") -var importPath = "github.com/grafana/grafana/packages/grafana-schema/src/common" - -type ComposableKind struct { - Name string - Filename string - CueFile cue.Value -} - -func GetComposableKinds() ([]ComposableKind, error) { - kinds := make([]ComposableKind, 0) - - _, caller, _, _ := runtime.Caller(0) - root := filepath.Join(caller, "../../../..") - - azuremonitorCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/azuremonitor/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "azuremonitor", - Filename: "dataquery.cue", - CueFile: azuremonitorCue, - }) - - googlecloudmonitoringCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/cloud-monitoring/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "googlecloudmonitoring", - Filename: "dataquery.cue", - CueFile: googlecloudmonitoringCue, - }) - - cloudwatchCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/cloudwatch/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "cloudwatch", - Filename: "dataquery.cue", - CueFile: cloudwatchCue, - }) - - elasticsearchCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/elasticsearch/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "elasticsearch", - Filename: "dataquery.cue", - CueFile: elasticsearchCue, - }) - - grafanapyroscopeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/grafana-pyroscope-datasource/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "grafanapyroscope", - Filename: "dataquery.cue", - CueFile: grafanapyroscopeCue, - }) - - lokiCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/loki/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "loki", - Filename: "dataquery.cue", - CueFile: lokiCue, - }) - - parcaCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/parca/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "parca", - Filename: "dataquery.cue", - CueFile: parcaCue, - }) - - tempoCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/tempo/dataquery.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "tempo", - Filename: "dataquery.cue", - CueFile: tempoCue, - }) - - annotationslistCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/annolist/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "annotationslist", - Filename: "panelcfg.cue", - CueFile: annotationslistCue, - }) - - barchartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/barchart/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "barchart", - Filename: "panelcfg.cue", - CueFile: barchartCue, - }) - - bargaugeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/bargauge/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "bargauge", - Filename: "panelcfg.cue", - CueFile: bargaugeCue, - }) - - candlestickCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/candlestick/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "candlestick", - Filename: "panelcfg.cue", - CueFile: candlestickCue, - }) - - canvasCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/canvas/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "canvas", - Filename: "panelcfg.cue", - CueFile: canvasCue, - }) - - dashboardlistCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/dashlist/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "dashboardlist", - Filename: "panelcfg.cue", - CueFile: dashboardlistCue, - }) - - datagridCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/datagrid/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "datagrid", - Filename: "panelcfg.cue", - CueFile: datagridCue, - }) - - debugCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/debug/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "debug", - Filename: "panelcfg.cue", - CueFile: debugCue, - }) - - gaugeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/gauge/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "gauge", - Filename: "panelcfg.cue", - CueFile: gaugeCue, - }) - - geomapCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/geomap/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "geomap", - Filename: "panelcfg.cue", - CueFile: geomapCue, - }) - - heatmapCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/heatmap/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "heatmap", - Filename: "panelcfg.cue", - CueFile: heatmapCue, - }) - - histogramCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/histogram/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "histogram", - Filename: "panelcfg.cue", - CueFile: histogramCue, - }) - - logsCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/logs/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "logs", - Filename: "panelcfg.cue", - CueFile: logsCue, - }) - - logstableCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/logstable/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "logstable", - Filename: "panelcfg.cue", - CueFile: logstableCue, - }) - - newsCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/news/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "news", - Filename: "panelcfg.cue", - CueFile: newsCue, - }) - - nodegraphCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/nodeGraph/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "nodegraph", - Filename: "panelcfg.cue", - CueFile: nodegraphCue, - }) - - piechartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/piechart/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "piechart", - Filename: "panelcfg.cue", - CueFile: piechartCue, - }) - - statCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/stat/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "stat", - Filename: "panelcfg.cue", - CueFile: statCue, - }) - - statetimelineCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/state-timeline/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "statetimeline", - Filename: "panelcfg.cue", - CueFile: statetimelineCue, - }) - - statushistoryCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/status-history/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "statushistory", - Filename: "panelcfg.cue", - CueFile: statushistoryCue, - }) - - tableCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/table/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "table", - Filename: "panelcfg.cue", - CueFile: tableCue, - }) - - textCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/text/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "text", - Filename: "panelcfg.cue", - CueFile: textCue, - }) - - timeseriesCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/timeseries/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "timeseries", - Filename: "panelcfg.cue", - CueFile: timeseriesCue, - }) - - trendCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/trend/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "trend", - Filename: "panelcfg.cue", - CueFile: trendCue, - }) - - xychartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/xychart/panelcfg.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, ComposableKind{ - Name: "xychart", - Filename: "panelcfg.cue", - CueFile: xychartCue, - }) - - return kinds, nil -} - -func loadCueFileWithCommon(root string, entrypoint string) (cue.Value, error) { - commonFS, err := mockCommonFS(root) - if err != nil { - fmt.Printf("cannot load common cue files: %s\n", err) - return cue.Value{}, err - } - - overlay, err := buildOverlay(commonFS) - if err != nil { - fmt.Printf("Cannot build overlay: %s\n", err) - return cue.Value{}, err - } - - bis := load.Instances([]string{entrypoint}, &load.Config{ - ModuleRoot: "/", - Overlay: overlay, - }) - - values, err := cuecontext.New().BuildInstances(bis) - if err != nil { - fmt.Printf("Cannot build instance: %s\n", err) - return cue.Value{}, err - } - - return values[0], nil -} - -func mockCommonFS(root string) (fs.FS, error) { - path := filepath.Join(root, cueImportsPath) - dir, err := os.ReadDir(path) - if err != nil { - return nil, fmt.Errorf("cannot open common cue files directory: %s", err) - } - - prefix := "cue.mod/pkg/" + importPath - - commonFS := fstest.MapFS{} - for _, d := range dir { - if d.IsDir() { - continue - } - - readPath := filepath.Join(path, d.Name()) - b, err := os.ReadFile(filepath.Clean(readPath)) - if err != nil { - return nil, err - } - - commonFS[filepath.Join(prefix, d.Name())] = &fstest.MapFile{Data: b} - } - - return commonFS, nil -} - -// It loads common cue files into the schema to be able to make import works -func buildOverlay(commonFS fs.FS) (map[string]load.Source, error) { - overlay := make(map[string]load.Source) - - err := fs.WalkDir(commonFS, ".", func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - - if d.IsDir() { - return nil - } - - f, err := commonFS.Open(path) - if err != nil { - return err - } - defer func() { _ = f.Close() }() - - b, err := io.ReadAll(f) - if err != nil { - return err - } - - overlay[filepath.Join("/", path)] = load.FromBytes(b) - - return nil - }) - - return overlay, err -} diff --git a/pkg/registry/schemas/core_kind.go b/pkg/registry/schemas/core_kind.go deleted file mode 100644 index 1c8a9e37802..00000000000 --- a/pkg/registry/schemas/core_kind.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated - EDITING IS FUTILE. DO NOT EDIT. -// -// Generated by: -// kinds/gen.go -// Using jennies: -// CoreRegistryJenny -// -// Run 'make gen-cue' from repository root to regenerate. - -package schemas - -import ( - "os" - "path/filepath" - "runtime" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/cuecontext" -) - -type CoreKind struct { - Name string - CueFile cue.Value -} - -func GetCoreKinds() ([]CoreKind, error) { - ctx := cuecontext.New() - kinds := make([]CoreKind, 0) - - _, caller, _, _ := runtime.Caller(0) - root := filepath.Join(caller, "../../../..") - - dashboardCue, err := loadCueFile(ctx, filepath.Join(root, "./kinds/dashboard/dashboard_kind.cue")) - if err != nil { - return nil, err - } - kinds = append(kinds, CoreKind{ - Name: "dashboard", - CueFile: dashboardCue, - }) - - return kinds, nil -} - -func loadCueFile(ctx *cue.Context, path string) (cue.Value, error) { - cueFile, err := os.ReadFile(path) - if err != nil { - return cue.Value{}, err - } - - return ctx.CompileBytes(cueFile), nil -} diff --git a/public/app/plugins/gen.go b/public/app/plugins/gen.go index 50988199032..6e59bc0897d 100644 --- a/public/app/plugins/gen.go +++ b/public/app/plugins/gen.go @@ -43,7 +43,6 @@ func main() { }) pluginKindGen.Append( - &codegen.PluginRegistryJenny{}, codegen.PluginGoTypesJenny("pkg/tsdb"), codegen.PluginTSTypesJenny("public/app/plugins"), )