Skip to content

Commit 1981309

Browse files
authored
Merge pull request #17 from basicrum/simplified-local-setup
Simplified local setup
2 parents b4816a8 + 6092a5b commit 1981309

File tree

17 files changed

+92
-9367
lines changed

17 files changed

+92
-9367
lines changed

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ RUN find /usr/share/grafana/public/build/ -name *.js -exec sed -i 's|..createEle
3838

3939
RUN /bin/bash -c 'grafana cli plugins install ae3e-plotly-panel 0.5.0'
4040
RUN /bin/bash -c 'grafana cli plugins install vertamedia-clickhouse-datasource 2.5.1'
41-
RUN /bin/bash -c 'grafana cli plugins install volkovlabs-form-panel 3.2.1'
4241

4342
## Set Home Dashboard
4443
ENV GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/General.json
4544

4645
# Adding datasources
47-
ADD templates/datasources /etc/grafana/provisioning/datasources
46+
ADD templates/datasources/default.yaml /etc/grafana/provisioning/datasources/default.yaml
4847

4948
# Adding dashboards yaml
50-
ADD templates/dashboards /etc/grafana/provisioning/dashboards
49+
ADD templates/dashboards/General.yaml /etc/grafana/provisioning/dashboards/General.yaml
5150

5251
# Adding dashboards
5352
ADD build/dashboards /etc/grafana/provisioning/dashboards
5453

55-
# Replace grafana.ini
56-
ADD grafana/grafana.ini /etc/grafana/grafana.ini

Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ SHELL=bash
55
UID := $(shell id -u)
66

77
dc_path=./docker-compose.yaml
8-
dc_path_quick_test=./docker-compose.quick-test.yaml
98
clickhouse_container=basicrum_clickhouse_server_build
10-
grafana_container=basicrum_grafana
9+
grafana_container=basicrum_grafana_build
1110

1211
help:
1312
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -19,14 +18,6 @@ up: ## Starts the environment
1918
down: ## Stops the environment
2019
env UID=${UID} docker-compose -f ${dc_path} down
2120

22-
23-
up_quick_test: ## Starts quick test environment
24-
env UID=${UID} docker-compose -f ${dc_path_quick_test} build
25-
env UID=${UID} docker-compose -f ${dc_path_quick_test} up
26-
27-
down_quick_test: ## Stops quick test environment
28-
env UID=${UID} docker-compose -f ${dc_path_quick_test} down
29-
3021
restart: down up # Restart the environment
3122

3223
rebuild: ## Rebuilds the environment from scratch

build.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var fs = require('fs');
1+
var fs = require("fs");
22

3-
const DashboardBuilder = require('./lib/DashboardBuilder');
3+
const DashboardBuilder = require("./lib/DashboardBuilder");
4+
const { exit } = require("process");
45
const builder = new DashboardBuilder()
56

67
const options = {
@@ -9,17 +10,52 @@ const options = {
910
filterMap: {},
1011
}
1112

12-
var dir = './build';
13-
if (!fs.existsSync(dir)){
14-
fs.mkdirSync(dir);
13+
const buildDir = "./build";
14+
15+
try {
16+
if(fs.existsSync(buildDir)) {
17+
fs.rmSync(buildDir, { recursive: true, force: true });
18+
console.log("Removed the build folder.");
19+
}
20+
} catch(e) {
21+
console.error(e);
22+
exit(1);
23+
}
24+
25+
if (!fs.existsSync(buildDir)){
26+
fs.mkdirSync(buildDir);
27+
console.log("Created build folder.");
28+
}
29+
30+
const dashboardsDir = "./build/dashboards";
31+
if (!fs.existsSync(dashboardsDir)){
32+
fs.mkdirSync(dashboardsDir);
33+
console.log("Created build/dashboards folder.");
34+
}
35+
36+
const datasourcesDir = "./build/datasources";
37+
if (!fs.existsSync(datasourcesDir)){
38+
fs.mkdirSync(datasourcesDir);
39+
console.log("Created build/datasources folder.");
40+
}
41+
42+
try {
43+
fs.copyFileSync("./templates/dashboards/General.yaml", "./build/dashboards/General.yaml");
44+
console.log("Added build/dashboards/General.yaml");
45+
} catch(e) {
46+
console.error(e);
47+
exit(1);
1548
}
1649

17-
dir = './build/dashboards';
18-
if (!fs.existsSync(dir)){
19-
fs.mkdirSync(dir);
50+
try {
51+
fs.copyFileSync("./templates/datasources/default.yaml", "./build/datasources/default.yaml");
52+
console.log("Added build/datasources/default.yaml");
53+
} catch(e) {
54+
console.error(e);
55+
exit(1);
2056
}
2157

22-
const dashboards = ['General', 'Metrics', 'Summary'];
58+
const dashboards = ["General", "Metrics", "Summary"];
2359

2460
var summaryList = [];
2561
for (const dashboard of dashboards) {

build.test.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
const fs = require('fs');
2-
const DashboardBuilder = require('./lib/DashboardBuilder');
1+
const fs = require("fs");
2+
const DashboardBuilder = require("./lib/DashboardBuilder");
33
const builder = new DashboardBuilder()
44

5-
function runTest(dashboard) {
5+
function getDashboard(dashboard) {
66
const options = {
77
table: "basicrum_friends_webperf_rum_events",
88
datasourceUid: "A0Wl5Mc4z",
99
filterMap: {
1010
"hosts":"testHosts",
1111
},
1212
}
13-
13+
1414
builder.build(dashboard, options);
1515

16-
const expected = JSON.parse(fs.readFileSync(`./testdata/dashboards/${dashboard}.json`, { encoding: 'utf8', flag: 'r' }));
17-
const actual = JSON.parse(fs.readFileSync(`./build/dashboards/${dashboard}.json`, { encoding: 'utf8', flag: 'r' }));
18-
expect(actual).toMatchObject(expected);
16+
return JSON.parse(fs.readFileSync(`./build/dashboards/${dashboard}.json`, { encoding: "utf8", flag: "r" }));
1917
}
2018

21-
test('build General dashboard should be as expected', () => {
22-
runTest('General')
19+
test("Test General dashboard should be as expected", () => {
20+
const generalDashboard = getDashboard("General");
21+
22+
expect(34).toBe(generalDashboard.panels.length);
2323
});
2424

25-
test('build Metrics dashboard should be as expected', () => {
26-
runTest('Metrics')
25+
test("Test Metrics dashboard should be as expected", () => {
26+
const metricsDashboard = getDashboard("Metrics");
27+
28+
expect(4).toBe(metricsDashboard.panels.length);
2729
});
2830

29-
test('build Summary dashboard should be as expected', () => {
30-
runTest('Summary')
31+
test("Test Summary dashboard should be as expected", () => {
32+
const summaryDashboard = getDashboard("Summary");
33+
34+
expect(14).toBe(summaryDashboard.panels.length);
3135
});

default.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

docker-compose.quick-test.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

docker-compose.standalone.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

docker-compose.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ services:
44
basicrum_grafana_build:
55
build: .
66
ports:
7-
- 3200:3000
7+
- 3300:3000
88
env_file:
99
- .env
1010
volumes:
11-
# Mount provisioning related stuff
1211
- ./build/datasources:/etc/grafana/provisioning/datasources
1312
- ./build/dashboards:/etc/grafana/provisioning/dashboards
1413

1514
basicrum_clickhouse_server_build:
1615
image: clickhouse/clickhouse-server:22.8
16+
env_file:
17+
- .env
1718
volumes:
1819
- ./clickhouse/data:/var/lib/clickhouse
19-
- ./clickhouse/users.d/:/etc/clickhouse-server/users.d/
20-
- ./init-schema/:/docker-entrypoint-initdb.d/
20+
- ./setup/ch/users.d:/etc/clickhouse-server/users.d
21+
- ./setup/ch/init-schema:/docker-entrypoint-initdb.d
2122

2223
ulimits:
2324
nproc: 65535

init-schema/2.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)