Skip to content

Docs: Add guide for data source plugin default variables and links#2488

Open
mckn wants to merge 3 commits intomainfrom
mckn/docs-new-api-functions
Open

Docs: Add guide for data source plugin default variables and links#2488
mckn wants to merge 3 commits intomainfrom
mckn/docs-new-api-functions

Conversation

@mckn
Copy link
Collaborator

@mckn mckn commented Feb 26, 2026

What this PR does / why we need it

Adds comprehensive documentation for the new getDefaultVariables and getDefaultLinks methods on the DataSourceApi interface, available in Grafana 13.0+. This guide explains how data source plugin developers can register default variables and dashboard links that are automatically loaded onto any dashboard using their data source.

The documentation includes code examples, explains the key behaviors (runtime loading, URL sync, read-only constraints), and provides type references for developers implementing these features.

Related to: grafana/grafana#109108

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

This documentation follows the established patterns and conventions in the data-source-plugins how-to guide directory, including consistent code example formatting with the class extends DataSourceApi pattern.

Adds documentation for the new getDefaultVariables and getDefaultLinks methods on DataSourceApi, available in Grafana 13.0+. Includes code examples and explains how to implement these features, plus their runtime behavior and user-facing constraints.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@mckn mckn requested a review from a team as a code owner February 26, 2026 09:31
Copilot AI review requested due to automatic review settings February 26, 2026 09:31
@mckn mckn requested a review from a team as a code owner February 26, 2026 09:31
@mckn mckn requested review from eledobleefe and joshhunt February 26, 2026 09:31
@mckn mckn requested a review from Ukochka February 26, 2026 09:32
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

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

✨ This PR can be merged. It will not be considered when calculating future versions of the npm packages and will not appear in the changelogs.

@mckn mckn changed the title docs: Add guide for data source plugin default variables and links Docs: Add guide for data source plugin default variables and links Feb 26, 2026
@mckn mckn moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Feb 26, 2026
@mckn mckn self-assigned this Feb 26, 2026
@mckn mckn added type/docs Changes only affect the documentation release Create a release when this pr is merged no-changelog Don't include in changelog and version calculations and removed release Create a release when this pr is merged labels Feb 26, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive documentation for two new methods (getDefaultVariables and getDefaultLinks) on the DataSourceApi interface available in Grafana 13.0+. The documentation enables data source plugin developers to register default variables and dashboard links that automatically load onto dashboards using their data source.

Changes:

  • Added new documentation file explaining how to implement getDefaultVariables and getDefaultLinks methods
  • Included code examples following the established class extends DataSourceApi pattern
  • Added sidebar entry for the new documentation page

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
docusaurus/website/sidebars.ts Added sidebar entry for the new documentation page, positioned logically after the related "add-support-for-variables" guide
docusaurus/docs/how-to-guides/data-source-plugins/add-default-variables-and-links.md New comprehensive guide with code examples, key behaviors explanation, and types reference for implementing default variables and links in data source plugins

mckn and others added 2 commits February 26, 2026 10:50
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mckn mckn requested a review from Copilot February 26, 2026 09:58
| **buildMode** | `string` | The build mode of the plugin. This field is set automatically at build time, so it should not be provided manually.<br/> | |
| **builtIn** | `boolean` | [internal only] Indicates whether the plugin is developed and shipped as part of Grafana. Also known as a 'core plugin'.<br/> | |
| **category** | `string` | Plugin category used on the Add data source page.<br/>Possible values are: `"tsdb"`, `"logging"`, `"cloud"`, `"tracing"`, `"profiling"`, `"sql"`, `"enterprise"`, `"iot"`, `"other"`<br/> | |
| **category** | `string` | Plugin category used on the Add new connection page. Can be one from the list: "tsdb", "logging", "cloud", "tracing", "profiling", "sql", "enterprise", "iot", "other", empty string or custom string<br/> | |
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't true, at least not yet...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That file is auto-generated when you call npm -w website run prebuild. I'm not sure what change caused this. Let me see if I can find it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is from this PR: grafana/grafana#117898

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@urbiz-grafana urbiz-grafana left a comment

Choose a reason for hiding this comment

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

LGTM!


:::note

This feature is available from Grafana 13.0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we wanna merge this in advance of G13 it might be nice to point devs to the nightly builds so they can play around with it in advance? 🤔

Comment on lines +37 to +38
import { DataSourceApi, DataSourceInstanceSettings } from '@grafana/data';
import { VariableKind, DashboardLink } from '@grafana/schema/apis/dashboard.grafana.app/v2';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which versions of the @grafana npm dependencies are required to use these features / types?

Copy link
Collaborator Author

@mckn mckn Feb 27, 2026

Choose a reason for hiding this comment

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

Ah, sorry - it is 12.4.0 I believe. I will update this information.

Comment on lines +101 to +111
## Types reference

Both methods use types from the `@grafana/schema` package:

```ts
import { VariableKind, DashboardLink } from '@grafana/schema/apis/dashboard.grafana.app/v2';
```

`VariableKind` is a union type that supports several variable kinds including `CustomVariable`, `QueryVariable`, `DatasourceVariable`, `IntervalVariable`, `TextVariable`, `ConstantVariable`, and others. Each kind has a `spec` object with properties specific to that variable type.

`DashboardLink` defines a dashboard link with properties such as `title`, `url`, `type`, `icon`, `targetBlank`, and `placement`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I'm not sure how much benefit I see in this. If the dev is dropping the code snippets in their IDE I'd expect them to option+click on the types to see the entire interface.

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

Labels

no-changelog Don't include in changelog and version calculations type/docs Changes only affect the documentation

Projects

Status: 🔬 In review

Development

Successfully merging this pull request may close these issues.

5 participants