https://grafana.com/developers/plugin-tools/create-a-plugin/develop-a-plugin/best-practices
https://grafana.com/developers/plugin-tools/tutorials/build-a-data-source-backend-plugin
If you want to test a released, but unsigned plugin, follow this.
https://grafana.com/docs/grafana/latest/cli/#override-default-plugin-zip-url
grafana cli --pluginUrl https://github.com/wildmountainfarms/wild-graphql-datasource/releases/download/v0.0.6/retrodaredevil-wildgraphql-datasource-0.0.6.zip plugins install retrodaredevil-wildgraphql-datasource
Then update grafana.ini
with
[plugins]
allow_loading_unsigned_plugins = retrodaredevil-wildgraphql-datasource
- Web requirements
- Backend requirements
- Install go https://go.dev/doc/install
- Install Mage https://magefile.org/
- Grafana requirements
- Install Docker: https://docs.docker.com/engine/install/
npm run server
command usesdocker compose
to bring up Grafana
- Make sure your user is part of the
docker
group
- Install Docker: https://docs.docker.com/engine/install/
An example of commands you could run. Customize this setup to your liking.
# install nvm https://github.com/nvm-sh/nvm#installing-and-updating
nvm install 20
rm -rf /usr/local/go
wget -c https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
# /usr/local/go is GOROOT $HOME/go is GOPATH, so add both bins to path
echo 'export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"' >> ~/.bashrc
cd ~/Documents/Clones
git clone https://github.com/magefile/mage
cd mage
# This will install to GOPATH, which is $HOME/go by default
go run bootstrap.go
# *docker installation not shown*
# *adding $USER to docker group not shown*
Go setup
# This will install to your GOPATH, which is $HOME/go by default.
go get -u github.com/grafana/grafana-plugin-sdk-go
go mod tidy
mage -v
mage -l
Node setup:
npm install
Note that npm run server
uses docker compose
under the hood.
npm run dev
mage -v build:linux
npm run server
You may choose to use VS Code, which has free tools for developing TypeScript and Go code. IntelliJ IDEA Ultimate is a non-free choice that has support for both TypeScript and Go code. Alternatively, WebStorm (also not free) covers TypeScript development and GoLand covers Go development.
If you are using IntelliJ IDEA Ultimate, make sure go to "Language & Frameworks > Go Modules" and click "Enable go modules integration".
If you are using VS Code, this is a good read: https://github.com/golang/vscode-go/blob/master/docs/gopath.md
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch
Some random examples of data source plugin source code
- https://github.com/grafana/grafana-infinity-datasource/tree/main/pkg
- https://github.com/cnosdb/grafana-datasource-plugin/blob/main/cnosdb/pkg/plugin/query_model.go
- https://github.com/grafana/grafana-plugin-examples/tree/main/examples/datasource-http-backend
npm update
go get -u
go mod tidy
This section contains notes about dependencies.
graphql-ws
is not actually required by us, but this issue is unresolved so that's why we include it- graphql/graphiql#2405 (comment) (yes as of writing it says it's closed, but it's not)
- It's not a bad thing that we include this dependency because it gives us a couple of types that we end up using
- Make annotation queries more intuitive
- Add support for secure variable data defined in the data source configuration
- The variables defined here cannot be overridden for any request - this is for security
- Also add support for secure HTTP headers
Lower priority To-Dos
- Customize default query (#1)
- Add support for variables: https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/add-support-for-variables#add-support-for-query-variables-to-your-data-source
- Add metrics to backend component: https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/add-logs-metrics-traces-for-backend-plugins#implement-metrics-in-your-plugin
- Support returning logs data: https://grafana.com/developers/plugin-tools/tutorials/build-a-logs-data-source-plugin
- We could just add
"logs": true
toplugin.json
, however we need to support the renaming of fields because sometimes thebody
ortimestamp
fields will be nested
- We could just add
- Publish as a plugin
- https://grafana.com/developers/plugin-tools/publish-a-plugin/publish-a-plugin
- https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin#generate-an-access-policy-token
- https://grafana.com/legal/plugins/
- https://grafana.com/developers/plugin-tools/publish-a-plugin/provide-test-environment
- Create a GraphQL button panel (or a SolarThing app) that has a button panel that can be used to
- Auto-populate the data path field by using
documentAST
to recognize the first path to an array - Look into Apollo GraphQL