Search in sources :

Example 36 with MetricConfigDTO

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

the class DashboardResource method getMaxTime.

@GET
@Path(value = "/data/info")
@Produces(MediaType.APPLICATION_JSON)
public String getMaxTime(@QueryParam("dataset") String collection) {
    String collectionInfo = null;
    try {
        HashMap<String, String> map = new HashMap<>();
        long maxDataTime = collectionMaxDataTimeCache.get(collection);
        DatasetConfigDTO datasetConfig = CACHE_REGISTRY_INSTANCE.getDatasetConfigCache().get(collection);
        TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
        TimeGranularity dataGranularity = timespec.getDataGranularity();
        map.put("maxTime", "" + maxDataTime);
        map.put("dataGranularity", dataGranularity.getUnit().toString());
        List<MetricConfigDTO> metricConfigs = metricConfigDAO.findActiveByDataset(collection);
        List<String> inverseMetrics = new ArrayList<>();
        for (MetricConfigDTO metricConfig : metricConfigs) {
            if (metricConfig.isInverseMetric()) {
                inverseMetrics.add(metricConfig.getName());
            }
        }
        if (CollectionUtils.isNotEmpty(inverseMetrics)) {
            map.put("invertColorMetrics", Joiner.on(",").join(inverseMetrics));
        }
        collectionInfo = OBJECT_MAPPER.writeValueAsString(map);
    } catch (Exception e) {
        LOG.error("Error while fetching info for collection: " + collection, e);
    }
    return collectionInfo;
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with MetricConfigDTO

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

the class DashboardResource method getMetrics.

@GET
@Path(value = "/data/metrics")
@Produces(MediaType.APPLICATION_JSON)
public List<String> getMetrics(@QueryParam("dataset") String collection) throws Exception {
    try {
        List<String> metrics = new ArrayList<>();
        List<MetricConfigDTO> metricConfigs = metricConfigDAO.findActiveByDataset(collection);
        for (MetricConfigDTO metricConfig : metricConfigs) {
            metrics.add(metricConfig.getName());
        }
        Collections.sort(metrics);
        return metrics;
    } catch (Exception e) {
        LOG.error("Error while fetching metrics", e);
        throw e;
    }
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with MetricConfigDTO

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

the class MetricConfigResource method getMetricsForDataset.

@GET
@Path("/metrics")
public String getMetricsForDataset(@NotNull @QueryParam("dataset") String dataset) {
    Map<String, Object> filters = new HashMap<>();
    filters.put("dataset", dataset);
    List<MetricConfigDTO> metricConfigDTOs = metricConfigDao.findByParams(filters);
    List<String> metrics = new ArrayList<>();
    for (MetricConfigDTO metricConfigDTO : metricConfigDTOs) {
        metrics.add(metricConfigDTO.getAlias());
    }
    return JsonResponseUtil.buildResponseJSON(metrics).toString();
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 39 with MetricConfigDTO

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

the class MetricConfigResource method viewMetricConfig.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewMetricConfig(@NotNull @QueryParam("dataset") String dataset, @DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
    Map<String, Object> filters = new HashMap<>();
    filters.put("dataset", dataset);
    List<MetricConfigDTO> metricConfigDTOs = metricConfigDao.findByParams(filters);
    List<MetricConfigDTO> subList = Utils.sublist(metricConfigDTOs, jtStartIndex, jtPageSize);
    ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
    return rootNode.toString();
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) ObjectNode(org.codehaus.jackson.node.ObjectNode) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with MetricConfigDTO

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

the class AutoloadPinotMetricsServiceTest method testAddNewDataset.

@Test
public void testAddNewDataset() throws Exception {
    testAutoLoadPinotMetricsService = new AutoLoadPinotMetricsService();
    schema = Schema.fromInputSteam(ClassLoader.getSystemResourceAsStream("sample-pinot-schema.json"));
    testAutoLoadPinotMetricsService.addPinotDataset(dataset, schema, datasetConfig);
    Assert.assertEquals(datasetConfigDAO.findAll().size(), 1);
    datasetConfig = datasetConfigDAO.findByDataset(dataset);
    Assert.assertEquals(datasetConfig.getDataset(), dataset);
    Assert.assertEquals(datasetConfig.getDimensions(), schema.getDimensionNames());
    Assert.assertEquals(datasetConfig.getTimeColumn(), schema.getTimeColumnName());
    TimeGranularitySpec timeGranularitySpec = schema.getTimeFieldSpec().getOutgoingGranularitySpec();
    Assert.assertEquals(datasetConfig.getTimeUnit(), timeGranularitySpec.getTimeType());
    Assert.assertEquals(datasetConfig.getTimeDuration(), new Integer(timeGranularitySpec.getTimeUnitSize()));
    Assert.assertEquals(datasetConfig.getTimeFormat(), timeGranularitySpec.getTimeFormat());
    Assert.assertEquals(datasetConfig.getTimezone(), "UTC");
    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 : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) ArrayList(java.util.ArrayList) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) Test(org.testng.annotations.Test)

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