npawar commented on code in PR #8877:
URL: https://github.com/apache/pinot/pull/8877#discussion_r896260018


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/realtime/MissingConsumingSegmentFinder.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.pinot.controller.helix.core.realtime;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.helix.AccessOption;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metrics.ControllerGauge;
+import org.apache.pinot.common.metrics.ControllerMeter;
+import org.apache.pinot.common.metrics.ControllerMetrics;
+import org.apache.pinot.common.utils.LLCSegmentName;
+import 
org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel.SegmentStateModel;
+import org.apache.zookeeper.data.Stat;
+
+
+/**
+ * For a given table, this class finds out if there is any partition group for 
which there's no consuming segment in
+ * ideal state. If so, it emits two metrics:
+ *   - Number of missing consuming segments
+ *   - Maximum duration (in minutes) that a partition hasn't had a consuming 
segment
+ */
+public class MissingConsumingSegmentFinder {
+
+  private String _realtimeTableName;
+  private ControllerMetrics _controllerMetrics;
+  private SegmentMetadataFetcher _segmentMetadataFetcher;
+
+  public MissingConsumingSegmentFinder(String realtimeTableName, 
ZkHelixPropertyStore<ZNRecord> propertyStore,
+      ControllerMetrics controllerMetrics) {
+    _realtimeTableName = realtimeTableName;
+    _controllerMetrics = controllerMetrics;
+    _segmentMetadataFetcher = new SegmentMetadataFetcher(propertyStore, 
controllerMetrics);
+  }
+
+  @VisibleForTesting
+  MissingConsumingSegmentFinder(String realtimeTableName, 
SegmentMetadataFetcher segmentMetadataFetcher) {
+    _realtimeTableName = realtimeTableName;
+    _segmentMetadataFetcher = segmentMetadataFetcher;
+  }
+
+  public void findAndEmitMetrics(IdealState idealState) {
+    MissingSegmentInfo info = 
findMissingSegments(idealState.getRecord().getMapFields(), Instant.now());
+    _controllerMetrics.setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_COUNT,
+        info._count);
+    _controllerMetrics
+        .setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_MAX_DURATION_MINUTES,
+            info._maxDurationInMinutes);
+  }
+
+  @VisibleForTesting
+  MissingSegmentInfo findMissingSegments(Map<String, Map<String, String>> 
idealStateMap, Instant now) {
+    // create the maps
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestConsumingSegmentMap = 
new HashMap<>();
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestCompletedSegmentMap = 
new HashMap<>();
+    idealStateMap.forEach((segmentName, instanceToStatusMap) -> {
+      LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName);
+      if (llcSegmentName != null) { // Skip the uploaded realtime segments 
that don't conform to llc naming
+        if (instanceToStatusMap.containsValue(SegmentStateModel.CONSUMING)) {
+          updateMap(partitionGroupIdToLatestConsumingSegmentMap, 
llcSegmentName);

Review Comment:
   `So for these cases, the last consumed time is when the previous completed 
segment went to ONLINE state.` - I think this misses the case when the very 
first segment itself is OFFLINE.  



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/realtime/MissingConsumingSegmentFinder.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.pinot.controller.helix.core.realtime;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.helix.AccessOption;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metrics.ControllerGauge;
+import org.apache.pinot.common.metrics.ControllerMeter;
+import org.apache.pinot.common.metrics.ControllerMetrics;
+import org.apache.pinot.common.utils.LLCSegmentName;
+import 
org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel.SegmentStateModel;
+import org.apache.zookeeper.data.Stat;
+
+
+/**
+ * For a given table, this class finds out if there is any partition group for 
which there's no consuming segment in
+ * ideal state. If so, it emits two metrics:
+ *   - Number of missing consuming segments
+ *   - Maximum duration (in minutes) that a partition hasn't had a consuming 
segment
+ */
+public class MissingConsumingSegmentFinder {
+
+  private String _realtimeTableName;
+  private ControllerMetrics _controllerMetrics;
+  private SegmentMetadataFetcher _segmentMetadataFetcher;
+
+  public MissingConsumingSegmentFinder(String realtimeTableName, 
ZkHelixPropertyStore<ZNRecord> propertyStore,
+      ControllerMetrics controllerMetrics) {
+    _realtimeTableName = realtimeTableName;
+    _controllerMetrics = controllerMetrics;
+    _segmentMetadataFetcher = new SegmentMetadataFetcher(propertyStore, 
controllerMetrics);
+  }
+
+  @VisibleForTesting
+  MissingConsumingSegmentFinder(String realtimeTableName, 
SegmentMetadataFetcher segmentMetadataFetcher) {
+    _realtimeTableName = realtimeTableName;
+    _segmentMetadataFetcher = segmentMetadataFetcher;
+  }
+
+  public void findAndEmitMetrics(IdealState idealState) {
+    MissingSegmentInfo info = 
findMissingSegments(idealState.getRecord().getMapFields(), Instant.now());
+    _controllerMetrics.setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_COUNT,
+        info._count);
+    _controllerMetrics
+        .setValueOfTableGauge(_realtimeTableName, 
ControllerGauge.MISSING_CONSUMING_SEGMENT_MAX_DURATION_MINUTES,
+            info._maxDurationInMinutes);
+  }
+
+  @VisibleForTesting
+  MissingSegmentInfo findMissingSegments(Map<String, Map<String, String>> 
idealStateMap, Instant now) {
+    // create the maps
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestConsumingSegmentMap = 
new HashMap<>();
+    Map<Integer, LLCSegmentName> partitionGroupIdToLatestCompletedSegmentMap = 
new HashMap<>();
+    idealStateMap.forEach((segmentName, instanceToStatusMap) -> {
+      LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName);
+      if (llcSegmentName != null) { // Skip the uploaded realtime segments 
that don't conform to llc naming
+        if (instanceToStatusMap.containsValue(SegmentStateModel.CONSUMING)) {
+          updateMap(partitionGroupIdToLatestConsumingSegmentMap, 
llcSegmentName);

Review Comment:
   And for the new partition case, my strong preference would still be to 
include them here so this becomes a reliable metric covering all cases. It 
would be hard to reason about and explain to users about the cases this 
includes and excludes (like if they delete a CONSUMING segment that had seqId 
3, we would detect it, but if they deleted CONSUMING segment with segId 0, we 
wouldnt detect it, and then proceed to explain how that is okay to not detect 
because validation manager would anyway fix it.)
   But if keeping this lightweight and free of stream connections and stream 
error handling is a string requirement, I guess it's fine.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to