metrist-grafana-datasource

module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: Apache-2.0

README

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
  1. Run npm run server:with-plugin
  2. In a separate terminal run the frontend npm run dev
  3. Head over to http://localhost:3000/datasources -> Add data source -> Search for Metrist
  4. Click on the Metrist plugin. This will install the plugin
  5. Configure the API Key and click Save and test
Frontend
  1. Install dependencies

    npm install
    
  2. Build plugin in development mode or run in watch mode

    npm run dev
    
    # or
    
    npm run watch
    
  3. Build plugin in production mode

    npm run build
    
  4. 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
    
  5. Spin up a Grafana instance and run the plugin inside it (using Docker)

    npm run server
    
  6. 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
    
  7. Run the linter

    npm run lint
    
    # or
    
    npm run lint:fix
    
Backend
  1. Update Grafana plugin SDK for Go dependency to the latest minor version:

    go get
    
  2. Build backend plugin binaries for Linux, Windows and Darwin:

    mage -v
    
  3. 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

  1. install oapi codegen go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest then asdf reshim if using asdf

  2. 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.

Directories

Path Synopsis
pkg
internal
Some helpers around the auto generated openapi.go structs for easy grafana data.Frame creation across auto created types
Some helpers around the auto generated openapi.go structs for easy grafana data.Frame creation across auto created types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL