feat(create-plugin): add grafana-app-sdk CUE kind code generation - #2853
feat(create-plugin): add grafana-app-sdk CUE kind code generation#2853stevesg wants to merge 8 commits into
Conversation
|
|
@grafana/create-plugin
@grafana/eslint-config
@grafana/eslint-plugin-plugins
@grafana/plugin-docs-cli
@grafana/plugin-docs-parser
@grafana/plugin-e2e
@grafana/plugin-meta-extractor
@grafana/plugin-types-bundler
@grafana/react-detect
@grafana/sign-plugin
@grafana/tsconfig
commit: |
sunker
left a comment
There was a problem hiding this comment.
This looks really promising. I really like the simplicity of this. Feels like it aligns really well with the goal defined in the product DNA. Also like the fact that app sdk support is optionally additional and that it can live alongside existing APIs. Added some minor inline comments. Aside from that, I have the following high-level feedback:
Since the add command mechnism was introduced we're moving away from feature toggles in the root command and try to enable "optional capabilities" via the add cmd instead. So I'd drop --feature-flags=experimentalAppSdk and only push on add experimental-app-sdk for now. Once these APIs for app sdk have proven stable for internal users and we have a clear path for community plugins, we can flip to enabling app sdk by default for new scaffolded plugins too. Since the short term goal is to get internal devs started quickly, the add script is what we should focus on IMO.
Just note that internal plugins that have been around for a while may have a different file structure etc, so worth testing your add script against a few real ones before announcing internally. I tried it on a 7.6.0 app plugin and hit a couple of smaller issues things (see inlinbe comments). Also, while this is being actively worked on you may not even want to merge the add cmd yet, simply pointing people at the pre-release is probably easier:
npx https://pkg.pr.new/grafana/plugin-tools/@grafana/create-plugin@2d6533a add experimental-app-sdk
IIUC there's nothing protecting us from drift between the CUE and the generated code right now. Easy to edit a kind, forget to regenerate and commit and typecheck won't catch it since the stale types are still valid ts. Not necessarily something that needs to be addressed in this PR, but would be good to scaffold a workflow that protects against this at some point.
| */ | ||
| export default function appSdk(context: Context): Context { | ||
| if (!isAppPlugin(context)) { | ||
| return context; |
There was a problem hiding this comment.
Is this working in all versions of Grafana? If only supported in certain versions, you need to check grafanaDependency in plugin.json and take necessary actions if the plugin supports version of Grafana that dot not support app platform APIs.
There was a problem hiding this comment.
That's a nice idea, didn't think of that. Though the work is still under development in so we don't know the exact version number yet.
|
Thanks for the valuable feedback, appreciate it. I've removed the feature-flag version which cleaned up a lot of code, will address the other points too shortly. |
Adds opt-in support for `grafana-app-sdk` via feature flag or `add`: ``` $ create-plugin --feature-flags=experimentalAppSdk $ create-plugin add experimental-app-sdk ``` Code generation runs through `npm run generate:kinds`, a convenience script to download the grafana-app-sdk binary and run it. This change covers frontend-only app plugins: `kinds/config.cue` sets `codegen: goEnabled: false`, so no Go code, go.mod dependency, or backend is involved. Validation/mutation/conversion and custom routes are not supported. Summary of changes: - templates/app-sdk/: CUE kinds, the generate script, and a README - kinds/config.cue writes the manifest straight into src/app-sdk-manifest.json, so the frontend build's existing **/*.json copy pattern picks it up with no dedicated copy step - docker-compose.yaml: enable the plugins.appSDKManifest feature toggle - AGENTS/: app-sdk.md and edit to instructions.md to point at it
fb2aa12 to
124b3b6
Compare
|
Addressed most of the feedback - will do a round of manual testing on some existing plugins. |
What this PR does / why we need it:
Adds opt-in support for
grafana-app-sdk:Code generation runs through
npm run generate:kinds, a convenience script to download the grafana-app-sdk binary and run it.This change covers frontend-only app plugins:
kinds/config.cuesetscodegen: goEnabled: false, so no Go code, go.mod dependency, or backend is involved. Validation/mutation/conversion and custom routes are not supported.Summary of changes:
Which issue(s) this PR fixes:
Part of #2842
Special notes for your reviewer: