-
Notifications
You must be signed in to change notification settings - Fork 160
/
alerts.libsonnet
197 lines (195 loc) · 9.31 KB
/
alerts.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';
{
new(this): {
local instanceLabel = xtd.array.slice(this.config.instanceLabels, -1)[0],
local groupLabel = xtd.array.slice(this.config.groupLabels, -1)[0],
groups+: [
{
name: this.config.uid + '-kafka-alerts',
rules:
[
{
alert: 'KafkaLagKeepsIncreasing',
expr: 'sum by (%s, topic, consumergroup) (%s) > 0' %
[
std.join(',', this.config.groupLabels),
// split back combined string to wrap in delta, then join back:
std.join(
'\nor\n',
std.map(
function(x) 'delta(%s[5m])' % x,
std.split(this.signals.consumerGroup.consumerGroupLag.asRuleExpression(), '\nor\n')
)
),
],
'for': '15m',
keep_firing_for: '10m',
labels: {
severity: 'warning',
},
annotations: {
summary: 'Kafka lag keeps increasing.',
description: 'Kafka lag keeps increasing over the last 15 minutes for consumer group: {{$labels.consumergroup}}, topic: {{$labels.topic}}.',
},
},
{
alert: 'KafkaLagIsTooHigh',
expr: 'sum by (%s, topic, consumergroup) (%s) > %s' %
[
std.join(',', this.config.groupLabels),
this.signals.consumerGroup.consumerGroupLag.asRuleExpression(),
this.config.alertKafkaLagTooHighThreshold,
],
'for': '15m',
keep_firing_for: '5m',
labels: {
severity: this.config.alertKafkaLagTooHighSeverity,
},
annotations: {
summary: 'Kafka lag is too high.',
description: 'Total kafka lag across all partitions is too high ({{ printf "%.0f" $value }}) for consumer group: {{$labels.consumergroup}}, topic: {{$labels.topic}}.',
},
},
{
alert: 'KafkaISRExpandRate',
expr: |||
sum by (%s) (%s) != 0
||| % [
std.join(',', this.config.groupLabels + this.config.instanceLabels),
this.signals.brokerReplicaManager.isrExpands.asRuleExpression(),
],
'for': '5m',
keep_firing_for: '15m',
labels: {
severity: 'warning',
},
annotations: {
summary: 'Kafka ISR expansion rate is expanding.',
description: 'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} In-Sync Replica (ISR) is expanding by {{ $value }} per second. If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR expansion rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'
% [
instanceLabel,
groupLabel,
],
},
},
{
alert: 'KafkaISRShrinkRate',
expr: |||
sum by (%s) (%s) != 0
||| % [
std.join(',', this.config.groupLabels + this.config.instanceLabels),
this.signals.brokerReplicaManager.isrShrinks.asRuleExpression(),
],
'for': '5m',
keep_firing_for: '15m',
labels: {
severity: 'warning',
},
annotations: {
summary: 'Kafka ISR expansion rate is shrinking.',
description: 'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} In-Sync Replica (ISR) is shrinking by {{ $value }} per second. If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR shrink rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'
% [
instanceLabel,
groupLabel,
],
},
},
{
alert: 'KafkaOfflinePartitonCount',
expr: |||
sum by (%s) (%s) > 0
||| % [
std.join(',', this.config.groupLabels),
this.signals.brokerReplicaManager.offlinePartitions.asRuleExpression(),
],
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka has offline partitons.',
description: 'Kafka cluster {{ $labels.%s }} has {{ $value }} offline partitions. After successful leader election, if the leader for partition dies, then the partition moves to the OfflinePartition state. Offline partitions are not available for reading and writing. Restart the brokers, if needed, and check the logs for errors.'
% groupLabel,
},
},
{
alert: 'KafkaUnderReplicatedPartitionCount',
expr: |||
sum by (%s) (%s) > 0
||| % [
std.join(',', this.config.groupLabels + this.config.instanceLabels),
this.signals.brokerReplicaManager.underReplicatedPartitions.asRuleExpression(),
],
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka has under replicated partitons.',
description: 'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} has {{ $value }} under replicated partitons'
% [
instanceLabel,
groupLabel,
],
},
},
{
alert: 'KafkaNoActiveController',
expr: 'sum by(' + std.join(',', this.config.groupLabels) + ') (' + this.signals.cluster.activeControllers.asRuleExpression() + ') != 1',
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka has no active controller.',
description: 'Kafka cluster {{ $labels.%s }} has {{ $value }} broker(s) reporting as the active controller in the last 5 minute interval. During steady state there should be only one active controller per cluster.'
% groupLabel,
},
},
{
alert: 'KafkaUncleanLeaderElection',
expr: '(%s) != 0' % this.signals.brokerReplicaManager.uncleanLeaderElection.asRuleExpression(),
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka has unclean leader elections.',
description: 'Kafka cluster {{ $labels.%s }} has {{ $value }} unclean partition leader elections reported in the last 5 minute interval. When unclean leader election is held among out-of-sync replicas, there is a possibility of data loss if any messages were not synced prior to the loss of the former leader. So if the number of unclean elections is greater than 0, investigate broker logs to determine why leaders were re-elected, and look for WARN or ERROR messages. Consider setting the broker configuration parameter unclean.leader.election.enable to false so that a replica outside of the set of in-sync replicas is never elected leader.'
% groupLabel,
},
},
{
alert: 'KafkaBrokerCount',
expr: 'count by(' + std.join(',', this.config.groupLabels) + ') (' + this.signals.cluster.brokersCount.asRuleExpression() + ') == 0',
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka has no brokers online.',
description: 'Kafka cluster {{ $labels.%s }} broker count is 0.' % groupLabel,
},
},
{
alert: 'KafkaZookeeperSyncConnect',
expr: 'avg by(' + std.join(',', this.config.groupLabels + this.config.instanceLabels) + ') (' + this.signals.zookeeperClient.zookeeperConnections.asRuleExpression() + ') < 0',
'for': '5m',
labels: {
severity: 'critical',
},
annotations: {
summary: 'Kafka Zookeeper sync disconected.',
description:
'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} has disconected from Zookeeper.'
% [
instanceLabel,
groupLabel,
],
},
},
],
},
],
},
}