You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/06/24 19:44:55 UTC

[GitHub] [incubator-pinot] xiaohui-sun commented on a change in pull request #4354: [TE] Trigger expression based grouping of anomalies - AND, OR and combinations

xiaohui-sun commented on a change in pull request #4354: [TE] Trigger expression based grouping of anomalies - AND, OR and combinations
URL: https://github.com/apache/incubator-pinot/pull/4354#discussion_r296884998
 
 

 ##########
 File path: thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/TriggerConditionGrouper.java
 ##########
 @@ -0,0 +1,283 @@
+/*
+ * 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.thirdeye.detection.components;
+
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
+import org.apache.pinot.thirdeye.detection.ConfigUtils;
+import org.apache.pinot.thirdeye.detection.InputDataFetcher;
+import org.apache.pinot.thirdeye.detection.annotation.Components;
+import org.apache.pinot.thirdeye.detection.annotation.DetectionTag;
+import org.apache.pinot.thirdeye.detection.spec.TriggerConditionGrouperSpec;
+import org.apache.pinot.thirdeye.detection.spi.components.Grouper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.pinot.thirdeye.detection.DetectionUtils.*;
+
+
+/**
+ * Expression based grouper - supports AND, OR and nested combinations of grouping
+ */
+@Components(title = "TriggerCondition", type = "GROUPER",
+    tags = {DetectionTag.GROUPER}, description = "An expression based grouper")
+public class TriggerConditionGrouper implements Grouper<TriggerConditionGrouperSpec> {
+  protected static final Logger LOG = LoggerFactory.getLogger(TriggerConditionGrouper.class);
+
+  private String expression;
+  private String operator;
+  private Map<String, Object> leftOp;
+  private Map<String, Object> rightOp;
+  private InputDataFetcher dataFetcher;
+
+  static final String PROP_DETECTOR_COMPONENT_NAME = "detectorComponentName";
+  static final String PROP_AND = "and";
+  static final String PROP_OR = "or";
+
+  private static final String PROP_OPERATOR = "operator";
+  private static final String PROP_LEFT_OP = "leftOp";
+  private static final String PROP_RIGHT_OP = "rightOp";
+
+  /**
+   * Group based on 'AND' criteria - Entity has anomaly if both sub-entities A and B have anomalies
+   * at the same time. This means we find anomaly overlapping interval.
+   *
+   * Since the anomalies from the respective entities/metrics are merged
+   * before calling the grouper, we do not have to deal with overlapping
+   * anomalies within an entity/metric
+   *
+   * Core logic:
+   * Sort anomalies by start time and iterate through the list
+   * Push first anomaly to stack
+   * For each anomaly following, pop stack and compare with current anomaly
+   * 1. No overlap:
+   *    If the anomaly doesn't overlap, create and push new entity anomaly
+   * 2. Partial overlap:
+   *    If partial overlap, create new grouped entity anomaly and push to stack followed by current anomaly
+   * 3. Full overlap:
+   *    If full overlap, create new grouped entity anomaly and push to stack followed by current anomaly
+   * After the last anomaly, the stack will have one extra anomaly which needs to be popped out.
+   * Now the stack will hold all the grouped/entity anomalies
+   *
+   * Note the each time an entity copy is created, the children needs to be marked and set appropriately
+   *
+   */
+  private List<MergedAnomalyResultDTO> andGrouping(
+      List<MergedAnomalyResultDTO> anomalyListA, List<MergedAnomalyResultDTO> anomalyListB) {
+    Set<MergedAnomalyResultDTO> groupedAnomalies = new HashSet<>();
+    List<MergedAnomalyResultDTO> anomalies = mergeAndSortAnomalies(anomalyListA, anomalyListB);
+
+    Stack<MergedAnomalyResultDTO> anomalyStack = new Stack<>();
+    for (MergedAnomalyResultDTO anomaly : anomalies) {
+      if (anomalyStack.isEmpty()) {
+        anomalyStack.push(makeParentEntityAnomaly(anomaly));
+        continue;
+      }
+
+      MergedAnomalyResultDTO anomalyStackTop = anomalyStack.pop();
+
+      if (anomaly.getStartTime() > anomalyStackTop.getEndTime()) {
+        // No overlap
+        anomalyStack.push(makeParentEntityAnomaly(anomaly));
+      } else if (anomaly.getEndTime() > anomalyStackTop.getEndTime()) {
+        //Partial overlap
+        anomalyStackTop.setStartTime(anomaly.getStartTime());
+        setEntityChildMapping(anomalyStackTop, anomaly);
 
 Review comment:
   If partial overlap should update the endTime to the minimum of the anomalies.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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