-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create-plugin: Add provisioning scaffold (#529)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Joe Perez <joseph.perez@grafana.com> Co-authored-by: David Harris <david.harris@grafana.com>
- Loading branch information
1 parent
a3755f7
commit 2dfba91
Showing
25 changed files
with
273 additions
and
14 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
docusaurus/docs/publish-a-plugin/provide-test-environment.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
id: provide-test-environment | ||
title: Provide a test environment | ||
description: How to add provisioning to your plugin to speed up your plugin review process. | ||
keywords: | ||
- github | ||
- provisioning | ||
- provision | ||
- review | ||
sidebar_position: 5 | ||
--- | ||
|
||
# Provide a test environment | ||
|
||
Developers often ask us how long it takes for a plugin to be reviewed for publishing to the Grafana [plugin catalog](https://grafana.com/plugins). Although we [can't provide estimates](https://grafana.com/developers/plugin-tools/publish-a-plugin/publish-a-plugin#how-long-does-it-take-to-review-a-submission), we are always looking for ways to reduce cycle times. | ||
|
||
By far the most time consuming aspect of a plugin's review is the creation of a suitable test environment so we can verify its behavior. This step often involves a number of back-and-forth conversations between the plugin developer and the review team. | ||
|
||
To drastically improve the review time, developers can provide this themselves by [_provisioning_](https://grafana.com/docs/grafana/latest/administration/provisioning/#provision-grafana) their plugin. Provisioning refers to the process of preparing and configuring a test environment within the plugin's [Docker development environment](https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment). | ||
|
||
## Why should plugin developers care about this? | ||
|
||
There are several benefits to provisioning: | ||
|
||
- **Much faster review times.** If you provision your plugin prior to submission, your wait for the review will be much shorter. | ||
- **Easier contributions.** By having an out-of-the-box working example available, would-be contributors to your plugin can easily experiment with additions to the plugin and raise pull requests. | ||
- **Easier set up for e2e tests.** By provisioning dashboards, e2e tests can run against specific scenarios across local development and in CI. | ||
- **Improved clarity.** We have found that provisioned plugins make it easier for tech-savvy users to understand how the plugin works. | ||
|
||
## Mechanism to provide a test environment | ||
|
||
Grafana can be configured to have resources installed and enabled through a mechanism known as [provisioning](https://grafana.com/docs/grafana/latest/administration/provisioning/#provision-grafana), where resources are configured in a YAML file under a `/provisioning` directory. | ||
|
||
Since create-plugin v2.8.0, we generate provisioning capabilities for all plugin types (apps, scenes-apps, datasources, panels), and to include a sample dashboard as part of create-plugin. | ||
|
||
## What do plugin developers need to do? | ||
|
||
:::note | ||
|
||
Provisioning is not required; it's an optional part of the plugin submission process that will speed the review. | ||
|
||
::: | ||
|
||
1. When you run the create-plugin tool, it will generate a folder called `provisioning` with additional files based on the plugin type selected. | ||
1. When you run the Docker development environment, these files are used to automatically install (and if applicable, _enable_) your plugin and a sample dashboard. | ||
1. We recommended that you use and update the sample dashboard to continuously verify behavior as part of your development process. And, as appropriate, configure your plugin so that it can return data. | ||
|
||
:::note | ||
|
||
In the case where a plugin has been scaffolded with a previous version of create-plugin, a new command can be run to retrospectively add the provisioning files. | ||
|
||
::: | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/create-plugin/src/commands/provisioning.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import glob from 'glob'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { TEMPLATE_PATHS, TEXT } from '../constants'; | ||
import { getPluginJson } from '../utils/utils.plugin'; | ||
import { compileProvisioningTemplateFile, getTemplateData } from '../utils/utils.templates'; | ||
import { confirmPrompt, printMessage, printSuccessMessage, printError } from '../utils/utils.console'; | ||
|
||
export const provisioning = async () => { | ||
const { type } = getPluginJson(); | ||
const provisioningFolder = path.join(process.cwd(), 'provisioning'); | ||
try { | ||
if (await confirmPrompt(TEXT.addProvisioning)) { | ||
if (!fs.existsSync(provisioningFolder)) { | ||
const provisioningSpecificFiles = glob.sync(`${TEMPLATE_PATHS[type]}/provisioning/**`, { dot: true }); | ||
|
||
provisioningSpecificFiles.forEach((file) => { | ||
compileProvisioningTemplateFile(type, file, getTemplateData()); | ||
}); | ||
printSuccessMessage(TEXT.addProvisioningSuccess); | ||
} else { | ||
printMessage(`You plugin already has provisioning files located under ${provisioningFolder}, aborting.`); | ||
process.exit(0); | ||
} | ||
} else { | ||
printMessage(TEXT.addProvisioningAborted); | ||
process.exit(1); | ||
} | ||
} catch (error) { | ||
printError(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/create-plugin/templates/app/provisioning/plugins/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
For more information see our documentation: | ||
|
||
- [Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/) | ||
- [Provision a plugin](https://grafana.com/developers/plugin-tools/publish-a-plugin/provide-test-environment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/create-plugin/templates/datasource/provisioning/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
For more information see [Provision dashboards and data sources](https://grafana.com/tutorials/provision-dashboards-and-data-sources/) |
Empty file.
10 changes: 10 additions & 0 deletions
10
packages/create-plugin/templates/datasource/provisioning/datasources/datasources.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: '{{ pluginName }}' | ||
type: '{{ normalize_id pluginName orgName 'datasource' }}' | ||
access: proxy | ||
isDefault: false | ||
orgId: 1 | ||
version: 1 | ||
editable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
For more information see [Provision dashboards and data sources](https://grafana.com/tutorials/provision-dashboards-and-data-sources/) |
Empty file.
71 changes: 71 additions & 0 deletions
71
packages/create-plugin/templates/panel/provisioning/dashboards/dashboard.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"annotations": { | ||
"list": [ | ||
{ | ||
"builtIn": 1, | ||
"datasource": { | ||
"type": "grafana", | ||
"uid": "-- Grafana --" | ||
}, | ||
"enable": true, | ||
"hide": true, | ||
"iconColor": "rgba(0, 211, 255, 1)", | ||
"name": "Annotations & Alerts", | ||
"type": "dashboard" | ||
} | ||
] | ||
}, | ||
"editable": true, | ||
"fiscalYearStartMonth": 0, | ||
"graphTooltip": 0, | ||
"links": [], | ||
"liveNow": false, | ||
"panels": [ | ||
{ | ||
"datasource": { | ||
"type": "grafana", | ||
"uid": "grafana" | ||
}, | ||
"gridPos": { | ||
"h": 8, | ||
"w": 12, | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"id": 1, | ||
"options": { | ||
"seriesCountSize": "sm", | ||
"showSeriesCount": false, | ||
"text": "Default value of text input option" | ||
}, | ||
"targets": [ | ||
{ | ||
"datasource": { | ||
"type": "datasource", | ||
"uid": "grafana" | ||
}, | ||
"queryType": "randomWalk", | ||
"refId": "A" | ||
} | ||
], | ||
"title": "Panel Title", | ||
"type": "{{ pluginId }}" | ||
} | ||
], | ||
"refresh": "", | ||
"schemaVersion": 38, | ||
"style": "dark", | ||
"tags": [], | ||
"templating": { | ||
"list": [] | ||
}, | ||
"time": { | ||
"from": "now-6h", | ||
"to": "now" | ||
}, | ||
"timepicker": {}, | ||
"timezone": "", | ||
"title": "Provisioned {{ pluginName }} dashboard", | ||
"version": 0, | ||
"weekStart": "" | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/create-plugin/templates/panel/provisioning/dashboards/default.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: 1 | ||
|
||
providers: | ||
- name: '{{ pluginName }}' | ||
type: file | ||
options: | ||
path: /etc/grafana/provisioning/dashboards |
4 changes: 4 additions & 0 deletions
4
packages/create-plugin/templates/scenes-app/provisioning/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
For more information see our documentation: | ||
|
||
- [Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/) | ||
- [Provision a plugin](https://grafana.com/developers/plugin-tools/publish-a-plugin/provide-test-environment) |
5 changes: 5 additions & 0 deletions
5
packages/create-plugin/templates/scenes-app/provisioning/custom.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
app_mode = development | ||
|
||
[feature_toggles] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ apiVersion: 1 | |
|
||
datasources: | ||
- name: gdev-testdata | ||
isDefault: true | ||
isDefault: false | ||
type: testdata |
12 changes: 12 additions & 0 deletions
12
packages/create-plugin/templates/scenes-app/provisioning/plugins/app.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: 1 | ||
|
||
apps: | ||
- type: '{{ normalize_id pluginName orgName 'app' }}' | ||
org_id: 1 | ||
org_name: '{{ orgName }}' | ||
disabled: false | ||
jsonData: | ||
apiUrl: http://default-url.com | ||
isApiKeySet: true | ||
secureJsonData: | ||
apiKey: secret-key |
5 changes: 0 additions & 5 deletions
5
packages/create-plugin/templates/scenes-app/provisioning/plugins/apps.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as semver from 'semver'; | ||
import { test, expect } from '../src'; | ||
|
||
test('should resolve ds picker selector with test id for grafana 10 and later', async ({ | ||
grafanaVersion, | ||
selectors, | ||
}, testInfo) => { | ||
testInfo.skip(semver.lt(grafanaVersion, '10.0.0')); | ||
expect(selectors.components.DataSourcePicker.container).toBe('data-testid Data source picker select container'); | ||
}); | ||
|
||
test('should resolve ds picker selector without test id for grafana 10 and later', async ({ | ||
grafanaVersion, | ||
selectors, | ||
}, testInfo) => { | ||
testInfo.skip(semver.gte(grafanaVersion, '10.0.0')); | ||
expect(selectors.components.DataSourcePicker.container).toBe('Data source picker select container'); | ||
}); |