hudi-agent commented on code in PR #18690:
URL: https://github.com/apache/hudi/pull/18690#discussion_r3186623258


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/partitioner/index/RecordLevelIndexBackend.java:
##########
@@ -140,4 +142,9 @@ public void close() throws IOException {
       throw new HoodieException("Exception happened during close metadata 
table.", e);
     }
   }
+
+  @Override
+  public void registerMetrics(MetricGroup metricGroup) {

Review Comment:
   🤖 After `reloadMetadataTable()` runs (e.g. on checkpoint complete), 
`this.metadataTable` is replaced with a new instance backed by a new 
`HoodieMetadataMetrics`/`MetricRegistry`. But the gauges registered with Flink 
in `registerMetrics()` capture references to the *previous* registry's metrics, 
so they keep pointing at the closed metadata table and won't reflect updates 
from the reloaded one. Should `registerMetrics` be re-invoked (or the bridging 
done indirectly through a level of indirection) after each reload so the metric 
group sees the live registry?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/metrics/FlinkMetricsUtils.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.hudi.metrics;
+
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.hudi.metadata.HoodieBackedTableMetadata;
+
+/**
+ * Utils for Flink metrics registration.
+ */
+public class FlinkMetricsUtils {
+
+  public static void registerMetadataTableMetrics(HoodieBackedTableMetadata 
metadataTable, MetricGroup metricGroup) {
+    if (metadataTable == null) {

Review Comment:
   🤖 Is this method safe to call more than once on the same `MetricGroup` (e.g. 
operator restart, or the index-backend reload path)? Flink's 
`MetricGroup#gauge` will throw/log on duplicate names, and Dropwizard registry 
contents are not necessarily empty across calls. Might be worth either 
documenting the single-call contract or guarding against duplicates here.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/metrics/FlinkMetricsUtils.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.hudi.metrics;
+
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.hudi.metadata.HoodieBackedTableMetadata;
+
+/**
+ * Utils for Flink metrics registration.
+ */
+public class FlinkMetricsUtils {
+
+  public static void registerMetadataTableMetrics(HoodieBackedTableMetadata 
metadataTable, MetricGroup metricGroup) {
+    if (metadataTable == null) {
+      return;
+    }
+
+    // metrics is Option.empty() when metrics are disabled
+    metadataTable.getMetrics().ifPresent(m -> {
+      m.registry().getGauges().forEach((name, gauge) ->
+          metricGroup.gauge(name, gauge::getValue));
+      m.registry().getCounters().forEach((name, counter) ->
+          metricGroup.gauge(name, counter::getCount));
+      m.registry().getMeters().forEach((name, meter) -> {

Review Comment:
   🤖 nit: counters are registered under the bare `name` key while every other 
metric type uses `name + ".count"` for the count sub-metric — so a counter 
named `hits` shows up as `hits` in Flink but a meter named `hits` shows 
`hits.count`. Could you either apply the same `.count` suffix here for 
consistency, or add a short comment explaining the intentional asymmetry?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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