Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
Sync with simple datasource repo (#11)
Browse files Browse the repository at this point in the history
* Sync circleci config

* Sync changes from simple-datasource master branch

* Update readme

* yarn install

* Build and test backend in ci

Fixes #5
  • Loading branch information
marefr authored May 15, 2020
1 parent 0b424f0 commit 04a76ec
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 493 deletions.
227 changes: 72 additions & 155 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,158 +1,75 @@
version: 2
jobs:
build_plugin:
docker:
- image: circleci/node:12
working_directory: ~/plugin
steps:
- checkout
- restore_cache:
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install yarn
command: yarn install --pure-lockfile
- run:
name: Run Toolkit Build
command: |
npx grafana-toolkit plugin:ci-build
npx grafana-toolkit plugin:ci-build --finish
- save_cache:
paths:
- node_modules
key: yarn-packages-{{ checksum "yarn.lock" }}
- persist_to_workspace:
root: .
paths:
- ci
package:
docker:
- image: circleci/node:12
working_directory: ~/plugin
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Package Distribution
command: npx grafana-toolkit plugin:ci-package
- persist_to_workspace:
root: .
paths:
- ci/jobs/package
- ci/packages
- ci/dist
- ci/grafana-test-env
test_6_2_5:
docker:
- image: circleci/node:12-browsers
working_directory: ~/plugin
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Setup Grafana (local install)
command: |
wget https://dl.grafana.com/oss/release/grafana_6.2.5_amd64.deb
sudo apt-get install -y adduser libfontconfig1
sudo dpkg -i grafana_6.2.5_amd64.deb
sudo apt-get install locate
sudo updatedb
sudo locate grafana
sudo cat /etc/grafana/grafana.ini
sudo echo ------------------------
sudo cp ci/grafana-test-env/custom.ini /usr/share/grafana/conf/custom.ini
sudo cp ci/grafana-test-env/custom.ini /etc/grafana/grafana.ini
sudo service grafana-server start
sudo grafana-cli --version
- run:
name: Run e2e tests
command: |
npx grafana-toolkit plugin:ci-test
- persist_to_workspace:
root: .
paths:
- ci/jobs/test_6_2_5
- store_test_results:
path: ci/jobs/test_6_2_5
- store_artifacts:
path: ci/jobs/test_6_2_5
test_6_3_0_beta1:
docker:
- image: circleci/node:12-browsers
working_directory: ~/plugin
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Setup Grafana (local install)
command: |
wget https://dl.grafana.com/oss/release/grafana_6.3.0-beta1_amd64.deb
sudo apt-get install -y adduser libfontconfig1
sudo dpkg -i grafana_6.3.0-beta1_amd64.deb
sudo apt-get install locate
sudo updatedb
sudo locate grafana
sudo cat /etc/grafana/grafana.ini
sudo echo ------------------------
sudo cp ci/grafana-test-env/custom.ini /usr/share/grafana/conf/custom.ini
sudo cp ci/grafana-test-env/custom.ini /etc/grafana/grafana.ini
sudo service grafana-server start
sudo grafana-cli --version
- run:
name: Run e2e tests
command: |
npx grafana-toolkit plugin:ci-test
- persist_to_workspace:
root: .
paths:
- ci/jobs/test_6_3_0_beta1
- store_test_results:
path: ci/jobs/test_6_3_0_beta1
- store_artifacts:
path: ci/jobs/test_6_3_0_beta1
report:
docker:
- image: circleci/node:12
working_directory: ~/plugin
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Toolkit Report
command: npx grafana-toolkit plugin:ci-report
- store_artifacts:
path: ci
version: 2.1

parameters:
ssh-fingerprint:
type: string
default: ${GITHUB_SSH_FINGERPRINT}

aliases:
# Workflow filters
- &filter-only-master
branches:
only: master
- &filter-only-release
branches:
only: /^v[1-9]*[0-9]+\.[1-9]*[0-9]+\.x$/

workflows:
version: 2
plugin_workflow:
jobs:
- build_plugin
- package:
requires:
- build_plugin
- test_6_2_5:
requires:
- package
- test_6_3_0_beta1:
requires:
- package
- report:
requires:
- test_6_2_5
- test_6_3_0_beta1
- build

executors:
default_exec: # declares a reusable executor
docker:
- image: srclosson/grafana-plugin-ci-alpine:latest
e2e_exec:
docker:
- image: srclosson/grafana-plugin-ci-e2e:latest

jobs:
build:
executor: default_exec
steps:
- checkout
- restore_cache:
name: restore node_modules
keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run:
name: Install dependencies
command: |
mkdir ci
[ -f ~/project/node_modules/.bin/grafana-toolkit ] || yarn install --frozen-lockfile
- save_cache:
name: save node_modules
paths:
- ~/project/node_modules
key: build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run:
name: Build and test frontend
command: ./node_modules/.bin/grafana-toolkit plugin:ci-build
- run:
name: Build backend
command: mage -v buildAll
- run:
name: Test backend
command: |
mage -v lint
mage -v coverage
- run:
name: Move results to ci folder
command: ./node_modules/.bin/grafana-toolkit plugin:ci-build --finish
- run:
name: Package distribution
command: |
./node_modules/.bin/grafana-toolkit plugin:ci-package
- persist_to_workspace:
root: .
paths:
- ci/jobs/package
- ci/packages
- ci/dist
- ci/grafana-test-env
- store_artifacts:
path: ci
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ work/
ci/
e2e-results/

# Editor
.idea
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"),
};
};
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,57 @@
This template is a starting point for building Grafana Data Source Backend Plugins

## What is Grafana Data Source Backend Plugin?
Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.

Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.

For more information about backend plugins, refer to the documentation on [Backend plugins](https://grafana.com/docs/grafana/latest/developers/plugins/backend/).

## Getting started

A data source backend plugin consists of both frontend and backend components.

### Frontend

1. Install dependencies
```BASH
yarn install
```
2. Build plugin the plugin

2. Build plugin in development mode or run in watch mode
```BASH
yarn dev
mage -v buildAll
```
or
```BASH
yarn watch
```
3. Build plugin in production mode
```BASH
yarn build
```

### Backend

1. Update [Grafana plugin SDK for Go](https://grafana.com/docs/grafana/latest/developers/plugins/backend/grafana-plugin-sdk-for-go/) dependency to the latest minor version:

```bash
go get -u github.com/grafana/grafana-plugin-sdk-go
```

2. Build backend plugin binaries for Linux, Windows and Darwin:
```BASH
mage -v
```

3. List all available Mage targets for additional commands:
```BASH
mage -l
```

## Learn more

- [Build a data source backend plugin tutorial](https://grafana.com/tutorials/build-a-data-source-backend-plugin)
- [Grafana documentation](https://grafana.com/docs/)
- [Grafana Tutorials](https://grafana.com/tutorials/) - Grafana Tutorials are step-by-step guides that help you make the most of Grafana
- [Grafana UI Library](https://developers.grafana.com/ui) - UI components to help you build interfaces using Grafana Design System
- [Grafana plugin SDK for Go](https://grafana.com/docs/grafana/latest/developers/plugins/backend/grafana-plugin-sdk-for-go/)
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "simple-datasource-backend",
"version": "1.0.0",
"description": "Grafana Data Source Plugin Template",
"backend": true,
"executable": "gpx_simple_datasource_backend",
"description": "Grafana Data Source Backend Plugin Template",
"scripts": {
"build": "grafana-toolkit plugin:build",
"test": "grafana-toolkit plugin:test",
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { LegacyForms } from '@grafana/ui';
import React, { ChangeEvent, PureComponent } from 'react';
import { LegacyForms } from '@grafana/ui';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { MyDataSourceOptions, MySecureJsonData } from './types';

const { SecretFormField, FormField } = LegacyForms;
Expand Down
5 changes: 3 additions & 2 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { QueryEditorProps } from '@grafana/data';
import { LegacyForms } from '@grafana/ui';
import defaults from 'lodash/defaults';

import React, { ChangeEvent, PureComponent } from 'react';
import { LegacyForms } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { DataSource } from './DataSource';
import { defaultQuery, MyDataSourceOptions, MyQuery } from './types';

Expand Down
5 changes: 0 additions & 5 deletions src/module.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "datasource",
"name": "Grafana Data Source Plugin Template",
"name": "Grafana Data Source Backend Plugin Template",
"id": "myorgid-simple-backend-datasource",
"metrics": true,
"backend": true,
"executable": "gpx_simple_datasource_backend",
"info": {
"description": "Grafana Data Source Plugin Template",
"description": "Grafana Data Source Backend Plugin Template",
"author": {
"name": "Your Name"
},
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "@grafana/toolkit/src/config/tsconfig.plugin.json",
"extends": "./node_modules/@grafana/toolkit/src/config/tsconfig.plugin.json",
"include": ["src", "types"],
"compilerOptions": {
"rootDir": "./src",
"baseUrl": "./src",
"typeRoots": ["./node_modules/@types"]
}
}
}
Loading

0 comments on commit 04a76ec

Please sign in to comment.