hudi-agent commented on code in PR #18685:
URL: https://github.com/apache/hudi/pull/18685#discussion_r3192944342
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/bootstrap/RLIBootstrapOperator.java:
##########
@@ -54,11 +55,22 @@ public class RLIBootstrapOperator
private transient HoodieBackedTableMetadata metadataTable;
private transient long loadedCnt;
+ private transient long numFileSlicesProcessed;
+ private transient long bootstrapCostMs;
+ private transient FlinkRLIBootstrapMetrics metrics;
public RLIBootstrapOperator(Configuration conf) {
super(conf);
}
+ @Override
+ public void open() throws Exception {
+ super.open();
+ this.metrics = new
FlinkRLIBootstrapMetrics(getRuntimeContext().getMetricGroup());
+ this.metrics.registerMetrics();
+ this.metrics.updateLoadResult(numFileSlicesProcessed, loadedCnt,
bootstrapCostMs);
Review Comment:
🤖 nit: this `updateLoadResult` call passes the just-default zero values, so
it's a no-op (gauges already return 0 from the field defaults). Could you drop
it and rely on the call in `initializeState` after `preLoadRLIRecords` to
publish the real values?
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/bootstrap/RLIBootstrapOperator.java:
##########
@@ -70,6 +82,7 @@ public void initializeState(StateInitializationContext
context) throws Exception
conf.get(FlinkOptions.PATH));
// Load RLI records
preLoadRLIRecords();
+ this.metrics.updateLoadResult(numFileSlicesProcessed, loadedCnt,
bootstrapCostMs);
Review Comment:
🤖 In Flink's operator lifecycle, `initializeState()` runs before `open()`,
so `this.metrics` is still null here and this call would NPE. Could you move
the `metrics` initialization into `initializeState()` (before
`preLoadRLIRecords()`), or guard this update with a null check? @danny0405
could you confirm the lifecycle ordering for this operator?
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/metrics/TestFlinkRLIBootstrapMetrics.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.Gauge;
+import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.BOOTSTRAP_COST_MS;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.BOOTSTRAP_RECORD_PER_MS;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.NUM_FILE_SLICES_PROCESSED;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.NUM_INDEX_RECORDS_EMITTED;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+/**
+ * Test cases for {@link FlinkRLIBootstrapMetrics}.
+ */
+class TestFlinkRLIBootstrapMetrics {
+
+ /** Subclass that captures registered gauges so tests can read their values.
*/
+ private static class CapturingMetricGroup extends UnregisteredMetricsGroup {
+ final Map<String, Gauge<?>> gauges = new HashMap<>();
+
+ @Override
+ public <T, G extends Gauge<T>> G gauge(String name, G gauge) {
+ gauges.put(name, gauge);
+ return gauge;
+ }
+ }
+
+ private CapturingMetricGroup metricGroup;
+ private FlinkRLIBootstrapMetrics metrics;
+
+ @BeforeEach
+ void setUp() {
+ metricGroup = new CapturingMetricGroup();
+ metrics = new FlinkRLIBootstrapMetrics(metricGroup);
+ metrics.registerMetrics();
+ }
+
+ // -------------------------------------------------------------------------
+ // Metric name constants
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testMetricNameConstants() {
+ assertEquals("rliBootstrap.numFileSlicesProcessed",
NUM_FILE_SLICES_PROCESSED);
+ assertEquals("rliBootstrap.numIndexRecordsEmitted",
NUM_INDEX_RECORDS_EMITTED);
+ assertEquals("rliBootstrap.bootstrapCostMs", BOOTSTRAP_COST_MS);
+ assertEquals("rliBootstrap.bootstrapRecordPerMs", BOOTSTRAP_RECORD_PER_MS);
+ }
+
+ // -------------------------------------------------------------------------
+ // Gauge registration
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testAllMetricsAreRegistered() {
+ assertEquals(4, metricGroup.gauges.size());
+ assertEquals(true,
metricGroup.gauges.containsKey(NUM_FILE_SLICES_PROCESSED));
+ assertEquals(true,
metricGroup.gauges.containsKey(NUM_INDEX_RECORDS_EMITTED));
+ assertEquals(true, metricGroup.gauges.containsKey(BOOTSTRAP_COST_MS));
+ assertEquals(true,
metricGroup.gauges.containsKey(BOOTSTRAP_RECORD_PER_MS));
+ }
+
+ @Test
+ void testRegisterMetricsWithUnregisteredGroupDoesNotThrow() {
+ assertDoesNotThrow(() ->
+ new FlinkRLIBootstrapMetrics(new
UnregisteredMetricsGroup()).registerMetrics());
+ }
+
+ // -------------------------------------------------------------------------
+ // Initial values (before any update)
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testInitialValuesAreZero() {
+ assertEquals(0L, (Long) gaugeValue(NUM_FILE_SLICES_PROCESSED));
+ assertEquals(0L, (Long) gaugeValue(NUM_INDEX_RECORDS_EMITTED));
+ assertEquals(0L, (Long) gaugeValue(BOOTSTRAP_COST_MS));
+ assertEquals(0.0, gaugeValue(BOOTSTRAP_RECORD_PER_MS));
+ }
+
+ // -------------------------------------------------------------------------
+ // After updateLoadResult
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testUpdateLoadResultReflectsInGauges() {
+ metrics.updateLoadResult(8, 1000, 500);
+
+ assertEquals(8L, (Long) gaugeValue(NUM_FILE_SLICES_PROCESSED));
+ assertEquals(1000L, (Long) gaugeValue(NUM_INDEX_RECORDS_EMITTED));
+ assertEquals(500L, (Long) gaugeValue(BOOTSTRAP_COST_MS));
+ }
+
+ @Test
+ void testThroughputIsRecordsPerSecond() {
Review Comment:
🤖 nit: the test name and the comment on the next line say "records/sec", but
the metric (`BOOTSTRAP_RECORD_PER_MS`) and the asserted value (`4.0` for
2000/500ms) are records-per-ms. Could you rename to
`testThroughputIsRecordsPerMs` and update the comment to match? Otherwise it's
easy for a future reader to think there's a unit bug.
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/metrics/TestFlinkRLIBootstrapMetrics.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.Gauge;
+import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.BOOTSTRAP_COST_MS;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.BOOTSTRAP_RECORD_PER_MS;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.NUM_FILE_SLICES_PROCESSED;
+import static
org.apache.hudi.metrics.FlinkRLIBootstrapMetrics.NUM_INDEX_RECORDS_EMITTED;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+/**
+ * Test cases for {@link FlinkRLIBootstrapMetrics}.
+ */
+class TestFlinkRLIBootstrapMetrics {
+
+ /** Subclass that captures registered gauges so tests can read their values.
*/
+ private static class CapturingMetricGroup extends UnregisteredMetricsGroup {
+ final Map<String, Gauge<?>> gauges = new HashMap<>();
+
+ @Override
+ public <T, G extends Gauge<T>> G gauge(String name, G gauge) {
+ gauges.put(name, gauge);
+ return gauge;
+ }
+ }
+
+ private CapturingMetricGroup metricGroup;
+ private FlinkRLIBootstrapMetrics metrics;
+
+ @BeforeEach
+ void setUp() {
+ metricGroup = new CapturingMetricGroup();
+ metrics = new FlinkRLIBootstrapMetrics(metricGroup);
+ metrics.registerMetrics();
+ }
+
+ // -------------------------------------------------------------------------
+ // Metric name constants
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testMetricNameConstants() {
+ assertEquals("rliBootstrap.numFileSlicesProcessed",
NUM_FILE_SLICES_PROCESSED);
+ assertEquals("rliBootstrap.numIndexRecordsEmitted",
NUM_INDEX_RECORDS_EMITTED);
+ assertEquals("rliBootstrap.bootstrapCostMs", BOOTSTRAP_COST_MS);
+ assertEquals("rliBootstrap.bootstrapRecordPerMs", BOOTSTRAP_RECORD_PER_MS);
+ }
+
+ // -------------------------------------------------------------------------
+ // Gauge registration
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testAllMetricsAreRegistered() {
+ assertEquals(4, metricGroup.gauges.size());
+ assertEquals(true,
metricGroup.gauges.containsKey(NUM_FILE_SLICES_PROCESSED));
Review Comment:
🤖 nit: `assertEquals(true, ...)` reads better as `assertTrue(...)` here (and
on the three lines below). Minor, but it expresses intent more directly.
<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]