Search in sources :

Example 16 with DashboardConfigDTO

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

the class AutoLoadPinotMetricsService method checkMetricAsDimensionDataset.

private void checkMetricAsDimensionDataset(DatasetConfigDTO datasetConfigDTO, Schema schema) {
    String dataset = datasetConfigDTO.getDataset();
    String metricNamesColumn = datasetConfigDTO.getMetricNamesColumn();
    String metricValuesColumn = datasetConfigDTO.getMetricValuesColumn();
    FieldSpec metricValuesColumnFieldSpec = schema.getFieldSpecFor(metricValuesColumn);
    String dashboardName = ThirdEyeUtils.getDefaultDashboardName(dataset);
    // remove metricNamesColumn from dimensions if exists
    List<String> dimensions = datasetConfigDTO.getDimensions();
    if (dimensions.contains(metricNamesColumn)) {
        dimensions.removeAll(Lists.newArrayList(metricNamesColumn));
        datasetConfigDTO.setDimensions(dimensions);
        DAO_REGISTRY.getDatasetConfigDAO().update(datasetConfigDTO);
    }
    // remove metricValuesColumn from metrics if exists
    MetricConfigDTO metricConfigDTO = DAO_REGISTRY.getMetricConfigDAO().findByMetricAndDataset(metricValuesColumn, dataset);
    if (metricConfigDTO != null) {
        Long metricId = metricConfigDTO.getId();
        DAO_REGISTRY.getMetricConfigDAO().delete(metricConfigDTO);
        // remove metricValuesColumn id from default dashboard
        DashboardConfigDTO dashboardConfig = DAO_REGISTRY.getDashboardConfigDAO().findByName(dashboardName);
        List<Long> dashboardMetricIds = dashboardConfig.getMetricIds();
        dashboardMetricIds.removeAll(Lists.newArrayList(metricId));
        LOG.info("Updating dashboard config for {}", dashboardName);
        DAO_REGISTRY.getDashboardConfigDAO().update(dashboardConfig);
    }
    if (datasetConfigDTO.isAutoDiscoverMetrics()) {
        // query pinot to fetch distinct metricNamesColumn
        List<String> allDistinctMetricNames = fetchMetricAsADimensionMetrics(dataset, metricNamesColumn);
        // create metrics for these metric names, if they dont exist
        List<MetricConfigDTO> existingMetricConfigs = DAO_REGISTRY.getMetricConfigDAO().findByDataset(dataset);
        List<String> existingMetricNames = Lists.newArrayList();
        for (MetricConfigDTO existingMetricConfig : existingMetricConfigs) {
            existingMetricNames.add(existingMetricConfig.getName());
        }
        allDistinctMetricNames.removeAll(existingMetricNames);
        for (String metricName : allDistinctMetricNames) {
            LOG.info("Creating metric config for {}", metricName);
            MetricFieldSpec metricFieldSpec = new MetricFieldSpec(metricName, metricValuesColumnFieldSpec.getDataType());
            MetricConfigDTO metricConfig = ConfigGenerator.generateMetricConfig(metricFieldSpec, dataset);
            DAO_REGISTRY.getMetricConfigDAO().save(metricConfig);
        }
        // Add metrics to default dashboard
        List<Long> allMetricIds = ConfigGenerator.getMetricIdsFromMetricConfigs(DAO_REGISTRY.getMetricConfigDAO().findByDataset(dataset));
        DashboardConfigDTO dashboardConfig = DAO_REGISTRY.getDashboardConfigDAO().findByName(dashboardName);
        dashboardConfig.setMetricIds(allMetricIds);
        LOG.info("Creating dashboard config for {}", dashboardName);
        DAO_REGISTRY.getDashboardConfigDAO().update(dashboardConfig);
    }
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec)

Example 17 with DashboardConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO 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)

Example 18 with DashboardConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO 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)

Aggregations

DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)18 ArrayList (java.util.ArrayList)9 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)8 MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)4 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)4 DashboardConfigBean (com.linkedin.thirdeye.datalayer.pojo.DashboardConfigBean)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)3 IOException (java.io.IOException)2 Test (org.testng.annotations.Test)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 LoadingCache (com.google.common.cache.LoadingCache)1 RemovalListener (com.google.common.cache.RemovalListener)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 DimensionFieldSpec (com.linkedin.pinot.common.data.DimensionFieldSpec)1 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)1 TimeGranularitySpec (com.linkedin.pinot.common.data.TimeGranularitySpec)1 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)1