You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ji...@apache.org on 2019/06/03 18:49:38 UTC

[incubator-pinot] branch master updated: [TE] detection config semantic validation fix (#4267)

This is an automated email from the ASF dual-hosted git repository.

jihao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 55a20b2  [TE] detection config semantic validation fix (#4267)
55a20b2 is described below

commit 55a20b2d6b394482ea6beb57f10fb89de93368db
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Mon Jun 3 11:49:32 2019 -0700

    [TE] detection config semantic validation fix (#4267)
    
    Detection config semantic validation is called before tuning, and it will throw an exception. This PR fixes the issue.
---
 .../thirdeye/detection/yaml/DetectionConfigTuner.java      |  4 +++-
 .../apache/pinot/thirdeye/detection/yaml/YamlResource.java | 14 +++++++-------
 .../detection/yaml/translator/ConfigTranslator.java        |  5 +----
 .../translator/YamlDetectionAlertConfigTranslator.java     |  2 +-
 .../yaml/translator/YamlDetectionConfigTranslator.java     |  2 +-
 5 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/DetectionConfigTuner.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/DetectionConfigTuner.java
index ded20cc..44415fa 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/DetectionConfigTuner.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/DetectionConfigTuner.java
@@ -32,6 +32,7 @@ import org.apache.pinot.thirdeye.datalayer.dto.MetricConfigDTO;
 import org.apache.pinot.thirdeye.detection.ConfigUtils;
 import org.apache.pinot.thirdeye.detection.DataProvider;
 import org.apache.pinot.thirdeye.detection.DefaultInputDataFetcher;
+import org.apache.pinot.thirdeye.detection.DetectionPipelineLoader;
 import org.apache.pinot.thirdeye.detection.DetectionUtils;
 import org.apache.pinot.thirdeye.detection.InputDataFetcher;
 import org.apache.pinot.thirdeye.detection.annotation.registry.DetectionRegistry;
@@ -80,6 +81,7 @@ public class DetectionConfigTuner {
   private final String metricUrn;
 
   public DetectionConfigTuner(DetectionConfigDTO config, DataProvider dataProvider) {
+    Preconditions.checkNotNull(config);
     this.detectionConfig = config;
     this.dataProvider = dataProvider;
 
@@ -108,7 +110,7 @@ public class DetectionConfigTuner {
     Map<String, Object> tunedSpec = new HashMap<>();
 
     // Instantiate tunable component
-    long configId = detectionConfig == null ? 0 : detectionConfig.getId();
+    long configId = detectionConfig.getId() == null ? 0 : detectionConfig.getId();
     String componentClassName = componentProps.get(PROP_CLASS_NAME).toString();
     Map<String, Object> yamlParams = ConfigUtils.getMap(componentProps.get(PROP_YAML_PARAMS));
     InputDataFetcher dataFetcher = new DefaultInputDataFetcher(dataProvider, configId);
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
index a247b71..6b5dde0 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
@@ -165,17 +165,18 @@ public class YamlResource {
     }
 
     // Translate the raw yaml config to detection config object
-    DetectionConfigDTO config = (DetectionConfigDTO) detectionConfigTranslator.translate();
-
-    // Tune the detection config - Passes the raw yaml params & injects tuned params
-    DetectionConfigTuner detectionTuner = new DetectionConfigTuner(config, provider);
-    config = detectionTuner.tune(tuningStartTime, tuningEndTime);
+    DetectionConfigDTO config = detectionConfigTranslator.translate();
 
     if (existingConfig != null) {
       config.setId(existingConfig.getId());
       config.setLastTimestamp(existingConfig.getLastTimestamp());
       config.setCreatedBy(existingConfig.getCreatedBy());
     }
+
+    // Tune the detection config - Passes the raw yaml params & injects tuned params
+    DetectionConfigTuner detectionTuner = new DetectionConfigTuner(config, provider);
+    config = detectionTuner.tune(tuningStartTime, tuningEndTime);
+    this.detectionValidator.validateConfig(config);
     return config;
   }
 
@@ -501,8 +502,7 @@ public class YamlResource {
     // Translate payload to detection alert config
     TreeMap<String, Object> newAlertConfigMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
     newAlertConfigMap.putAll(ConfigUtils.getMap(this.yaml.load(yamlAlertConfig)));
-    DetectionAlertConfigDTO newAlertConfig = (DetectionAlertConfigDTO)
-        new YamlDetectionAlertConfigTranslator(detectionConfigDAO, newAlertConfigMap).translate();
+    DetectionAlertConfigDTO newAlertConfig = new YamlDetectionAlertConfigTranslator(detectionConfigDAO, newAlertConfigMap).translate();
 
     // Update existing alert config with the newly supplied config.
     DetectionAlertConfigDTO updatedAlertConfig = updateDetectionAlertConfig(oldAlertConfig, newAlertConfig);
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/ConfigTranslator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/ConfigTranslator.java
index b6e93e9..e4d7953 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/ConfigTranslator.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/ConfigTranslator.java
@@ -47,9 +47,6 @@ public abstract class ConfigTranslator<T extends AbstractDTO, V extends ConfigVa
    */
   public T translate() throws IllegalArgumentException {
     validator.validateYaml(this.yamlConfig);
-    T configDTO = this.translateConfig();
-    validator.validateConfig(configDTO);
-
-    return configDTO;
+    return this.translateConfig();
   }
 }
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionAlertConfigTranslator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionAlertConfigTranslator.java
index e424d77..5efab02 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionAlertConfigTranslator.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionAlertConfigTranslator.java
@@ -45,7 +45,7 @@ import org.yaml.snakeyaml.Yaml;
 /**
  * The translator converts the alert yaml config into a detection alert config
  */
-public class YamlDetectionAlertConfigTranslator extends ConfigTranslator {
+public class YamlDetectionAlertConfigTranslator extends ConfigTranslator<DetectionAlertConfigDTO, SubscriptionConfigValidator> {
   public static final String PROP_DETECTION_CONFIG_IDS = "detectionConfigIds";
   public static final String PROP_RECIPIENTS = "recipients";
 
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionConfigTranslator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionConfigTranslator.java
index dfcc4b1..4b8fa34 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionConfigTranslator.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/translator/YamlDetectionConfigTranslator.java
@@ -34,7 +34,7 @@ import org.yaml.snakeyaml.Yaml;
  * The YAML config translator converts the yaml config into a detection config.
  * Calls training module for each stage.
  */
-public abstract class YamlDetectionConfigTranslator extends ConfigTranslator {
+public abstract class YamlDetectionConfigTranslator extends ConfigTranslator<DetectionConfigDTO, DetectionConfigValidator> {
   protected static final Logger LOG = LoggerFactory.getLogger(YamlDetectionConfigTranslator.class);
   private static final String PROP_NAME = "detectionName";
   private static final String PROP_DESC_NAME = "description";


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