Skip to content

POC: Generate query spec #291

Open
ryantxu wants to merge 22 commits intomainfrom
with-query-spec
Open

POC: Generate query spec #291
ryantxu wants to merge 22 commits intomainfrom
with-query-spec

Conversation

@ryantxu
Copy link
Copy Markdown
Contributor

@ryantxu ryantxu commented Feb 17, 2024

Using grafana/grafana-plugin-sdk-go#897 to generate a query spec

@ryantxu ryantxu requested a review from a team as a code owner February 17, 2024 03:35
@ryantxu ryantxu requested review from gabor, yesoreyeram and zoltanbedi and removed request for a team February 17, 2024 03:35
@gabor
Copy link
Copy Markdown
Contributor

gabor commented Feb 19, 2024

hi @ryantxu , sorry are you looking for feedback in this PR? (i assume you're not, but want to be sure 😄 )

@ryantxu
Copy link
Copy Markdown
Contributor Author

ryantxu commented Feb 19, 2024

@gabor Only in the context of https://docs.google.com/document/d/1la4XW9BZ5XXyU91ZjbzEPE4jvPAyusE0dfJdsrCbbPI/edit#heading=h.5sybau7waq2q. -- trying to get a feeling if this is a reasonable approach or not. Github is interesting because "options" means something different for each query type

@@ -0,0 +1,891 @@
{
"kind": "QueryTypeDefinitionList",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to understand this better. How this kind:QueryTypeDefinitionList maps to queryType:Issues in the actual payload? Am I missing any other contract here? Even if we argue queryType is not owned by the plugin but by the grafana(??), at least plugins should pass if they really use queryType and if it use, the schema should have details of all the possible query types.

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that each "QueryTypeDefinition" can include a discriminator that says queryType is a special field:

        "discriminators": [
          {
            "field": "queryType",
            "value": "Issues"
          }
        ],

Comment on lines +2 to +3
"kind": "QueryTypeDefinitionList",
"apiVersion": "query.grafana.app/v0alpha1",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not understand everything here, but this feels a bit limited if all plugins share the same apiVersion and colliding kinds?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the apiVersion defines how to read this JSON file. The apiVersion for each datasource is independent.

This is the equivalent to the apiVersion on a CRD file, not the custom resource (where the apiVersion is defined inside the CRD!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the schema for this file is the same across all data sources. If/when we need to make breaking changes to the QueryTypeDefinitionList then the apiVersion would update.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 👍

@gabor gabor removed their request for review October 2, 2024 08:04
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Aug 25, 2025

CLA assistant check
All committers have signed the CLA.

@yesoreyeram yesoreyeram closed this Jan 1, 2026
@github-project-automation github-project-automation bot moved this to Complete in OSS Big Tent Jan 1, 2026
@ryantxu ryantxu reopened this Apr 7, 2026
@ryantxu ryantxu requested a review from a team as a code owner April 7, 2026 15:09
}

require.NoError(t, err)
err = builder.AddQueries(schemabuilder.QueryTypeInfo{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need the new query types added to be accurate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And gives swagger + agents "example" queries to fill in

@ryantxu
Copy link
Copy Markdown
Contributor Author

ryantxu commented Apr 7, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c03e5e0a38

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

require.NoError(t, err)
err = builder.AddQueries(schemabuilder.QueryTypeInfo{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Register all supported query types in generated query spec

This AddQueries registration is incomplete relative to the datasource's supported query surface, so the generated query.types.json / query.*.schema.json only describe a subset of valid queries. Query kinds still handled elsewhere (for example Code_Scanning, Commit_Files, Pull_Request_Reviews, Pull_Request_Files, Workflow_Runs, Deployments, Organizations, GraphQL, and Projects) will be hidden or rejected by schema-driven editors/admission even though backend handlers can execute them.

Useful? React with 👍 / 👎.

Comment on lines +53 to +56
"required": [
"repository",
"owner",
"timeField"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop requiring owner/repository inside options payloads

The generated schema now requires options.repository and options.owner for this query type, but this plugin's persisted query model keeps repo identity at top level and commonly stores only query-specific fields inside options; this mismatch makes existing saved queries fail validation once schema admission is enabled, despite backend handlers already deriving repo/owner from top-level fields.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

5 participants