Skip to content

Commit

Permalink
Fix kafka alerts (#1320)
Browse files Browse the repository at this point in the history
* Fix kafka alerts
to support combined signals

* Fix label

* Fix typo
  • Loading branch information
v-zhuravlev authored Aug 29, 2024
1 parent d7f91f1 commit 1132fd7
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions kafka-observ-lib/alerts.libsonnet
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
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.instanceLabels, -1)[0],
groups+: [
{
name: this.config.uid + '-kafka-alerts',
rules:
[
{
alert: 'KafkaLagKeepsIncreasing',
expr: 'sum without (partition) (delta(%s[5m]) > 0)' %
[
this.signals.consumerGroup.consumerGroupLag.asRuleExpression(),
],
expr: 'sum without (partition) (%s) > 0' %
// 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: {
Expand Down Expand Up @@ -52,8 +61,8 @@
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.'
% [
this.config.instanceLabels[0],
this.config.groupLabels[0],
instanceLabel,
groupLabel,
],
},
},
Expand All @@ -71,10 +80,9 @@
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.'
% [
this.config.instanceLabels[0],
this.config.groupLabels[0],
instanceLabel,
groupLabel,
],

},
},
{
Expand All @@ -91,13 +99,13 @@
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.'
% this.config.groupLabels[0],
% groupLabel,
},
},
{
alert: 'KafkaUnderReplicatedPartitionCount',
expr: |||
%s > 0
(%s) > 0
||| % [
this.signals.replicaManager.underReplicatedPartitions.asRuleExpression(),
],
Expand All @@ -109,8 +117,8 @@
summary: 'Kafka has under replicated partitons.',
description: 'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} has {{ $value }} under replicated partitons'
% [
this.config.instanceLabels[0],
this.config.groupLabels[0],
instanceLabel,
groupLabel,
],
},
},
Expand All @@ -124,20 +132,20 @@
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.'
% this.config.groupLabels[0],
% groupLabel,
},
},
{
alert: 'KafkaUncleanLeaderElection',
expr: this.signals.replicaManager.uncleanLeaderElection.asRuleExpression() + ' != 0',
expr: '(%s) != 0' % this.signals.replicaManager.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.'
% this.config.groupLabels[0],
% groupLabel,
},
},
{
Expand All @@ -149,7 +157,7 @@
},
annotations: {
summary: 'Kafka has no brokers online.',
description: 'Kafka cluster {{ $labels.%s }} broker count is 0.' % this.config.groupLabels[0],
description: 'Kafka cluster {{ $labels.%s }} broker count is 0.' % groupLabel,
},
},
{
Expand All @@ -161,11 +169,12 @@
},
annotations: {
summary: 'Kafka Zookeeper sync disconected.',
description: 'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} has disconected from Zookeeper.'
% [
this.config.instanceLabels[0],
this.config.groupLabels[0],
],
description:
'Kafka broker {{ $labels.%s }} in cluster {{ $labels.%s }} has disconected from Zookeeper.'
% [
instanceLabel,
groupLabel,
],
},
},

Expand Down

0 comments on commit 1132fd7

Please sign in to comment.