Skip to content

Commit 51a8bb5

Browse files
Clickhouse add multicluster support for K8s (#1080)
* add multicluster support * correct datasource * remove comment * update refresh value * remove filename from selector
1 parent 0d94f19 commit 51a8bb5

File tree

5 files changed

+203
-269
lines changed

5 files changed

+203
-269
lines changed

clickhouse-mixin/.lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exclusions:
1212
- panel: "Zookeeper watches"
1313
- panel: "Zookeeper sessions"
1414
- panel: "Zookeeper requests"
15+
- panel: "Active connections"
1516
template-datasource-rule:
1617
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
1718
template-instance-rule:

clickhouse-mixin/config.libsonnet

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
_config+:: {
3+
enableMultiCluster: false,
4+
clickhouseSelector: if self.enableMultiCluster then 'job=~"$job", instance=~"$instance", cluster=~"$cluster"' else 'job=~"$job", instance=~"$instance"',
5+
36
dashboardTags: ['clickhouse-mixin'],
47
dashboardPeriod: 'now-30m',
58
dashboardTimezone: 'default',
69
dashboardRefresh: '1m',
10+
logExpression: if self.enableMultiCluster then '{job=~"$job", instance=~"$instance", cluster=~"$cluster"}'
11+
else '{job=~"$job", instance=~"$instance"}',
712

813
// for alerts
914
alertsReplicasMaxQueueSize: '99',

clickhouse-mixin/dashboards/clickhouse-latency.libsonnet

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ local grafana = (import 'grafonnet/grafana.libsonnet');
33
local dashboard = grafana.dashboard;
44
local template = grafana.template;
55
local dashboardUid = 'clickhouse-latency';
6-
local matcher = 'job=~"$job", instance=~"$instance"';
6+
local promDatasourceName = 'prometheus_datasource';
7+
local getMatcher(cfg) = '%(clickhouseSelector)s' % cfg;
78

8-
local diskReadLatencyPanel =
9+
local promDatasource = {
10+
uid: '${%s}' % promDatasourceName,
11+
};
12+
13+
local diskReadLatencyPanel(matcher) =
914
{
10-
datasource: {
11-
type: 'prometheus',
12-
uid: '${prometheus_datasource}',
13-
},
15+
datasource: promDatasource,
1416
description: 'Time spent waiting for read syscall',
1517
fieldConfig: {
1618
defaults: {
@@ -79,10 +81,7 @@ local diskReadLatencyPanel =
7981
},
8082
targets: [
8183
{
82-
datasource: {
83-
type: 'prometheus',
84-
uid: '${prometheus_datasource}',
85-
},
84+
datasource: promDatasource,
8685
editorMode: 'builder',
8786
expr: 'increase(ClickHouseProfileEvents_DiskReadElapsedMicroseconds{' + matcher + '}[$__rate_interval])',
8887
legendFormat: 'Disk read elapsed',
@@ -94,12 +93,9 @@ local diskReadLatencyPanel =
9493
type: 'timeseries',
9594
};
9695

97-
local diskWriteLatencyPanel =
96+
local diskWriteLatencyPanel(matcher) =
9897
{
99-
datasource: {
100-
type: 'prometheus',
101-
uid: '${prometheus_datasource}',
102-
},
98+
datasource: promDatasource,
10399
description: 'Time spent waiting for write syscall',
104100
fieldConfig: {
105101
defaults: {
@@ -168,10 +164,7 @@ local diskWriteLatencyPanel =
168164
},
169165
targets: [
170166
{
171-
datasource: {
172-
type: 'prometheus',
173-
uid: '${prometheus_datasource}',
174-
},
167+
datasource: promDatasource,
175168
editorMode: 'builder',
176169
expr: 'increase(ClickHouseProfileEvents_DiskWriteElapsedMicroseconds{' + matcher + '}[$__rate_interval])',
177170
legendFormat: 'Disk write elapsed',
@@ -183,12 +176,9 @@ local diskWriteLatencyPanel =
183176
type: 'timeseries',
184177
};
185178

186-
local networkTransmitLatencyPanel =
179+
local networkTransmitLatencyPanel(matcher) =
187180
{
188-
datasource: {
189-
type: 'prometheus',
190-
uid: '${prometheus_datasource}',
191-
},
181+
datasource: promDatasource,
192182
description: 'Latency of inbound network traffic',
193183
fieldConfig: {
194184
defaults: {
@@ -257,10 +247,7 @@ local networkTransmitLatencyPanel =
257247
},
258248
targets: [
259249
{
260-
datasource: {
261-
type: 'prometheus',
262-
uid: '${prometheus_datasource}',
263-
},
250+
datasource: promDatasource,
264251
editorMode: 'builder',
265252
expr: 'increase(ClickHouseProfileEvents_NetworkReceiveElapsedMicroseconds{' + matcher + '}[$__rate_interval])',
266253
legendFormat: 'Network receive elapsed',
@@ -272,12 +259,9 @@ local networkTransmitLatencyPanel =
272259
type: 'timeseries',
273260
};
274261

275-
local networkTransmitLatencyPanel =
262+
local networkTransmitLatencyPanel(matcher) =
276263
{
277-
datasource: {
278-
type: 'prometheus',
279-
uid: '${prometheus_datasource}',
280-
},
264+
datasource: promDatasource,
281265
description: 'Latency of outbound network traffic',
282266
fieldConfig: {
283267
defaults: {
@@ -346,10 +330,7 @@ local networkTransmitLatencyPanel =
346330
},
347331
targets: [
348332
{
349-
datasource: {
350-
type: 'prometheus',
351-
uid: '${prometheus_datasource}',
352-
},
333+
datasource: promDatasource,
353334
editorMode: 'builder',
354335
expr: 'increase(ClickHouseProfileEvents_NetworkSendElapsedMicroseconds{' + matcher + '}[$__rate_interval])',
355336
legendFormat: 'Network send elapsed',
@@ -361,12 +342,9 @@ local networkTransmitLatencyPanel =
361342
type: 'timeseries',
362343
};
363344

364-
local zooKeeperWaitTimePanel =
345+
local zooKeeperWaitTimePanel(matcher) =
365346
{
366-
datasource: {
367-
type: 'prometheus',
368-
uid: '${prometheus_datasource}',
369-
},
347+
datasource: promDatasource,
370348
description: 'Time spent waiting for ZooKeeper request to process',
371349
fieldConfig: {
372350
defaults: {
@@ -435,10 +413,7 @@ local zooKeeperWaitTimePanel =
435413
},
436414
targets: [
437415
{
438-
datasource: {
439-
type: 'prometheus',
440-
uid: '${prometheus_datasource}',
441-
},
416+
datasource: promDatasource,
442417
editorMode: 'builder',
443418
expr: 'increase(ClickHouseProfileEvents_ZooKeeperWaitMicroseconds{' + matcher + '}[$__rate_interval])',
444419
legendFormat: 'ZooKeeper wait',
@@ -471,19 +446,17 @@ local zooKeeperWaitTimePanel =
471446
tags=($._config.dashboardTags),
472447
)).addTemplates(
473448
[
474-
{
475-
hide: 0,
476-
label: 'Data source',
477-
name: 'prometheus_datasource',
478-
query: 'prometheus',
479-
refresh: 1,
480-
regex: '',
481-
type: 'datasource',
482-
},
449+
template.datasource(
450+
promDatasourceName,
451+
'prometheus',
452+
null,
453+
label='Data source',
454+
refresh='load'
455+
),
483456
template.new(
484457
name='job',
485458
label='job',
486-
datasource='$prometheus_datasource',
459+
datasource=promDatasource,
487460
query='label_values(ClickHouseProfileEvents_DiskReadElapsedMicroseconds,job)',
488461
current='',
489462
refresh=2,
@@ -495,29 +468,41 @@ local zooKeeperWaitTimePanel =
495468
template.new(
496469
name='instance',
497470
label='instance',
498-
datasource='$prometheus_datasource',
471+
datasource=promDatasource,
499472
query='label_values(ClickHouseProfileEvents_DiskReadElapsedMicroseconds{job=~"$job"}, instance)',
500473
current='',
501474
refresh=2,
502475
includeAll=false,
503476
sort=1
504477
),
478+
template.new(
479+
'cluster',
480+
promDatasource,
481+
'label_values(ClickHouseProfileEvents_DiskReadElapsedMicroseconds{job=~"$job"}, cluster)',
482+
label='Cluster',
483+
refresh=2,
484+
includeAll=true,
485+
multi=true,
486+
allValues='',
487+
hide=if $._config.enableMultiCluster then '' else 'variable',
488+
sort=0
489+
),
505490
]
506491
)
507492
.addPanels(
508493
std.flattenArrays([
509494
[
510-
diskReadLatencyPanel { gridPos: { h: 8, w: 12, x: 0, y: 0 } },
511-
diskWriteLatencyPanel { gridPos: { h: 8, w: 12, x: 12, y: 0 } },
495+
diskReadLatencyPanel(getMatcher($._config)) { gridPos: { h: 8, w: 12, x: 0, y: 0 } },
496+
diskWriteLatencyPanel(getMatcher($._config)) { gridPos: { h: 8, w: 12, x: 12, y: 0 } },
512497
],
513498
//next row
514499
[
515-
networkTransmitLatencyPanel { gridPos: { h: 8, w: 12, x: 0, y: 8 } },
516-
networkTransmitLatencyPanel { gridPos: { h: 8, w: 12, x: 12, y: 8 } },
500+
networkTransmitLatencyPanel(getMatcher($._config)) { gridPos: { h: 8, w: 12, x: 0, y: 8 } },
501+
networkTransmitLatencyPanel(getMatcher($._config)) { gridPos: { h: 8, w: 12, x: 12, y: 8 } },
517502
],
518503
//next row
519504
[
520-
zooKeeperWaitTimePanel { gridPos: { h: 8, w: 24, x: 0, y: 16 } },
505+
zooKeeperWaitTimePanel(getMatcher($._config)) { gridPos: { h: 8, w: 24, x: 0, y: 16 } },
521506
],
522507
])
523508
),

0 commit comments

Comments
 (0)