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/11 18:02:47 UTC

[GitHub] [incubator-pinot] akshayrai commented on a change in pull request #4266: [TE] Detection model maintenance flow

akshayrai commented on a change in pull request #4266: [TE] Detection model maintenance flow
URL: https://github.com/apache/incubator-pinot/pull/4266#discussion_r292589601
 
 

 ##########
 File path: thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DefaultModelMaintenanceFlow.java
 ##########
 @@ -0,0 +1,110 @@
+/*
+ *
+ *  * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.stream.Collectors;
+import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO;
+import org.apache.pinot.thirdeye.detection.annotation.registry.DetectionRegistry;
+import org.apache.pinot.thirdeye.detection.components.MapeAveragePercentageChangeModelEvaluator;
+import org.apache.pinot.thirdeye.detection.spec.AbstractSpec;
+import org.apache.pinot.thirdeye.detection.spec.MapeAveragePercentageChangeModelEvaluatorSpec;
+import org.apache.pinot.thirdeye.detection.spi.components.ModelEvaluator;
+import org.apache.pinot.thirdeye.detection.spi.model.ModelStatus;
+import org.apache.pinot.thirdeye.detection.yaml.DetectionConfigTuner;
+import org.joda.time.Instant;
+
+
+/**
+ * The default model maintenance flow. If the model is tunable, this flow will run the configured model evaluators for
+ * the detection config and automatically re-tunes the model.
+ */
+public class DefaultModelMaintenanceFlow implements ModelMaintenanceFlow {
+  private static final int DEFAULT_TUNING_WINDOW_DAYS = 28;
+
+  private final DataProvider provider;
+  private final DetectionRegistry detectionRegistry;
+
+  DefaultModelMaintenanceFlow(DataProvider provider, DetectionRegistry detectionRegistry) {
+    this.provider = provider;
+    this.detectionRegistry = detectionRegistry;
+  }
+
+  public DetectionConfigDTO maintain(DetectionConfigDTO config, Instant timestamp) {
+    if (isTunable(config)) {
+      // if the pipeline is tunable, get the model evaluators
+      Collection<? extends ModelEvaluator<? extends AbstractSpec>> modelEvaluators = getModelEvaluators(config);
+      // check the status for model evaluators
+      for (ModelEvaluator<? extends AbstractSpec> modelEvaluator : modelEvaluators) {
+        // if returns bad model status, trigger model tuning
+        if (modelEvaluator.evaluateModel(timestamp).getStatus().equals(ModelStatus.BAD)) {
+          DetectionConfigTuner detectionConfigTuner = new DetectionConfigTuner(config, provider);
+          config = detectionConfigTuner.tune(timestamp.toDateTime().minusDays(DEFAULT_TUNING_WINDOW_DAYS).getMillis(),
+              timestamp.getMillis());
+          config.setLastTuningTimestamp(timestamp.getMillis());
 
 Review comment:
   Agree! it will be good to somehow track this. We shouldn't end up repeatedly calling retune after every detection.

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