Skip to content
Viacheslav Mitrofanov edited this page Sep 28, 2023 · 20 revisions

Development

This part of the documentation relates only to the development of the plugin and is not required if you only intended to use it.

The frontend part is implemented using Typescript, Yarn and React. The backend is written on Golang and based on Hashicorp Plugin System. The plugin development uses docker actively and it's recommended to have at least a basic understanding of docker and docker-compose, although all steps can be done without docker.

Installation and Build

First, clone the project. It has to be built with docker or with locally installed tools.

Docker Way (Recommended)

All steps below are given for OSX and Linux systems, see Building for Windows page for Windows OS.

  1. Install frontend dependencies
docker run --rm -v ${PWD}:/opt/gcds -w /opt/gcds node:20-alpine yarn install
  1. Build frontend
docker run --rm -v ${PWD}:/opt/gcds -w /opt/gcds node:20-alpine yarn build
  1. Install backend dependencies
docker run --rm -v ${PWD}:/go/src/github.com/ha/gcp -w /go/src/github.com/ha/gcp/backend golang:1-alpine go mod vendor
  1. Build backend
docker run --rm -v ${PWD}:/go/src/github.com/ha/gcp -w /go/src/github.com/ha/gcp/backend golang:1-alpine go build -o ../dist/cassandra-plugin_linux_amd64 .

Locally

If you have yarn and golang installed locally, you can do the build steps without docker:

yarn install
yarn build
cd backend
go mod download
go build -o ../dist/cassandra-plugin_$(go env -json | jq -r '"\(.GOOS)_\(.GOARCH)"') .

Run Grafana and Cassandra

docker-compose up -d

docker-compose includes three services:

  • Grafana by itself, the plugin is mounted as a volume to /var/lib/grafana/plugins/cassandra. Verbose logging is enabled. Grafana is available at http://localhost:3000, no password required.
  • Apache Cassandra, host cassandra:9042, user cassandra, password cassandra. cqlsh is available via docker-compose exec cassandra cqlsh -u cassandra -p cassandra.
  • Sample Data - a little script that loads sample data for development purposes.

After the startup, the datasource should be available in the list of datasources. Also, following lines should appear in grafana logs:

# Frontend part registered
lvl=info msg="Starting plugin search" logger=plugins
lvl=info msg="Registering plugin" logger=plugins name="Apache Cassandra"
...
# Backend part is started and running
msg="Plugins: Adding route" logger=http.server route=/public/plugins/hadesarchitect-cassandra-datasource dir=/var/lib/grafana/plugins/cassandra/dist
msg="starting plugin" logger=plugins plugin-id=hadesarchitect-cassandra-datasource path=/var/lib/grafana/plugins/cassandra/dist/cassandra-plugin_linux_amd64 args=[/var/lib/grafana/plugins/cassandra/dist/cassandra-plugin_linux_amd64]
msg="plugin started" logger=plugins plugin-id=hadesarchitect-cassandra-datasource path=/var/lib/grafana/plugins/cassandra/dist/cassandra-plugin_linux_amd64 pid=23
msg="waiting for RPC address" logger=plugins plugin-id=hadesarchitect-cassandra-datasource path=/var/lib/grafana/plugins/cassandra/dist/cassandra-plugin_linux_amd64
msg="2020-01-16T22:08:51.619Z [DEBUG] cassandra-backend-datasource: Running Cassandra backend datasource..." logger=plugins plugin-id=hadesarchitect-cassandra-datasource
msg="plugin address" logger=plugins plugin-id=hadesarchitect-cassandra-datasource address=/tmp/plugin991218850 network=unix timestamp=2020-01-16T22:08:51.622Z
msg="using plugin" logger=plugins plugin-id=hadesarchitect-cassandra-datasource version=1

To read the logs, use docker-compose logs -f grafana.

Testing

Docker Way (Recommended)

Backend tests:

docker run --rm -v ${PWD}:/go/src/github.com/ha/gcp -w /go/src/github.com/ha/gcp/backend golang:1-alpine go test -v -vet=off ./...

Locally

cd backend
go test ./...

Making Changes

Frontend

[OUTDATED] This part of the documentation is not updated yet

Run webpack with --watch option to enable watching:

  • docker run --rm -v ${PWD}:/opt/gcds -w /opt/gcds node:12 node node_modules/webpack/bin/webpack.js --watch
  • docker-compose restart grafana

Backend

With any changes done to backend, the binary file should be recompiled and grafana should be restarted:

  • docker run --rm -v ${PWD}:/go/src/github.com/ha/gcp -w /go/src/github.com/ha/gcp/backend golang:1-alpine go build -buildvcs=false -o ../dist/cassandra-plugin_linux_amd64 .
  • docker-compose restart grafana