Skip to content

Latest commit

 

History

History
158 lines (111 loc) · 5.76 KB

DEVELOPMENT.md

File metadata and controls

158 lines (111 loc) · 5.76 KB

Development

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

Installing via grafana-cli

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

Building and Development

Setup your system

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*

Setup build environment

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

Test inside Grafana instance

Note that npm run server uses docker compose under the hood.

npm run dev
mage -v build:linux
npm run server

Recommended development environment

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

Common Errors During Development

Example repos

Some random examples of data source plugin source code

Updating dependencies

npm update
go get -u
go mod tidy

Dependency Notes

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

To-Do

  • 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