Search in sources :

Example 11 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class TestOverrideConfigHelper method TestTargetEntityLevel.

@Test
public void TestTargetEntityLevel() {
    OverrideConfigDTO overrideConfigDTO = new OverrideConfigDTO();
    Map<String, List<String>> overrideTarget = new HashMap<>();
    overrideTarget.put(OverrideConfigHelper.TARGET_COLLECTION, Arrays.asList("collection1"));
    overrideTarget.put(OverrideConfigHelper.TARGET_METRIC, Arrays.asList("metric1", "metric2"));
    overrideTarget.put(OverrideConfigHelper.EXCLUDED_METRIC, Arrays.asList("metric3"));
    overrideConfigDTO.setTargetLevel(overrideTarget);
    // Test "Only include any entity whose level has collection1, metric 1, metric 2, but not
    // metric3"
    Map<String, String> entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric1", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric3", 1);
    Assert.assertFalse(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection11", "metric2", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection11", "metric11", 1);
    Assert.assertFalse(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    // Test "Only include any entity whose level has collection1, metric 1, metric 2"
    overrideTarget = new HashMap<>();
    overrideTarget.put(OverrideConfigHelper.TARGET_COLLECTION, Arrays.asList("collection1"));
    overrideTarget.put(OverrideConfigHelper.TARGET_METRIC, Arrays.asList("metric1", "metric2"));
    overrideConfigDTO.setTargetLevel(overrideTarget);
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric1", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric3", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection11", "metric2", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection11", "metric11", 1);
    Assert.assertFalse(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    // Test "Include everything but collection3"
    overrideTarget = new HashMap<>();
    overrideTarget.put(OverrideConfigHelper.EXCLUDED_COLLECTION, Arrays.asList("collection3"));
    overrideConfigDTO.setTargetLevel(overrideTarget);
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric1", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection1", "metric3", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection11", "metric2", 1);
    Assert.assertTrue(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
    entityTargetLevel = OverrideConfigHelper.getEntityTargetLevel("collection3", "metric2", 1);
    Assert.assertFalse(OverrideConfigHelper.isEnabled(entityTargetLevel, overrideConfigDTO));
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) HashMap(java.util.HashMap) List(java.util.List) Test(org.testng.annotations.Test)

Example 12 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class OverrideConfigResource method updateOverrideConfig.

@POST
@Path("/override-config/update")
public Response updateOverrideConfig(@NotNull @QueryParam("id") long id, @NotNull @QueryParam("startTime") long startTimeMillis, @NotNull @QueryParam("endTime") long endTimeMillis, @QueryParam("targetLevel") String targetLevelJson, @NotNull @QueryParam("targetEntity") String targetEntity, @QueryParam("overrideProperties") String overridePropertiesJson, @QueryParam("active") boolean active) {
    Map<String, List<String>> targetLevel;
    if (StringUtils.isEmpty(targetLevelJson)) {
        targetLevel = Collections.emptyMap();
    } else {
        try {
            targetLevel = OBJECT_MAPPER.readValue(targetLevelJson, HashMap.class);
        } catch (IOException e) {
            LOG.error("Invalid JSON string {}", targetLevelJson);
            return Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
    }
    if (StringUtils.isEmpty(targetEntity)) {
        LOG.error("Received null for one of the mandatory params \"targetEntity\": {}", targetEntity);
        return Response.status(Response.Status.NOT_ACCEPTABLE).build();
    }
    Map<String, String> overrideProperties;
    if (StringUtils.isEmpty(overridePropertiesJson)) {
        overrideProperties = Collections.emptyMap();
    } else {
        try {
            overrideProperties = OBJECT_MAPPER.readValue(overridePropertiesJson, HashMap.class);
        } catch (IOException e) {
            LOG.error("Invalid JSON string {}", overridePropertiesJson);
            return Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
    }
    OverrideConfigManager overrideConfigDAO = DAO_REGISTRY.getOverrideConfigDAO();
    OverrideConfigDTO overrideConfigDTO = overrideConfigDAO.findById(id);
    if (overrideConfigDTO == null) {
        LOG.error("Unable to find override config with id {}", id);
        return Response.status(Response.Status.NOT_ACCEPTABLE).build();
    }
    overrideConfigDTO.setStartTime(startTimeMillis);
    overrideConfigDTO.setEndTime(endTimeMillis);
    overrideConfigDTO.setTargetLevel(targetLevel);
    overrideConfigDTO.setTargetEntity(targetEntity);
    overrideConfigDTO.setOverrideProperties(overrideProperties);
    overrideConfigDTO.setActive(active);
    overrideConfigDAO.update(overrideConfigDTO);
    return Response.ok().build();
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) HashMap(java.util.HashMap) List(java.util.List) IOException(java.io.IOException) OverrideConfigManager(com.linkedin.thirdeye.datalayer.bao.OverrideConfigManager) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

OverrideConfigDTO (com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO)12 HashMap (java.util.HashMap)5 List (java.util.List)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 OverrideConfigManager (com.linkedin.thirdeye.datalayer.bao.OverrideConfigManager)2 Path (javax.ws.rs.Path)2 AlertConfigDTO (com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)1 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)1 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)1 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)1 EmailConfigurationDTO (com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 OverrideConfigBean (com.linkedin.thirdeye.datalayer.pojo.OverrideConfigBean)1 ScalingFactor (com.linkedin.thirdeye.detector.metric.transfer.ScalingFactor)1 HashSet (java.util.HashSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1