mirror of
https://github.com/grafana/grafana.git
synced 2026-08-17 08:34:59 -05:00
Merge pull request #12101 from bergquist/devenv
devenv: initial scripts for setting up devenv
This commit is contained in:
@@ -66,3 +66,5 @@ debug.test
|
|||||||
/vendor/**/.editorconfig
|
/vendor/**/.editorconfig
|
||||||
/vendor/**/appengine*
|
/vendor/**/appengine*
|
||||||
*.orig
|
*.orig
|
||||||
|
|
||||||
|
/devenv/dashboards/bulk-testing/*.json
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
This folder contains useful scripts and configuration for...
|
||||||
|
|
||||||
|
* Configuring datasources in Grafana
|
||||||
|
* Provision example dashboards in Grafana
|
||||||
|
* Run preconfiured datasources as docker containers
|
||||||
|
|
||||||
|
want to know more? run setup!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./setup.sh
|
||||||
|
```
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: 1
|
||||||
|
|
||||||
|
providers:
|
||||||
|
- name: 'Bulk dashboards'
|
||||||
|
folder: 'Bulk dashboards'
|
||||||
|
type: file
|
||||||
|
options:
|
||||||
|
path: devenv/dashboards/bulk-testing
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
|||||||
|
apiVersion: 1
|
||||||
|
|
||||||
|
datasources:
|
||||||
|
- name: Graphite
|
||||||
|
type: graphite
|
||||||
|
access: proxy
|
||||||
|
url: http://localhost:8080
|
||||||
|
jsonData:
|
||||||
|
graphiteVersion: "1.1"
|
||||||
|
|
||||||
|
- name: Prometheus
|
||||||
|
type: prometheus
|
||||||
|
access: proxy
|
||||||
|
isDefault: true
|
||||||
|
url: http://localhost:9090
|
||||||
|
|
||||||
|
- name: InfluxDB
|
||||||
|
type: influxdb
|
||||||
|
access: proxy
|
||||||
|
database: site
|
||||||
|
user: grafana
|
||||||
|
password: grafana
|
||||||
|
url: http://localhost:8086
|
||||||
|
jsonData:
|
||||||
|
timeInterval: "15s"
|
||||||
|
|
||||||
|
- name: OpenTsdb
|
||||||
|
type: opentsdb
|
||||||
|
access: proxy
|
||||||
|
url: http://localhost:4242
|
||||||
|
jsonData:
|
||||||
|
tsdbResolution: 1
|
||||||
|
tsdbVersion: 1
|
||||||
|
|
||||||
|
- name: Elastic
|
||||||
|
type: elasticsearch
|
||||||
|
access: proxy
|
||||||
|
database: "[metrics-]YYYY.MM.DD"
|
||||||
|
url: http://localhost:9200
|
||||||
|
jsonData:
|
||||||
|
interval: Daily
|
||||||
|
timeField: "@timestamp"
|
||||||
|
|
||||||
|
- name: MySQL
|
||||||
|
type: mysql
|
||||||
|
url: localhost:3306
|
||||||
|
database: grafana
|
||||||
|
user: grafana
|
||||||
|
password: password
|
||||||
|
|
||||||
|
- name: MSSQL
|
||||||
|
type: mssql
|
||||||
|
url: localhost:1433
|
||||||
|
database: grafana
|
||||||
|
user: grafana
|
||||||
|
password: "Password!"
|
||||||
|
|
||||||
|
- name: Postgres
|
||||||
|
type: postgres
|
||||||
|
url: localhost:5432
|
||||||
|
database: grafana
|
||||||
|
user: grafana
|
||||||
|
password: password
|
||||||
|
jsonData:
|
||||||
|
sslmode: "disable"
|
||||||
|
|
||||||
|
- name: Cloudwatch
|
||||||
|
type: cloudwatch
|
||||||
|
editable: true
|
||||||
|
jsonData:
|
||||||
|
authType: credentials
|
||||||
|
defaultRegion: eu-west-2
|
||||||
|
|
||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#/bin/bash
|
||||||
|
|
||||||
|
bulkDashboard() {
|
||||||
|
|
||||||
|
requiresJsonnet
|
||||||
|
|
||||||
|
COUNTER=0
|
||||||
|
MAX=400
|
||||||
|
while [ $COUNTER -lt $MAX ]; do
|
||||||
|
jsonnet -o "dashboards/bulk-testing/dashboard${COUNTER}.json" -e "local bulkDash = import 'dashboards/bulk-testing/bulkdash.jsonnet'; bulkDash + { uid: 'uid-${COUNTER}', title: 'title-${COUNTER}' }"
|
||||||
|
let COUNTER=COUNTER+1
|
||||||
|
done
|
||||||
|
|
||||||
|
ln -s -f -r ./dashboards/bulk-testing/bulk-dashboards.yaml ../conf/provisioning/dashboards/custom.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
requiresJsonnet() {
|
||||||
|
if ! type "jsonnet" > /dev/null; then
|
||||||
|
echo "you need you install jsonnet to run this script"
|
||||||
|
echo "follow the instructions on https://github.com/google/jsonnet"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultDashboards() {
|
||||||
|
echo "not implemented yet"
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultDatasources() {
|
||||||
|
echo "setting up all default datasources using provisioning"
|
||||||
|
|
||||||
|
ln -s -f -r ./datasources/default/default.yaml ../conf/provisioning/datasources/custom.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo -e "install.sh\n\tThis script installs my basic setup for a debian laptop\n"
|
||||||
|
echo "Usage:"
|
||||||
|
echo " bulk-dashboards - create and provisioning 400 dashboards"
|
||||||
|
echo " default-datasources - provisiong all core datasources"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local cmd=$1
|
||||||
|
|
||||||
|
if [[ -z "$cmd" ]]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $cmd == "bulk-dashboards" ]]; then
|
||||||
|
bulkDashboard
|
||||||
|
elif [[ $cmd == "default-datasources" ]]; then
|
||||||
|
defaultDatasources
|
||||||
|
elif [[ $cmd == "default-dashboards" ]]; then
|
||||||
|
bulkDashboard
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
@@ -47,9 +47,15 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
|
|||||||
log.Error("Cannot read directory", "error", err)
|
log.Error("Cannot read directory", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absPath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Could not create absolute path ", "path", path)
|
||||||
|
absPath = path //if .Abs return an error we fallback to path
|
||||||
|
}
|
||||||
|
|
||||||
return &fileReader{
|
return &fileReader{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Path: path,
|
Path: absPath,
|
||||||
log: log,
|
log: log,
|
||||||
dashboardService: dashboards.NewProvisioningService(),
|
dashboardService: dashboards.NewProvisioningService(),
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -15,14 +15,57 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultDashboards = "./testdata/test-dashboards/folder-one"
|
defaultDashboards = "testdata/test-dashboards/folder-one"
|
||||||
brokenDashboards = "./testdata/test-dashboards/broken-dashboards"
|
brokenDashboards = "testdata/test-dashboards/broken-dashboards"
|
||||||
oneDashboard = "./testdata/test-dashboards/one-dashboard"
|
oneDashboard = "testdata/test-dashboards/one-dashboard"
|
||||||
containingId = "./testdata/test-dashboards/containing-id"
|
containingId = "testdata/test-dashboards/containing-id"
|
||||||
|
|
||||||
fakeService *fakeDashboardProvisioningService
|
fakeService *fakeDashboardProvisioningService
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestCreatingNewDashboardFileReader(t *testing.T) {
|
||||||
|
Convey("creating new dashboard file reader", t, func() {
|
||||||
|
cfg := &DashboardsAsConfig{
|
||||||
|
Name: "Default",
|
||||||
|
Type: "file",
|
||||||
|
OrgId: 1,
|
||||||
|
Folder: "",
|
||||||
|
Options: map[string]interface{}{},
|
||||||
|
}
|
||||||
|
|
||||||
|
Convey("using path parameter", func() {
|
||||||
|
cfg.Options["path"] = defaultDashboards
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(reader.Path, ShouldNotEqual, "")
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("using folder as options", func() {
|
||||||
|
cfg.Options["folder"] = defaultDashboards
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(reader.Path, ShouldNotEqual, "")
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("using full path", func() {
|
||||||
|
cfg.Options["folder"] = "/var/lib/grafana/dashboards"
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(reader.Path, ShouldEqual, "/var/lib/grafana/dashboards")
|
||||||
|
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("using relative path", func() {
|
||||||
|
cfg.Options["folder"] = defaultDashboards
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestDashboardFileReader(t *testing.T) {
|
func TestDashboardFileReader(t *testing.T) {
|
||||||
Convey("Dashboard file reader", t, func() {
|
Convey("Dashboard file reader", t, func() {
|
||||||
bus.ClearBusHandlers()
|
bus.ClearBusHandlers()
|
||||||
@@ -170,30 +213,6 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can use bpth path and folder as dashboard path", func() {
|
|
||||||
cfg := &DashboardsAsConfig{
|
|
||||||
Name: "Default",
|
|
||||||
Type: "file",
|
|
||||||
OrgId: 1,
|
|
||||||
Folder: "",
|
|
||||||
Options: map[string]interface{}{},
|
|
||||||
}
|
|
||||||
|
|
||||||
Convey("using path parameter", func() {
|
|
||||||
cfg.Options["path"] = defaultDashboards
|
|
||||||
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
So(reader.Path, ShouldEqual, defaultDashboards)
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("using folder as options", func() {
|
|
||||||
cfg.Options["folder"] = defaultDashboards
|
|
||||||
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
So(reader.Path, ShouldEqual, defaultDashboards)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
dashboards.NewProvisioningService = origNewDashboardProvisioningService
|
dashboards.NewProvisioningService = origNewDashboardProvisioningService
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ import (
|
|||||||
var (
|
var (
|
||||||
logger log.Logger = log.New("fake.log")
|
logger log.Logger = log.New("fake.log")
|
||||||
|
|
||||||
twoDatasourcesConfig = "./test-configs/two-datasources"
|
twoDatasourcesConfig = "testdata/two-datasources"
|
||||||
twoDatasourcesConfigPurgeOthers = "./test-configs/insert-two-delete-two"
|
twoDatasourcesConfigPurgeOthers = "testdata/insert-two-delete-two"
|
||||||
doubleDatasourcesConfig = "./test-configs/double-default"
|
doubleDatasourcesConfig = "testdata/double-default"
|
||||||
allProperties = "./test-configs/all-properties"
|
allProperties = "testdata/all-properties"
|
||||||
versionZero = "./test-configs/version-0"
|
versionZero = "testdata/version-0"
|
||||||
brokenYaml = "./test-configs/broken-yaml"
|
brokenYaml = "testdata/broken-yaml"
|
||||||
|
|
||||||
fakeRepo *fakeRepository
|
fakeRepo *fakeRepository
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user