Search in sources :

Example 41 with MetricConfigDTO

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

the class AutoloadPinotMetricsServiceTest method testRefreshDataset.

@Test(dependsOnMethods = { "testAddNewDataset" })
public void testRefreshDataset() throws Exception {
    DimensionFieldSpec dimensionFieldSpec = new DimensionFieldSpec("newDimension", DataType.STRING, true);
    schema.addField(dimensionFieldSpec);
    testAutoLoadPinotMetricsService.addPinotDataset(dataset, schema, datasetConfig);
    Assert.assertEquals(datasetConfigDAO.findAll().size(), 1);
    DatasetConfigDTO newDatasetConfig1 = datasetConfigDAO.findByDataset(dataset);
    Assert.assertEquals(newDatasetConfig1.getDataset(), dataset);
    Assert.assertEquals(Sets.newHashSet(newDatasetConfig1.getDimensions()), Sets.newHashSet(schema.getDimensionNames()));
    MetricFieldSpec metricFieldSpec = new MetricFieldSpec("newMetric", DataType.LONG);
    schema.addField(metricFieldSpec);
    testAutoLoadPinotMetricsService.addPinotDataset(dataset, schema, newDatasetConfig1);
    Assert.assertEquals(datasetConfigDAO.findAll().size(), 1);
    List<MetricConfigDTO> metricConfigs = metricConfigDAO.findByDataset(dataset);
    List<String> schemaMetricNames = schema.getMetricNames();
    List<Long> metricIds = new ArrayList<>();
    Assert.assertEquals(metricConfigs.size(), schemaMetricNames.size());
    for (MetricConfigDTO metricConfig : metricConfigs) {
        Assert.assertTrue(schemaMetricNames.contains(metricConfig.getName()));
        metricIds.add(metricConfig.getId());
    }
    DashboardConfigDTO dashboardConfig = dashboardConfigDAO.findByName(DashboardConfigBean.DEFAULT_DASHBOARD_PREFIX + dataset);
    Assert.assertEquals(dashboardConfig.getMetricIds(), metricIds);
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) ArrayList(java.util.ArrayList) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) Test(org.testng.annotations.Test)

Example 42 with MetricConfigDTO

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

the class ThirdEyeUtils method substituteMetricIdsForMetrics.

// TODO: Write parser instead of looking for occurrence of every metric
public static String substituteMetricIdsForMetrics(String metricExpression, String dataset) {
    MetricConfigManager metricConfigDAO = DAO_REGISTRY.getMetricConfigDAO();
    List<MetricConfigDTO> metricConfigs = metricConfigDAO.findByDataset(dataset);
    for (MetricConfigDTO metricConfig : metricConfigs) {
        if (metricConfig.isDerived()) {
            continue;
        }
        String metricName = metricConfig.getName();
        metricExpression = metricExpression.replaceAll(metricName, MetricConfigBean.DERIVED_METRIC_ID_PREFIX + metricConfig.getId());
    }
    return metricExpression;
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) MetricConfigManager(com.linkedin.thirdeye.datalayer.bao.MetricConfigManager)

Example 43 with MetricConfigDTO

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

the class ThirdEyeUtils method getMetricThresholdsMap.

public static Map<String, Double> getMetricThresholdsMap(List<MetricFunction> metricFunctions) {
    Map<String, Double> metricThresholds = new HashMap<>();
    for (MetricFunction metricFunction : metricFunctions) {
        String derivedMetricExpression = metricFunction.getMetricName();
        String metricId = derivedMetricExpression.replaceAll(MetricConfigBean.DERIVED_METRIC_ID_PREFIX, "");
        MetricConfigDTO metricConfig = DAO_REGISTRY.getMetricConfigDAO().findById(Long.valueOf(metricId));
        metricThresholds.put(derivedMetricExpression, metricConfig.getRollupThreshold());
    }
    return metricThresholds;
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) HashMap(java.util.HashMap) MetricFunction(com.linkedin.thirdeye.client.MetricFunction)

Example 44 with MetricConfigDTO

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

the class AnomaliesResource method getExternalURL.

private String getExternalURL(MergedAnomalyResultDTO mergedAnomaly) {
    String metric = mergedAnomaly.getMetric();
    String dataset = mergedAnomaly.getCollection();
    Long startTime = mergedAnomaly.getStartTime();
    Long endTime = mergedAnomaly.getEndTime();
    MetricConfigDTO metricConfigDTO = metricConfigDAO.findByMetricAndDataset(metric, dataset);
    Map<String, String> context = new HashMap<>();
    context.put(MetricConfigBean.URL_TEMPLATE_START_TIME, String.valueOf(startTime));
    context.put(MetricConfigBean.URL_TEMPLATE_END_TIME, String.valueOf(endTime));
    StrSubstitutor strSubstitutor = new StrSubstitutor(context);
    Map<String, String> urlTemplates = metricConfigDTO.getExtSourceLinkInfo();
    if (urlTemplates == null) {
        return "";
    }
    for (Map.Entry<String, String> entry : urlTemplates.entrySet()) {
        String sourceName = entry.getKey();
        String urlTemplate = entry.getValue();
        String extSourceUrl = strSubstitutor.replace(urlTemplate);
        urlTemplates.put(sourceName, extSourceUrl);
    }
    return new JSONObject(urlTemplates).toString();
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) DimensionMap(com.linkedin.thirdeye.api.DimensionMap)

Example 45 with MetricConfigDTO

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

the class DataResource method getDataAggregationGranularity.

@GET
@Path("agg/granularity/metric/{metricId}")
public List<String> getDataAggregationGranularity(@PathParam("metricId") Long metricId) {
    List<String> list = new ArrayList<>();
    list.add("DAYS");
    MetricConfigDTO metricConfigDTO = metricConfigDAO.findById(metricId);
    DatasetConfigDTO datasetConfigDTO = datasetConfigDAO.findByDataset(metricConfigDTO.getDataset());
    int dataAggSize = datasetConfigDTO.getTimeDuration();
    String dataGranularity = datasetConfigDTO.getTimeUnit().name();
    if (dataGranularity.equals("DAYS")) {
    // do nothing
    } else {
        list.add("HOURS");
        if (dataGranularity.equals("MINUTES")) {
            if (dataAggSize == 1) {
                list.add("MINUTES");
            } else {
                list.add(dataAggSize + "_MINUTES");
            }
        }
    }
    return list;
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)54 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)18 GET (javax.ws.rs.GET)17 HashMap (java.util.HashMap)13 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)9 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)7 MetricDataset (com.linkedin.thirdeye.client.cache.MetricDataset)7 DateTime (org.joda.time.DateTime)7 DateTimeZone (org.joda.time.DateTimeZone)7 MetricConfigBean (com.linkedin.thirdeye.datalayer.pojo.MetricConfigBean)6 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)5 IOException (java.io.IOException)5 LinkedHashMap (java.util.LinkedHashMap)5 Test (org.testng.annotations.Test)5 MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)4 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 ExecutionException (java.util.concurrent.ExecutionException)4