Metrist Datasource for Grafana
Getting started
Add the golang and mage plugin through asdf and install the required versions stated in .tool-versions
asdf plugin-add golang
asdf plugin-add mage
asdf plugin-add nodejs
asdf install
Quickest way to get started is to run
# NPM
npm ci
# Go
go get
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest # Required for openapi codegen
asdf reshim
mage -v # Build the backend
npm run dev # Build the frontend
npm run server # Run grafana server
npm run server:with-plugin # Run grafana server with the datasource plugin ready to be installed pointed to dev
npm run server:with-plugin-local # Run grafana server with the datasource plugin ready to be installed pointed to local
npm run server:with-plugin-prod # Run grafana server with the datasource plugin ready to be installed pointed to prod
Running the Frontend, Backend and Installing the plugin
- Run
npm run server:with-plugin
- In a separate terminal run the frontend
npm run dev
- Head over to
http://localhost:3000/datasources
-> Add data source
-> Search for Metrist
- Click on the
Metrist
plugin. This will install the plugin
- Configure the
API Key
and click Save and test
Frontend
-
Install dependencies
npm install
-
Build plugin in development mode or run in watch mode
npm run dev
# or
npm run watch
-
Build plugin in production mode
npm run build
-
Run the tests (using Jest)
# Runs the tests and watches for changes
npm run test
# Exists after running all the tests
npm run lint:ci
-
Spin up a Grafana instance and run the plugin inside it (using Docker)
npm run server
-
Run the E2E tests (using Cypress)
# Spin up a Grafana instance first that we tests against
npm run server
# Start the tests
npm run e2e
-
Run the linter
npm run lint
# or
npm run lint:fix
Backend
-
Update Grafana plugin SDK for Go dependency to the latest minor version:
go get
-
Build backend plugin binaries for Linux, Windows and Darwin:
mage -v
-
List all available Mage targets for additional commands:
mage -l
OpenAPI Generated Code
The code in pkg/internal/openapi.go
is generated by oapi-codegen. Our backend exposes an openapi v3 spec at /api/openapi which codegen can use
-
install oapi codegen
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
then asdf reshim
if using asdf
-
Run the following to generate the go file
oapi-codegen -package internal -generate types,client <url to /api/openapi for backend>.yaml > pkg/internal/openapi.go
Learn more
Below you can find source code for existing app plugins and other related documentation.