Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests, Provisioning and update README #1

Merged
merged 6 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ jobs:
uses: codecov/codecov-action@v2
with:
directory: ./coverage/
files: ./coverage/lcov.info
files: ./coverage/lcov.info,./coverage/backend.out
env_vars: OS,PYTHON
fail_ci_if_error: true
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

## 1.1.0 (IN PROGRESS)

### Features / Enhancements

- Add Tests, Provisioning and update README (#1)

## 1.0.0 (2022-02-20)

### Features / Enhancements

- Initial release based on the Grafana 8.4.1.
- Returns Environment Variables.
- Allows to filter unnecessary or secured variables using Regex.
- Allows filtering unnecessary or secured variables using Regex.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,32 @@ Environment data source can be installed from the Grafana Marketplace or use the
grafana-cli plugins install volkovlabs-env-datasource
```

![Grafana Marketplace](https://raw.githubusercontent.com/VolkovLabs/volkovlabs-env-datasource/main/src/img/grafana-marketplace.png)

## Features

- Returns Environment Variables.
- Allows to filter unnecessary or secured variables using Regex.

## Provisioning

Grafana supports managing data sources by adding one or more YAML config files in the `provisioning/datasources` folder.

Example of provisioning the Environment Data Source with a filter `GF_` to return only Grafana related variables.

```
datasources:
- name: Environment
type: volkovlabs-env-datasource
access: proxy
isDefault: true
orgId: 1
version: 1
editable: true
jsonData:
filter: GF_
```

## Feedback

We love to hear from users, developers, and the whole community interested in this plugin. These are various ways to get in touch with us:
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/grafana/grafana-starter-datasource-backend

go 1.16

require github.com/grafana/grafana-plugin-sdk-go v0.126.0
require (
github.com/grafana/grafana-plugin-sdk-go v0.126.0
github.com/stretchr/testify v1.7.0
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
Expand Down Expand Up @@ -595,6 +597,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"@grafana/data": "8.4.1",
"@grafana/runtime": "8.4.1",
"@grafana/toolkit": "8.4.1",
"@grafana/ui": "8.4.1",
"@types/lodash": "4.14.178"
"@grafana/ui": "8.4.1"
},
"engines": {
"node": ">=16"
Expand All @@ -22,9 +21,9 @@
"start": "docker-compose pull && docker-compose up",
"stop": "docker-compose down",
"test": "grafana-toolkit plugin:test",
"test:backend": "mage cover",
"test:backend": "mage coverage",
"upgrade": "yarn upgrade --latest",
"watch": "grafana-toolkit plugin:dev --watch"
},
"version": "1.0.0"
"version": "1.1.0"
}
8 changes: 3 additions & 5 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func (d *Datasource) query(_ context.Context, settings PluginSettings, query bac
var ids []string
var values []string

log.DefaultLogger.Info("Query called", "filter", settings.Filter)

/**
* Compile regex
*/
Expand Down Expand Up @@ -119,10 +117,10 @@ func (d *Datasource) query(_ context.Context, settings PluginSettings, query bac
* CheckHealth handles health checks sent from Grafana to the plugin
*/
func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
log.DefaultLogger.Info("CheckHealth called", "request", req)
log.DefaultLogger.Debug("CheckHealth called", "request", req)

var status = backend.HealthStatusOk
var message = "Data source is working"
var message = "Data Source is working as expected."

/**
* Create response struct
Expand All @@ -141,7 +139,7 @@ func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
*/
if res.Frames[0].Fields[0].Len() < 1 {
status = backend.HealthStatusError
message = "Can't find any environment variable"
message = "Can't find any environment variable."
}

return &backend.CheckHealthResult{
Expand Down
47 changes: 44 additions & 3 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (

"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-starter-datasource-backend/pkg/plugin"
"github.com/stretchr/testify/require"
)

/**
* Test Query
*/
func TestQueryData(t *testing.T) {
settings := plugin.PluginSettings{
Filter: "",
}
settings := plugin.PluginSettings{}
ds := plugin.Datasource{Settings: &settings}

resp, err := ds.QueryData(
Expand All @@ -34,3 +33,45 @@ func TestQueryData(t *testing.T) {
t.Fatal("QueryData must return a response")
}
}

/**
* Test Health Check
*/
func TestCheckHealth(t *testing.T) {
settings := plugin.PluginSettings{}
ds := plugin.Datasource{Settings: &settings}

resp, err := ds.CheckHealth(
context.Background(),
&backend.CheckHealthRequest{},
)

if err != nil {
t.Error(err)
}

require.NoError(t, err)
require.Equal(t, resp.Status, backend.HealthStatusOk)
}

/**
* Test Health Check with Error
*/
func TestCheckHealthWithError(t *testing.T) {
settings := plugin.PluginSettings{
Filter: "ABC",
}
ds := plugin.Datasource{Settings: &settings}

resp, err := ds.CheckHealth(
context.Background(),
&backend.CheckHealthRequest{},
)

if err != nil {
t.Error(err)
}

require.NoError(t, err)
require.Equal(t, resp.Status, backend.HealthStatusError)
}
2 changes: 2 additions & 0 deletions provisioning/datasources/datasources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ datasources:
orgId: 1
version: 1
editable: true
jsonData:
filter: GF_
Binary file added src/img/grafana-marketplace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 4 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2364,11 +2364,6 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==

"@types/lodash@4.14.178":
version "4.14.178"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==

"@types/mime@^1":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
Expand Down Expand Up @@ -10810,11 +10805,11 @@ rxjs@^6.6.3:
tslib "^1.9.0"

rxjs@^7.2.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.3.0.tgz#39fe4f3461dc1e50be1475b2b85a0a88c1e938c6"
integrity sha512-p2yuGIg9S1epc3vrjKf6iVb3RCaAYjYskkO+jHIaV0IjOPlJop4UnodOoFb2xeNwlguqLYvGw1b1McillYb5Gw==
version "7.5.4"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.4.tgz#3d6bd407e6b7ce9a123e76b1e770dc5761aa368d"
integrity sha512-h5M3Hk78r6wAheJF0a5YahB1yRQKCsZ4MsGdZ5O9ETbVtjPcScGfrMmoOq7EBsCRzd4BDkvDJ7ogP8Sz5tTFiQ==
dependencies:
tslib "~2.1.0"
tslib "^2.1.0"

safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
version "5.2.1"
Expand Down Expand Up @@ -11990,11 +11985,6 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
Expand Down