Skip to content

Commit 7eb4193

Browse files
committed
Modernize squid-mixin to grafonnet v11 and signals architecture
1 parent 54a1543 commit 7eb4193

19 files changed

+1229
-2688
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
vendor
33
jsonnetfile.lock.json
44
*.zip
5+
.worktrees

squid-mixin/.lint

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
exclusions:
2+
template-job-rule:
3+
reason: "Prometheus datasource variable is being named as prometheus_datasource now while linter expects 'datasource'"
4+
panel-datasource-rule:
5+
reason: "Modern mixins use signal-based architecture where datasource references are handled by the framework"
6+
template-datasource-rule:
7+
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
8+
template-instance-rule:
9+
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
210
panel-units-rule:
311
reason: "Custom units are used for better user experience in these panels"
412
entries:
513
- panel: "Client request errors"
614
- panel: "Server request errors"
7-
template-datasource-rule:
8-
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
9-
template-instance-rule:
10-
reason: "Based on new convention we are using variable names prometheus_datasource and loki_datasource where as linter expects 'datasource'"
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
prometheusAlerts+:: {
3-
groups+: [
2+
new(this): {
3+
groups: [
44
{
5-
name: 'squid',
5+
name: this.config.uid + '-alerts',
66
rules: [
77
{
8-
alert: 'SquidHighPercentageOfHTTPServerRequestErrors',
8+
alert: 'SquidHighHTTPServerRequestErrors',
99
expr: |||
1010
rate(squid_server_http_errors_total[5m]) / clamp_min(rate(squid_server_http_requests_total[5m]),1) * 100 > %(alertsCriticalHighPercentageRequestErrors)s
11-
||| % $._config,
11+
||| % this.config,
1212
'for': '5m',
1313
labels: {
1414
severity: 'critical',
@@ -17,14 +17,14 @@
1717
summary: 'There are a high number of HTTP server errors.',
1818
description: |||
1919
The percentage of HTTP server request errors is {{ printf "%%.0f" $value }} over the last 5m on {{ $labels.instance }} which is above the threshold of %(alertsCriticalHighPercentageRequestErrors)s.
20-
||| % $._config,
20+
||| % this.config,
2121
},
2222
},
2323
{
24-
alert: 'SquidHighPercentageOfFTPServerRequestErrors',
24+
alert: 'SquidHighFTPServerRequestErrors',
2525
expr: |||
2626
rate(squid_server_ftp_errors_total[5m]) / clamp_min(rate(squid_server_ftp_requests_total[5m]),1) * 100 > %(alertsCriticalHighPercentageRequestErrors)s
27-
||| % $._config,
27+
||| % this.config,
2828
'for': '5m',
2929
labels: {
3030
severity: 'critical',
@@ -33,14 +33,14 @@
3333
summary: 'There are a high number of FTP server request errors.',
3434
description: |||
3535
The percentage of FTP server request errors is {{ printf "%%.0f" $value }} over the last 5m on {{ $labels.instance }} which is above the threshold of %(alertsCriticalHighPercentageRequestErrors)s.
36-
||| % $._config,
36+
||| % this.config,
3737
},
3838
},
3939
{
40-
alert: 'SquidHighPercentageOfOtherServerRequestErrors',
40+
alert: 'SquidHighOtherServerRequestErrors',
4141
expr: |||
4242
rate(squid_server_other_errors_total[5m]) / clamp_min(rate(squid_server_other_requests_total[5m]),1) * 100 > %(alertsCriticalHighPercentageRequestErrors)s
43-
||| % $._config,
43+
||| % this.config,
4444
'for': '5m',
4545
labels: {
4646
severity: 'critical',
@@ -49,14 +49,14 @@
4949
summary: 'There are a high number of other server request errors.',
5050
description: |||
5151
The percentage of other server request errors is {{ printf "%%.0f" $value }} over the last 5m on {{ $labels.instance }} which is above the threshold of %(alertsCriticalHighPercentageRequestErrors)s.
52-
||| % $._config,
52+
||| % this.config,
5353
},
5454
},
5555
{
56-
alert: 'SquidHighPercentageOfClientRequestErrors',
56+
alert: 'SquidHighClientRequestErrors',
5757
expr: |||
5858
rate(squid_client_http_errors_total[5m]) / clamp_min(rate(squid_client_http_requests_total[5m]),1) * 100 > %(alertsCriticalHighPercentageRequestErrors)s
59-
||| % $._config,
59+
||| % this.config,
6060
'for': '5m',
6161
labels: {
6262
severity: 'critical',
@@ -65,14 +65,14 @@
6565
summary: 'There are a high number of HTTP client request errors.',
6666
description: |||
6767
The percentage of HTTP client request errors is {{ printf "%%.0f" $value }} over the last 5m on {{ $labels.instance }} which is above the threshold of %(alertsCriticalHighPercentageRequestErrors)s.
68-
||| % $._config,
68+
||| % this.config,
6969
},
7070
},
7171
{
7272
alert: 'SquidLowCacheHitRatio',
7373
expr: |||
7474
rate(squid_client_http_hits_total[10m]) / clamp_min(rate(squid_client_http_requests_total[10m]),1) * 100 < %(alertsWarningLowCacheHitRatio)s
75-
||| % $._config,
75+
||| % this.config,
7676
'for': '10m',
7777
labels: {
7878
severity: 'warning',
@@ -81,7 +81,7 @@
8181
summary: 'The cache hit ratio has fallen below the configured threshold (%).',
8282
description: |||
8383
The cache hit ratio is {{ printf "%%.0f" $value }} over the last 10m on {{ $labels.instance }} which is below the threshold of %(alertsWarningLowCacheHitRatio)s.
84-
||| % $._config,
84+
||| % this.config,
8585
},
8686
},
8787
],

squid-mixin/config.libsonnet

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
{
2-
_config+:: {
3-
dashboardTags: ['squid'],
4-
dashboardPeriod: 'now-1h',
5-
dashboardTimezone: 'default',
6-
dashboardRefresh: '1m',
2+
local this = self,
73

8-
// alerts thresholds
9-
alertsCriticalHighPercentageRequestErrors: 5,
10-
alertsWarningLowCacheHitRatio: 85,
11-
enableLokiLogs: true,
12-
enableMultiCluster: false,
13-
multiclusterSelector: 'job=~"$job"',
14-
squidSelector: if self.enableMultiCluster then 'job=~"$job", cluster=~"$cluster"' else 'job=~"$job"',
4+
// Basic filtering
5+
filteringSelector: 'job=~"$job", instance=~"$instance"',
6+
groupLabels: ['job'],
7+
instanceLabels: ['instance'],
8+
9+
// Dashboard settings
10+
dashboardTags: ['squid'],
11+
dashboardPeriod: 'now-1h',
12+
dashboardTimezone: 'default',
13+
dashboardRefresh: '1m',
14+
uid: 'squid',
15+
dashboardNamePrefix: 'Squid',
16+
17+
// Logs configuration
18+
enableLokiLogs: true,
19+
logLabels: ['job', 'instance', 'filename'],
20+
extraLogLabels: [],
21+
logsVolumeGroupBy: 'level',
22+
showLogsVolume: true,
23+
24+
// Multi-cluster support
25+
enableMultiCluster: false,
26+
multiclusterSelector: if self.enableMultiCluster then 'job=~"$job", cluster=~"$cluster"' else 'job=~"$job"',
27+
28+
// Alert thresholds
29+
alertsCriticalHighPercentageRequestErrors: 5, // %
30+
alertsWarningLowCacheHitRatio: 85, // %
31+
32+
// Metrics source
33+
metricsSource: 'prometheus',
34+
35+
// Signal definitions
36+
signals: {
37+
client: (import './signals/client.libsonnet')(this),
38+
server: (import './signals/server.libsonnet')(this),
39+
serviceTime: (import './signals/service_time.libsonnet')(this),
1540
},
1641
}

squid-mixin/dashboards.libsonnet

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
local g = import './g.libsonnet';
2+
local commonlib = import 'common-lib/common/main.libsonnet';
3+
4+
{
5+
local root = self,
6+
new(this):
7+
local prefix = this.config.dashboardNamePrefix;
8+
local links = this.grafana.links;
9+
local tags = this.config.dashboardTags;
10+
local uid = this.config.uid;
11+
local vars = commonlib.variables.new(
12+
filteringSelector=this.config.filteringSelector,
13+
groupLabels=this.config.groupLabels,
14+
instanceLabels=this.config.instanceLabels,
15+
varMetric='squid_server_http_requests_total',
16+
customAllValue='.+',
17+
enableLokiLogs=this.config.enableLokiLogs,
18+
);
19+
local annotations = {};
20+
local refresh = this.config.dashboardRefresh;
21+
local period = this.config.dashboardPeriod;
22+
local timezone = this.config.dashboardTimezone;
23+
24+
{
25+
'squid-overview.json':
26+
g.dashboard.new(prefix + ' overview')
27+
+ g.dashboard.withDescription('')
28+
+ g.dashboard.withPanels(
29+
g.util.panel.resolveCollapsedFlagOnRows(
30+
g.util.grid.wrapPanels(
31+
[
32+
this.grafana.rows.clientRow,
33+
this.grafana.rows.serverRow,
34+
]
35+
+
36+
if this.config.enableLokiLogs then
37+
[this.grafana.rows.logsRow]
38+
else
39+
[]
40+
)
41+
)
42+
)
43+
+ root.applyCommon(
44+
vars.multiInstance,
45+
uid + '-overview',
46+
tags,
47+
links,
48+
annotations,
49+
timezone,
50+
refresh,
51+
period
52+
),
53+
},
54+
55+
applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period):
56+
g.dashboard.withTags(tags)
57+
+ g.dashboard.withUid(uid)
58+
+ g.dashboard.withLinks([links[key].asDashboardLink() for key in std.objectFields(links)])
59+
+ g.dashboard.withTimezone(timezone)
60+
+ g.dashboard.withRefresh(refresh)
61+
+ g.dashboard.time.withFrom(period)
62+
+ g.dashboard.withVariables(vars)
63+
+ g.dashboard.withAnnotations(std.objectValues(annotations)),
64+
}

squid-mixin/dashboards/dashboards.libsonnet

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)