grafana / grok

Grafana Object Development Kit
Apache License 2.0
50 stars 1 forks source link

Generate code from schemas in the `kind-registry` #30

Closed K-Phoen closed 1 year ago

K-Phoen commented 1 year ago

This PR introduces a CLI to generate code (go, jsonschema, jsonnet) from CUE schemas stored in our kind-registry.

The end goal is to replace the current gen.go file and generate everything using the registry instead of depending on grafana/grafana.

While the CLI already can run the code generation process on core and composable kinds, there are a few issues:

  1. core kinds are all defined in a single folder within the registry, instead of one folder per kind. We currently work around that by isolating each file in a "virtual filesystem"
  2. composable kinds do not have a package directive, which generates interesting errors when loading them. We work around that by defining a package "in memory"
  3. most composable kinds depend on a set of common schemas defined in grafana/grafana. Grok needs to be able to access this dependency and load it for the CUE parsing process to work. The CLI currently assumes that this common schemas are in the registry, and explicitly loads them. Note: this isn't true yet, I just manually copy-pasted these files locally.
  4. the code generated from the schemas is slightly different from the code generated using input in grafana/grafana. It's probably related to differences in the schemas themselves, but we should look into it

Suggestions for next steps: