spuru9 commented on code in PR #1187:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/1187#discussion_r3820869212


##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/utils/PartitionMetricNameParser.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.autoscaler.utils;
+
+/**
+ * Parses Kafka/Pulsar source-partition metric names to extract a stable 
per-partition key.
+ *
+ * <p>Uses plain string splitting/indexing rather than a regex, since metric 
names are fully
+ * job-controlled and this must stay linear-time regardless of input shape.
+ */
+public final class PartitionMetricNameParser {

Review Comment:
   Yes — verified manually against real brokers, broadened well past the 
earlier topic-only check. Fresh minikube, operator built from this PR (`DEBUG` 
on `ScalingMetricCollector`), real Apache Kafka 3.9.1 (KRaft) + Pulsar 3.3.1 
(standalone), OSS connectors kafka:3.3.0-1.20 / pulsar:4.2.0-1.20 on Flink 
1.20. Per case I cross-checked broker ground truth → REST `/metrics` names → 
the operator's derived `numSourcePartitions`.
   
   | # | Dimension | Setup | Expected | Detected |
   |---|---|---|---|---|
   | 1 | Multi-topic + higher scale + edge names | Kafka `events`(6) + 
`big24`(24) + `orders.eu.v1`(3, dotted) + `my-topic`(2, hyphen), parallelism 1 
| 35 | 35 ✅ |
   | 2 | Source parallelism > 1 | Kafka `par12`(12) at parallelism 4 
(partitions spread across 4 subtasks) | 12 | 12 ✅ |
   | 3 | Multiple source vertices in one job | one job with a Kafka source 
(`kmix`=5) **and** a Pulsar source (`pmix`=3) | 5 / 3 | Kafka vtx 5, Pulsar vtx 
3 ✅ |
   | — | Negative (non-partition source) | `StateMachineExample` | none | 
`numSourcePartitions=0`, no false positive ✅ |
   
   Edge cases confirmed end-to-end:
   - **Dot sanitization:** `orders.eu.v1` arrives as 
`…topic.orders_eu_v1.partition.N.currentOffset` (`.` in a component becomes `_` 
before joining), so the split-on-`.` parser gets a clean segment.
   - **Hyphen vs `-partition-`:** `my-topic` / `orders-v2-partition-N` key off 
the right marker.
   - **Parallelism > 1:** correct when aggregating `currentOffset` across 
subtasks.
   - **Multiple sources:** each source vertex counted independently.
   
   **Upfront caveat:** with `scaling.enabled=true` the parser computes 
`numSourcePartitions=4` every cycle, but I couldn't force a live scale-up on 
this single-node setup to show that count *binding* as the source's 
max-parallelism cap. That cap-application is pre-existing autoscaler logic 
anyway — this PR only computes the count.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to