Skip to content

Commit 1c30d84

Browse files
authored
Add CI and documentation (#4)
1 parent 5075763 commit 1c30d84

16 files changed

+315
-20136
lines changed

.github/workflows/ci.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Setup Node.js environment
18+
uses: actions/[email protected]
19+
with:
20+
node-version: "16.x"
21+
22+
- name: Get yarn cache directory path
23+
id: yarn-cache-dir-path
24+
run: echo "::set-output name=dir::$(yarn cache dir)"
25+
26+
- name: Cache yarn cache
27+
uses: actions/cache@v2
28+
id: cache-yarn-cache
29+
with:
30+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
31+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
32+
restore-keys: |
33+
${{ runner.os }}-yarn-
34+
35+
- name: Cache node_modules
36+
id: cache-node-modules
37+
uses: actions/cache@v2
38+
with:
39+
path: node_modules
40+
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
43+
44+
- name: Install dependencies
45+
run: yarn install --frozen-lockfile
46+
47+
- name: Build and test frontend
48+
run: yarn build
49+
50+
- name: Check for backend
51+
id: check-for-backend
52+
run: |
53+
if [ -f "Magefile.go" ]
54+
then
55+
echo "::set-output name=has-backend::true"
56+
fi
57+
58+
- name: Setup Go environment
59+
if: steps.check-for-backend.outputs.has-backend == 'true'
60+
uses: actions/setup-go@v2
61+
with:
62+
go-version: "1.15"
63+
64+
- name: Test backend
65+
if: steps.check-for-backend.outputs.has-backend == 'true'
66+
uses: magefile/mage-action@v1
67+
with:
68+
version: latest
69+
args: coverage
70+
71+
- name: Build backend
72+
if: steps.check-for-backend.outputs.has-backend == 'true'
73+
uses: magefile/mage-action@v1
74+
with:
75+
version: latest
76+
args: buildAll

.github/workflows/release.yaml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*" # Run workflow on version tags, e.g. v1.0.0.
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Setup Node.js environment
16+
uses: actions/[email protected]
17+
with:
18+
node-version: "14.x"
19+
20+
- name: Setup Go environment
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: "1.16"
24+
25+
- name: Get yarn cache directory path
26+
id: yarn-cache-dir-path
27+
run: echo "::set-output name=dir::$(yarn cache dir)"
28+
29+
- name: Cache yarn cache
30+
uses: actions/cache@v2
31+
id: cache-yarn-cache
32+
with:
33+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
34+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-yarn-
37+
38+
- name: Cache node_modules
39+
id: cache-node-modules
40+
uses: actions/cache@v2
41+
with:
42+
path: node_modules
43+
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
46+
47+
- name: Install dependencies
48+
run: yarn install --frozen-lockfile;
49+
if: |
50+
steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
51+
steps.cache-node-modules.outputs.cache-hit != 'true'
52+
53+
- name: Build and test frontend
54+
run: yarn build
55+
56+
- name: Check for backend
57+
id: check-for-backend
58+
run: |
59+
if [ -f "Magefile.go" ]
60+
then
61+
echo "::set-output name=has-backend::true"
62+
fi
63+
64+
- name: Test backend
65+
if: steps.check-for-backend.outputs.has-backend == 'true'
66+
uses: magefile/mage-action@v1
67+
with:
68+
version: latest
69+
args: coverage
70+
71+
- name: Build backend
72+
if: steps.check-for-backend.outputs.has-backend == 'true'
73+
uses: magefile/mage-action@v1
74+
with:
75+
version: latest
76+
args: buildAll
77+
78+
- name: Sign plugin
79+
run: yarn sign
80+
env:
81+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
82+
83+
- name: Get plugin metadata
84+
id: metadata
85+
run: |
86+
sudo apt-get install jq
87+
88+
export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
89+
export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
90+
export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
91+
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
92+
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
93+
94+
echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}"
95+
echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}"
96+
echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}"
97+
echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}"
98+
echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
99+
100+
echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
101+
102+
- name: Read changelog
103+
id: changelog
104+
run: |
105+
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
106+
echo "::set-output name=path::release_notes.md"
107+
108+
- name: Check package version
109+
run: if [ "v${{ steps.metadata.outputs.plugin-version }}" != "${{ steps.metadata.outputs.github-tag }}" ]; then printf "\033[0;31mPlugin version doesn't match tag name\033[0m\n"; exit 1; fi
110+
111+
- name: Package plugin
112+
id: package-plugin
113+
run: |
114+
mv dist ${{ steps.metadata.outputs.plugin-id }}
115+
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
116+
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
117+
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
118+
119+
- name: Lint plugin
120+
run: |
121+
git clone https://github.com/grafana/plugin-validator
122+
pushd ./plugin-validator/pkg/cmd/plugincheck
123+
go install
124+
popd
125+
plugincheck ${{ steps.metadata.outputs.archive }}
126+
127+
- name: Create release
128+
id: create_release
129+
uses: actions/create-release@v1
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
with:
133+
tag_name: ${{ github.ref }}
134+
release_name: Release ${{ github.ref }}
135+
body_path: ${{ steps.changelog.outputs.path }}
136+
draft: true
137+
138+
- name: Add plugin to release
139+
id: upload-plugin-asset
140+
uses: actions/upload-release-asset@v1
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143+
with:
144+
upload_url: ${{ steps.create_release.outputs.upload_url }}
145+
asset_path: ./${{ steps.metadata.outputs.archive }}
146+
asset_name: ${{ steps.metadata.outputs.archive }}
147+
asset_content_type: application/zip
148+
149+
- name: Add checksum to release
150+
id: upload-checksum-asset
151+
uses: actions/upload-release-asset@v1
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154+
with:
155+
upload_url: ${{ steps.create_release.outputs.upload_url }}
156+
asset_path: ./${{ steps.metadata.outputs.archive-checksum }}
157+
asset_name: ${{ steps.metadata.outputs.archive-checksum }}
158+
asset_content_type: text/plain
159+
160+
- name: Publish to Grafana.com
161+
run: |
162+
echo A draft release has been created for your plugin. Please review and publish it. Then submit your plugin to grafana.com/plugins by opening a PR to https://github.com/grafana/grafana-plugin-repository with the following entry:
163+
echo
164+
echo '{ "id": "${{ steps.metadata.outputs.plugin-id }}", "type": "${{ steps.metadata.outputs.plugin-type }}", "url": "https://github.com/${{ github.repository }}", "versions": [ { "version": "${{ steps.metadata.outputs.plugin-version }}", "commit": "${{ github.sha }}", "url": "https://github.com/${{ github.repository }}", "download": { "any": { "url": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}", "md5": "${{ steps.package-plugin.outputs.checksum }}" } } } ] }' | jq .

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.DS_Store
3+
.eslintcache
4+
package-lock.json

README.md

Lines changed: 15 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,28 @@
1-
# Grafana data source plugin template
1+
# Parseable Datasource for Grafana
22

3-
This template is a starting point for building a Data Source Plugin for Grafana.
3+
This data source plugin allows you to query and visualize log data stored in Parseable server.
44

5-
## What are Grafana data source plugins?
5+
## Pre-requisites
66

7-
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.
7+
[Parseable server](https://github.com/parseablehq/parseable) setup and receiving logs from your application. Read more on [Parseable documentation](https://www.parseable.io/docs/quick-start).
88

9-
## Getting started
9+
## Installation
1010

11-
### Frontend
11+
- Install the plugin using the Grafana CLI, using the command `grafana-cli plugins install parseable-datasource`. Then restart Grafana. Alternatively, you can install the plugin from your Grafana instance (Configuration > Data sources > Add Data source).
1212

13-
1. Install dependencies
13+
- Add Parseable as a data source at the data source configuration page.
1414

15-
```bash
16-
yarn install
17-
```
15+
- Configure the data source specifying URL and port like `https://demo.parseable.io:443`. Parseable supports basic auth currently, so toggle the "Basic Auth" option under "Auth" section and enter the username and password under "Basic Auth Details" section. For Parseable demo server use `parseable` as both, username and password.
1816

19-
2. Build plugin in development mode or run in watch mode
17+
- Push the `Save and Test` button, if there is an error message, check the credentials and connection.
2018

21-
```bash
22-
yarn dev
19+
![data source config](./src/img/configuration.png)
2320

24-
# or
21+
## Usage
2522

26-
yarn watch
27-
```
23+
Once the plugin is configured with correct Parseable server instance. You can start using it to query logs and visualize them. You can use the query editor to write your own queries.
2824

29-
3. Build plugin in production mode
25+
## Screenshots
3026

31-
```bash
32-
yarn build
33-
```
34-
35-
4. Run the tests (using Jest)
36-
37-
```bash
38-
# Runs the tests and watches for changes
39-
yarn test
40-
41-
# Exists after running all the tests
42-
yarn lint:ci
43-
```
44-
45-
5. Spin up a Grafana instance and run the plugin inside it (using Docker)
46-
47-
```bash
48-
yarn server
49-
```
50-
51-
6. Run the E2E tests (using Cypress)
52-
53-
```bash
54-
# Spin up a Grafana instance first that we tests against
55-
yarn server
56-
57-
# Start the tests
58-
yarn e2e
59-
```
60-
61-
7. Run the linter
62-
63-
```bash
64-
yarn lint
65-
66-
# or
67-
68-
yarn lint:fix
69-
```
70-
71-
72-
73-
# Distributing your plugin
74-
75-
When distributing a Grafana plugin either within the community or privately the plugin must be signed so the Grafana application can verify its authenticity. This can be done with the `@grafana/sign-plugin` package.
76-
77-
_Note: It's not necessary to sign a plugin during development. The docker development environment that is scaffolded with `@grafana/create-plugin` caters for running the plugin without a signature._
78-
79-
## Initial steps
80-
81-
Before signing a plugin please read the Grafana [plugin publishing and signing criteria](https://grafana.com/docs/grafana/latest/developers/plugins/publishing-and-signing-criteria/) documentation carefully.
82-
83-
`@grafana/create-plugin` has added the necessary commands and workflows to make signing and distributing a plugin via the grafana plugins catalog as straightforward as possible.
84-
85-
Before signing a plugin for the first time please consult the Grafana [plugin signature levels](https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#plugin-signature-levels) documentation to understand the differences between the types of signature level.
86-
87-
1. Create a [Grafana Cloud account](https://grafana.com/signup).
88-
2. Make sure that the first part of the plugin ID matches the slug of your Grafana Cloud account.
89-
- _You can find the plugin ID in the plugin.json file inside your plugin directory. For example, if your account slug is `acmecorp`, you need to prefix the plugin ID with `acmecorp-`._
90-
3. Create a Grafana Cloud API key with the `PluginPublisher` role.
91-
4. Keep a record of this API key as it will be required for signing a plugin
92-
93-
## Signing a plugin
94-
95-
### Using Github actions release workflow
96-
97-
If the plugin is using the github actions supplied with `@grafana/create-plugin` signing a plugin is included out of the box. The [release workflow](./.github/workflows/release.yml) can prepare everything to make submitting your plugin to Grafana as easy as possible. Before being able to sign the plugin however a secret needs adding to the Github repository.
98-
99-
1. Please navigate to "settings > secrets > actions" within your repo to create secrets.
100-
2. Click "New repository secret"
101-
3. Name the secret "GRAFANA_API_KEY"
102-
4. Paste your Grafana Cloud API key in the Secret field
103-
5. Click "Add secret"
104-
105-
#### Push a version tag
106-
107-
To trigger the workflow we need to push a version tag to github. This can be achieved with the following steps:
108-
109-
1. Run `npm version <major|minor|patch>`
110-
2. Run `git push origin main --follow-tags`
111-
112-
113-
## Learn more
114-
115-
Below you can find source code for existing app plugins and other related documentation.
116-
117-
- [Basic data source plugin example](https://github.com/grafana/grafana-plugin-examples/tree/master/examples/datasource-basic#readme)
118-
- [Plugin.json documentation](https://grafana.com/docs/grafana/latest/developers/plugins/metadata/)
119-
- [How to sign a plugin?](https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/)
27+
![log explorer](./src/img/logs.png)
28+
![failure rate](./src/img/dashboard.png)

0 commit comments

Comments
 (0)