Skip to content

Commit 15abf38

Browse files
amuraruCopilot
andcommitted
fix: restore alert-driven broker downscale and safe monitoring defaults
Implement concrete Cruise Control replica lookup and fail closed on missing broker counts. Accept Alertmanager envelopes, separate diagnostic and action routes, and document explicit autoscaling configuration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 86b6d4a commit 15abf38

11 files changed

Lines changed: 1026 additions & 36 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ kubectl -n kafka run kafka-consumer -it --image=adobe/kafka:2.13-3.9.1 --rm=true
204204

205205
For detailed documentation on the Koperator project, see the [Koperator documentation website](https://opensource.adobe.com/koperator/).
206206

207+
- [Monitoring Kafka clusters](docs/monitoring.md)
208+
- [Broker autoscaling](docs/autoscale.md)
209+
207210
## Issues and contributions
208211

209212
We use GitHub to track issues and accept contributions.

‎config/samples/kafkacluster-prometheus.yaml‎

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,16 @@ spec:
7171
groups:
7272
- name: KafkaAlerts
7373
rules:
74-
- alert: BrokerOverLoaded
75-
expr: avg(sum by(brokerId, kafka_cr, namespace) (rate(kafka_network_requestmetrics_requests_total[15m]))) by (kafka_cr, namespace) > 30
74+
# Broker alerts are diagnostic only. These example thresholds are not capacity limits.
75+
- alert: BrokerRequestRateHigh
76+
expr: sum by(brokerId, kafka_cr, namespace) (rate(kafka_network_requestmetrics_requests_total[15m])) > 30
7677
for: 5m
7778
labels:
7879
severity: alert
7980
alertGroup: kafka
8081
annotations:
81-
description: 'broker {{ $labels.brokerId }} overloaded (current value is: {{ $value }})'
82-
summary: 'broker overloaded'
83-
# If brokerConfigGroup is defined it will override scaled broker config
84-
# brokerConfigGroup: 'default_group'
85-
storageClass: 'gp2'
86-
mountPath: '/kafkalog'
87-
diskSize: '10G'
88-
image: 'ghcr.io/adobe/koperator/kafka:2.13-3.9.2-jdk21.0.12' # renovate: datasource=docker depName=ghcr.io/adobe/koperator/kafka
89-
# annotations to be applied onto the broker pod
90-
# brokerAnnotations: '{ "sidecar.istio.io/logLevel": "trace", "sidecar.istio.io/proxyCPULimit": "50m" }'
91-
command: 'upScale'
82+
description: 'broker {{ $labels.brokerId }} request rate is high (current value is: {{ $value | printf "%.2f" }} requests/s); verify capacity and latency before scaling'
83+
summary: 'high broker request rate (diagnostic only)'
9284
- alert: BrokerUnderReplicated
9385
expr: kafka_server_replicamanager_underreplicatedpartitions > 0
9486
for: 5m
@@ -98,29 +90,15 @@ spec:
9890
annotations:
9991
description: 'broker {{ $labels.brokerId }} underreplicated'
10092
summary: 'broker underreplicated'
101-
storageClass: 'gp2'
102-
mountPath: '/kafkalog'
103-
diskSize: '10G'
104-
image: 'ghcr.io/adobe/koperator/kafka:2.13-3.9.2-jdk21.0.12' # renovate: datasource=docker depName=ghcr.io/adobe/koperator/kafka
105-
# annotations to be applied onto the broker pod
106-
# brokerAnnotations: '{ "sidecar.istio.io/logLevel": "trace", "sidecar.istio.io/proxyCPULimit": "50m" }'
107-
command: 'upScale'
10893
- alert: PartitionCountHigh
109-
expr: max(kafka_server_replicamanager_partitioncount) by (namespace, kafka_cr) > 100
94+
expr: kafka_server_replicamanager_partitioncount > 100
11095
for: 3m
11196
labels:
11297
severity: alert
11398
alertGroup: kafka
11499
annotations:
115100
description: 'broker {{ $labels.brokerId }} has high partition count'
116101
summary: 'high partition count'
117-
storageClass: 'gp2'
118-
mountPath: '/kafkalog'
119-
diskSize: '10G'
120-
image: 'ghcr.io/adobe/koperator/kafka:2.13-3.9.2-jdk21.0.12' # renovate: datasource=docker depName=ghcr.io/adobe/koperator/kafka
121-
# annotations to be applied onto the broker pod
122-
# brokerAnnotations: '{ "sidecar.istio.io/logLevel": "trace", "sidecar.istio.io/proxyCPULimit": "50m" }'
123-
command: 'upScale'
124102
- alert: PartitionCountLow
125103
expr: bottomk(1, kafka_server_replicamanager_partitioncount) by (namespace, kafka_cr) < 40
126104
for: 3m
@@ -130,7 +108,6 @@ spec:
130108
annotations:
131109
description: 'broker {{ $labels.brokerId }} has low partition count'
132110
summary: 'low partition count'
133-
command: 'downScale'
134111
- alert: RemainingDiskSpaceLow
135112
expr: (kubelet_volume_stats_available_bytes{job="kubelet",metrics_path="/metrics",namespace=~".*",persistentvolumeclaim=~"kafka-.*"}/ kubelet_volume_stats_capacity_bytes{job="kubelet",metrics_path="/metrics",namespace=~".*",persistentvolumeclaim=~"kafka-.*"})< 0.15 and predict_linear(kubelet_volume_stats_available_bytes{job="kubelet",metrics_path="/metrics",namespace=~".*",persistentvolumeclaim=~"kafka-.*"}[6h], 4 * 24 * 3600) < 0
136113
for: 2m
@@ -192,8 +169,8 @@ spec:
192169
alerting:
193170
alertmanagers:
194171
- namespace: kafka
195-
name: kafka-operator-alertmanager
196-
port: http-alerts
172+
name: kafka-alertmanager
173+
port: web
197174
serviceMonitorSelector:
198175
matchLabels:
199176
kafka_cr: kafka
@@ -205,3 +182,51 @@ spec:
205182
requests:
206183
memory: 400Mi
207184
enableAdminAPI: false
185+
---
186+
apiVersion: v1
187+
kind: Secret
188+
metadata:
189+
name: alertmanager-kafka-alertmanager
190+
stringData:
191+
alertmanager.yaml: |
192+
route:
193+
receiver: monitoring
194+
group_by: [alertname, namespace, kafka_cr]
195+
group_wait: 30s
196+
group_interval: 5m
197+
repeat_interval: 4h
198+
routes:
199+
- receiver: koperator-storage
200+
matchers:
201+
- alertname="RemainingDiskSpaceLow"
202+
- alertGroup="kafka"
203+
receivers:
204+
# Configure your human notification integration here before using this sample.
205+
- name: monitoring
206+
- name: koperator-storage
207+
webhook_configs:
208+
# Assumes the Helm release is named kafka-operator in the kafka namespace.
209+
- url: http://kafka-operator-alertmanager.kafka.svc:9001/
210+
send_resolved: true
211+
---
212+
apiVersion: monitoring.coreos.com/v1
213+
kind: Alertmanager
214+
metadata:
215+
name: kafka-alertmanager
216+
spec:
217+
replicas: 1
218+
resources:
219+
requests:
220+
memory: 64Mi
221+
---
222+
apiVersion: v1
223+
kind: Service
224+
metadata:
225+
name: kafka-alertmanager
226+
spec:
227+
selector:
228+
alertmanager: kafka-alertmanager
229+
ports:
230+
- name: web
231+
port: 9093
232+
targetPort: 9093

‎docs/autoscale.md‎

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<!--
2+
Copyright 2026 Adobe. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
# Broker autoscaling
18+
19+
Koperator can add or remove a data broker in response to an alert delivered to
20+
its action receiver. Prometheus evaluates your policy, Alertmanager routes the
21+
action alert, and Koperator updates the KafkaCluster's desired broker list.
22+
Reconciliation and Cruise Control perform the resource and replica changes.
23+
24+
**Broker autoscaling is opt-in.** The
25+
[monitoring sample](../config/samples/kafkacluster-prometheus.yaml) contains
26+
diagnostic broker alerts without scaling commands or broker-action routes.
27+
These sample defaults do not disable existing custom action alerts, direct
28+
webhook integrations, or manual changes to `spec.brokers`.
29+
30+
Set up metrics and human notifications using the
31+
[monitoring user guide](monitoring.md) before enabling broker actions.
32+
Keep the Helm setting `alertManager.enable` enabled and ensure Alertmanager can
33+
reach Koperator's webhook Service. Cruise Control must be configured and healthy.
34+
35+
## Prepare a scaling policy
36+
37+
Use a policy validated against your workload and deployment. The sample
38+
request-rate and partition-count thresholds are not capacity recommendations.
39+
40+
Before enabling actions:
41+
42+
1. Measure idle and representative load behavior per broker: CPU, memory, disk,
43+
network, request latency, replication health, and partition placement.
44+
2. Verify that adding a broker produces useful replica redistribution with
45+
your Cruise Control goals and load model.
46+
3. Before scale-in, verify that the remaining data brokers can sustain the
47+
workload and preserve replication factor, minimum ISR, and rack placement.
48+
4. Define a post-operation stabilization interval and prevent opposing
49+
scale-out/scale-in requests during it.
50+
5. Test the policy and delivery path in a disposable cluster before production.
51+
Include missing metrics, broker startup, skew, and overlapping signals.
52+
53+
Koperator does not provide a timed cooldown. An alert's `for` duration measures
54+
how long its expression remains true, not how long it has been since the last
55+
operation. Enforce stabilization in your action policy or external coordinator;
56+
keep scale-in manually approved until that control is in place.
57+
58+
## Configure broker-count limits
59+
60+
Set positive limits in the existing KafkaCluster manifest. This example allows
61+
three to four data brokers alongside three dedicated KRaft controllers; it is
62+
not a capacity recommendation:
63+
64+
```yaml
65+
spec:
66+
alertManagerConfig:
67+
downScaleLimit: 6
68+
upScaleLimit: 7
69+
```
70+
71+
Scale-in is skipped when the number of entries in `spec.brokers` is at or below
72+
`downScaleLimit`. Scale-out is skipped when that count is at or above
73+
`upScaleLimit`. Omitted or non-positive values do not provide an effective
74+
bound.
75+
76+
The count includes dedicated KRaft controllers. These limits apply to
77+
alert-triggered scaling, not manual edits of the broker list. Count limits alone
78+
do not establish replication, placement, or resource safety.
79+
80+
## Define separate action alerts
81+
82+
Keep diagnostic alerts unchanged. Create separately named action alerts with
83+
workload-specific conditions or an approval mechanism.
84+
85+
An action alert must contain `namespace` and `kafka_cr` labels and a supported
86+
`command` annotation. For example, an approved scale-out alert delivered to
87+
Koperator can carry:
88+
89+
```yaml
90+
labels:
91+
alertname: KafkaScaleOutApproved
92+
namespace: kafka
93+
kafka_cr: kafka
94+
autoscaling: approved
95+
annotations:
96+
command: upScale
97+
brokerConfigGroup: broker
98+
```
99+
100+
This is an alert payload fragment, not a complete PrometheusRule. Prometheus
101+
sets `alertname` from the rule's `alert` field. The `autoscaling` label is an
102+
example routing convention, not a Koperator authorization check; restrict who
103+
can create action rules and access the webhook.
104+
105+
For scale-out, `brokerConfigGroup` must name an existing configuration group
106+
suitable for a data broker. In KRaft mode, include the appropriate broker
107+
process role in that group. Without a matching group, Koperator builds the
108+
broker configuration from the alert's `image`, `storageClass`, `mountPath`,
109+
and `diskSize` annotations; provide valid image and storage settings.
110+
111+
For scale-in, use `command: downScale`. An optional `brokerId` label selects
112+
that broker. Without it, Cruise Control supplies replica counts and Koperator
113+
selects a broker with the fewest replicas. Equal minima have no guaranteed
114+
selection order. Failed lookups or empty maps leave the broker list unchanged.
115+
Neither explicit selection nor minimum replica count proves removal is safe.
116+
117+
## Route only approved actions to Koperator
118+
119+
In the Alertmanager configuration described in the
120+
[monitoring guide](monitoring.md#configure-notifications-and-actions), add a
121+
child route under the existing `route.routes` list:
122+
123+
```yaml
124+
- receiver: koperator-brokers
125+
matchers:
126+
- autoscaling="approved"
127+
- alertname=~"KafkaScaleOutApproved|KafkaScaleInApproved"
128+
- namespace="kafka"
129+
- kafka_cr="kafka"
130+
```
131+
132+
Add its receiver to the existing `receivers` list:
133+
134+
```yaml
135+
- name: koperator-brokers
136+
webhook_configs:
137+
- url: http://kafka-operator-alertmanager.kafka.svc:9001/
138+
send_resolved: true
139+
```
140+
141+
These are configuration fragments: merge them without replacing the existing
142+
`monitoring` or storage routes and receivers. Adjust names, labels, and the
143+
webhook address for your installation. Do not route all `alertGroup="kafka"`
144+
alerts to the action receiver.
145+
146+
Koperator accepts Prometheus alert arrays and Alertmanager webhook envelopes.
147+
Keep resolved deliveries enabled so an alert can be cleared and a later
148+
recurrence can be processed.
149+
150+
## What happens after an action
151+
152+
The cluster must be running. Koperator applies the count limits and checks for
153+
relevant pending or running Cruise Control tasks before changing the broker
154+
list.
155+
156+
| Action | Desired-state change | Subsequent work |
157+
|---|---|---|
158+
| `upScale` | Appends one broker to `spec.brokers`, using an ID one greater than the largest existing ID | Creates its resources and initiates Cruise Control scale-out work |
159+
| `downScale` | Removes the selected broker from `spec.brokers` | In the normal graceful path for initialized data brokers, evacuates replicas through Cruise Control before deleting the broker pod and associated data PVCs |
160+
161+
Replica movement depends on Cruise Control's goals and available model.
162+
Check actual placement and movement counts, not only task completion. This
163+
guide describes data-broker scaling; controller-only removal and removal of
164+
partially initialized brokers follow different paths.
165+
166+
### Repeated notifications
167+
168+
Koperator identifies an alert by a fingerprint of its labels. Once marked
169+
processed, repeated notifications for that fingerprint do not continuously add
170+
or remove brokers. A resolved notification clears the entry. Changing labels
171+
can create a new fingerprint; changing annotations alone does not.
172+
173+
This state is in memory and is lost on an operator restart. It is not a durable
174+
exactly-once guarantee or a cooldown. Do not assume a skipped scaling alert is
175+
queued for execution when other work finishes.
176+
177+
## Verify progress and completion
178+
179+
Select the intended context, namespace, and KafkaCluster:
180+
181+
```sh
182+
CONTEXT=your-kubernetes-context
183+
NAMESPACE=kafka
184+
CLUSTER=kafka
185+
kubectl --context "$CONTEXT" -n "$NAMESPACE" get kafkacluster "$CLUSTER" -o yaml
186+
kubectl --context "$CONTEXT" -n "$NAMESPACE" get cruisecontroloperations
187+
kubectl --context "$CONTEXT" -n "$NAMESPACE" get pods,pvc
188+
```
189+
190+
Confirm the requested change in `spec.brokers`, inspect graceful-action states
191+
in `status.brokersState`, and check the corresponding CruiseControlOperation
192+
results and operator logs. Verify replica placement, in-sync replicas, and
193+
producer/consumer availability before allowing another action.
194+
195+
HTTP `202 Accepted` acknowledges the alert payload, not successful scaling.
196+
Guards can skip an action, and action-handling errors can be logged without
197+
changing that response. Pod readiness alone is also not proof of completion.
198+
199+
## Pause broker autoscaling
200+
201+
Resolve existing broker-action alerts while resolved deliveries are still
202+
enabled, then disable their generation and action route. Keep diagnostic
203+
notifications and any separately approved storage actions active.
204+
205+
Check for pending or running operations. Disabling future alerts does not
206+
cancel an operation already underway. Do not delete broker pods or PVCs to
207+
interrupt scaling.

0 commit comments

Comments
 (0)