Skip to content

Conversation

@mckn
Copy link
Collaborator

@mckn mckn commented Nov 25, 2025

What this PR does / why we need it:
It will add an agents.md file that cover the fundamentals of datasource plugins (with and without backend). We are following the convention where we put generic information below .config folder (which should not be modified by the developer). Then we reference that file from the project AGENTS.md where the developers of the plugin can add more plugin specific details.

Which issue(s) this PR fixes:

Fixes https://github.com/grafana/grafana-community-team/issues/674

Special notes for your reviewer:

@mckn mckn self-assigned this Nov 25, 2025
@mckn mckn moved this from 📬 Triage to 🧑‍💻 In development in Plugins Platform / Grafana Community Nov 25, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged but will not trigger a new release. To trigger a new release add the release label before merging.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@mckn mckn added create-plugin related to the create-plugin tool minor Increment the minor version when merged labels Nov 25, 2025
- `src/datasource.ts` - Datasource implementation
- `src/components/QueryEditor.tsx` — Query builder UI
- `src/components/ConfigEditor.tsx` — Data source settings UI
- `src/types.ts` — Shared frontend models
Copy link
Collaborator

@tolzhabayev tolzhabayev Nov 27, 2025

Choose a reason for hiding this comment

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

models or types?

- Keep layouts responsive (use `width`/`height`)
- Avoid new dependencies unless necessary + Grafana-compatible
- Maintain consistent file structure and predictable types
- Use **`@grafana/plugin-e2e`** for E2E tests and **always use versioned selectors** to interact with the Grafana UI.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- Use **`@grafana/plugin-e2e`** for E2E tests and **always use versioned selectors** to interact with the Grafana UI.
- Use npm package called **`@grafana/plugin-e2e`** for E2E tests and **always use versioned selectors** to interact with the Grafana UI.

**plugin.json**

- Declares plugin ID, type (`datasource`), name, version
- Loaded by Grafana at startup
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this get more details beyond "Loaded by Grafana at startup" - e.g. why it is loaded and what the purpose is?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we could specify that the backend will be loaded if backend: true is set, not sure if we want to talk about other properties (alerts, annotations, etc).


## Boundaries

You must **NOT**:
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add "Do not log sensitive data"

@tolzhabayev
Copy link
Collaborator

We should probably add CLAUDE.md file pointing to Agents.md like this: https://github.com/grafana/plugin-tools/blob/3aed54e7d9d26d14dfbaa229806c3377391ccfcc/CLAUDE.md?plain=1

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

A bunch of comments here 👍

**plugin.json**

- Declares plugin ID, type (`datasource`), name, version
- Loaded by Grafana at startup
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we could specify that the backend will be loaded if backend: true is set, not sure if we want to talk about other properties (alerts, annotations, etc).

- CheckHealth (validates API key from settings)
- Dispose (cleanup hook).
- NewDatasource factory called when Grafana starts instance of plugin

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the default plugin also comes with a pkg/models/settings.go ?

- Use idiomatic React + TypeScript
- Use secureJsonData instead of jsonData for credentials and sensitive data
- Error happening should be logged with level `error`

Copy link
Contributor

Choose a reason for hiding this comment

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

a bunch of "shoulds" (not sure if worth of having all, extracted from best practices):

  • Implement a health check
  • Add template variables support
  • Skip execution for hidden or empty queries
  • Specify a default query
  • Add support for alerting (if backend enabled)
  • Keep cached connections (if backend enabled)

- Break public APIs (query model)
- Use the local file system
- Use environment variables
- Execute arbitrary code in the backend
Copy link
Contributor

Choose a reason for hiding this comment

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

more "shouldn'ts":

  • Use upstream Golang HTTP client, SHOULD use Grafana plugin SDK HTTP client instead.
  • Use "info" log level, use "debug" or "error" instead.


export const plugin = new DataSourcePlugin<DataSource, MyQuery, MyDataSourceOptions>(DataSource)
.setQueryEditor(QueryEditor)
.setVariableQueryEditor(VariableQueryEditor);
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach is deprecated, better to use a more modern example

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

Labels

create-plugin related to the create-plugin tool minor Increment the minor version when merged

Projects

Status: 🧑‍💻 In development

Development

Successfully merging this pull request may close these issues.

3 participants