vincentchenjl commented on a change in pull request #4724: [TE] Add event 
trigger listener for event driven scheduling
URL: https://github.com/apache/incubator-pinot/pull/4724#discussion_r341394043
 
 

 ##########
 File path: 
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/anomaly/detection/trigger/DataAvailabilityEventListener.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.pinot.thirdeye.anomaly.detection.trigger;
+
+import java.util.List;
+import 
org.apache.pinot.thirdeye.anomaly.detection.trigger.filter.DataAvailabilityEventFilter;
+import 
org.apache.pinot.thirdeye.anomaly.detection.trigger.utils.DatasetTriggerInfoRepo;
+import org.apache.pinot.thirdeye.anomaly.utils.ThirdeyeMetricsUtil;
+import org.apache.pinot.thirdeye.datalayer.bao.DatasetConfigManager;
+import org.apache.pinot.thirdeye.datasource.DAORegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is to listen to Kafka trigger events and update metadata in the 
metadata store based on the events,
+ * so that new anomaly detection can be trigger accordingly.
+ */
+public class DataAvailabilityEventListener implements Runnable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataAvailabilityEventListener.class);
+  private DataAvailabilityKafkaConsumer consumer;
+  private final List<DataAvailabilityEventFilter> filters;
+  private static final DAORegistry DAO_REGISTRY = DAORegistry.getInstance();
+  private DatasetTriggerInfoRepo datasetTriggerInfoRepo;
+  private DatasetConfigManager datasetConfigManager;
+  private long sleepTimeInMilli;
+  private long pollTimeInMilli;
+
+  public DataAvailabilityEventListener(DataAvailabilityKafkaConsumer consumer, 
List<DataAvailabilityEventFilter> filters,
+      long sleepTimeInMilli, long pollTimeInMilli) {
+    this.consumer = consumer;
+    this.filters = filters;
+    this.datasetConfigManager = DAO_REGISTRY.getDatasetConfigDAO();
+    this.datasetTriggerInfoRepo = DatasetTriggerInfoRepo.getInstance();
+    this.sleepTimeInMilli = sleepTimeInMilli;
+    this.pollTimeInMilli = pollTimeInMilli;
+  }
+
+  @Override
+  public void run() {
+    try {
+      while (!(Thread.interrupted())) {
+        processOneBatch();
+      }
+    } catch (InterruptedException e) {
+      LOG.error("Caught Interrupted Exception", e);
+    } finally {
+      consumer.close();
+    }
+    LOG.info("TriggerEventListener under thread {} is closed.", 
Thread.currentThread().getName());
+  }
+
+  public void close() {
+    datasetTriggerInfoRepo.close();
+  }
+
+  void processOneBatch() throws InterruptedException {
+    List<DataAvailabilityEvent> events = consumer.poll(pollTimeInMilli);
+    ThirdeyeMetricsUtil.triggerEventCounter.inc(events.size());
+    for (DataAvailabilityEvent event : events) {
+      if (checkAllFiltersPassed(event)) {
+        LOG.info("Processing event: " + event.getDatasetName() + " with 
watermark " + event.getHighWatermark());
+        String dataset = event.getDatasetName();
+        datasetTriggerInfoRepo.setLastUpdateTimestamp(dataset, 
event.getHighWatermark());
+        //TODO: Batch update the timestamps of dataset
 
 Review comment:
   Removed

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to