Search in sources :

Example 26 with MetricExpression

use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.

the class SummaryResource method buildSummaryManualDimensionOrder.

@GET
@Path(value = "/summary/manualDimensionOrder")
@Produces(MediaType.APPLICATION_JSON)
public String buildSummaryManualDimensionOrder(@QueryParam("dataset") String collection, @QueryParam("metric") String metric, @QueryParam("currentStart") Long currentStartInclusive, @QueryParam("currentEnd") Long currentEndExclusive, @QueryParam("baselineStart") Long baselineStartInclusive, @QueryParam("baselineEnd") Long baselineEndExclusive, @QueryParam("dimensions") String groupByDimensions, @QueryParam("summarySize") int summarySize, @QueryParam("oneSideError") @DefaultValue(DEFAULT_ONE_SIDE_ERROR) boolean doOneSideError, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone) throws Exception {
    if (summarySize < 1)
        summarySize = 1;
    SummaryResponse response = null;
    try {
        List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metric, MetricAggFunction.SUM, collection);
        OLAPDataBaseClient olapClient = new PinotThirdEyeSummaryClient(CACHE_REGISTRY_INSTANCE.getQueryCache());
        olapClient.setCollection(collection);
        olapClient.setMetricExpression(metricExpressions.get(0));
        olapClient.setCurrentStartInclusive(new DateTime(currentStartInclusive, DateTimeZone.forID(timeZone)));
        olapClient.setCurrentEndExclusive(new DateTime(currentEndExclusive, DateTimeZone.forID(timeZone)));
        olapClient.setBaselineStartInclusive(new DateTime(baselineStartInclusive, DateTimeZone.forID(timeZone)));
        olapClient.setBaselineEndExclusive(new DateTime(baselineEndExclusive, DateTimeZone.forID(timeZone)));
        List<String> allDimensions;
        if (groupByDimensions == null || groupByDimensions.length() == 0 || groupByDimensions.equals("undefined")) {
            allDimensions = Utils.getSchemaDimensionNames(collection);
        } else {
            allDimensions = Arrays.asList(groupByDimensions.trim().split(","));
        }
        if (allDimensions.size() > Integer.parseInt(DEFAULT_TOP_DIMENSIONS)) {
            allDimensions = allDimensions.subList(0, Integer.parseInt(DEFAULT_TOP_DIMENSIONS));
        }
        Dimensions dimensions = new Dimensions(allDimensions);
        Cube cube = new Cube();
        cube.buildWithManualDimensionOrder(olapClient, dimensions);
        Summary summary = new Summary(cube);
        response = summary.computeSummary(summarySize, doOneSideError);
        response.setMetricName(metric);
    } catch (Exception e) {
        LOG.error("Exception while generating difference summary", e);
        response = SummaryResponse.buildNotAvailableResponse();
    }
    return OBJECT_MAPPER.writeValueAsString(response);
}
Also used : SummaryResponse(com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse) Cube(com.linkedin.thirdeye.client.diffsummary.Cube) OLAPDataBaseClient(com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient) Dimensions(com.linkedin.thirdeye.client.diffsummary.Dimensions) Summary(com.linkedin.thirdeye.dashboard.views.diffsummary.Summary) PinotThirdEyeSummaryClient(com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with MetricExpression

use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.

the class DashboardResource method getTimeSeriesData.

@GET
@Path(value = "/data/timeseries")
@Produces(MediaType.APPLICATION_JSON)
public String getTimeSeriesData(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("currentStart") Long start, @QueryParam("currentEnd") Long end, @QueryParam("aggTimeGranularity") String aggTimeGranularity, @QueryParam("metrics") String metricsJson, @QueryParam("dimensions") String groupByDimensions) throws Exception {
    TimeSeriesRequest request = new TimeSeriesRequest();
    request.setCollectionName(collection);
    // See {@link #getDashboardData} for the reason that the start and end time are stored in a
    // DateTime object with data's timezone.
    DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
    request.setStart(new DateTime(start, timeZoneForCollection));
    request.setEnd(new DateTime(end, timeZoneForCollection));
    if (groupByDimensions != null && !groupByDimensions.isEmpty()) {
        request.setGroupByDimensions(Arrays.asList(groupByDimensions.trim().split(",")));
    }
    if (filterJson != null && !filterJson.isEmpty()) {
        filterJson = URLDecoder.decode(filterJson, "UTF-8");
        request.setFilterSet(ThirdEyeUtils.convertToMultiMap(filterJson));
    }
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
    request.setMetricExpressions(metricExpressions);
    request.setAggregationTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
    DatasetConfigDTO datasetConfig = CACHE_REGISTRY_INSTANCE.getDatasetConfigCache().get(collection);
    TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
    if (!request.getAggregationTimeGranularity().getUnit().equals(TimeUnit.DAYS) || !StringUtils.isBlank(timespec.getFormat())) {
        request.setEndDateInclusive(true);
    }
    TimeSeriesHandler handler = new TimeSeriesHandler(queryCache);
    String jsonResponse = "";
    try {
        TimeSeriesResponse response = handler.handle(request);
        JSONObject timeseriesMap = new JSONObject();
        JSONArray timeValueArray = new JSONArray();
        TreeSet<String> keys = new TreeSet<>();
        TreeSet<Long> times = new TreeSet<>();
        for (int i = 0; i < response.getNumRows(); i++) {
            TimeSeriesRow timeSeriesRow = response.getRow(i);
            times.add(timeSeriesRow.getStart());
        }
        for (Long time : times) {
            timeValueArray.put(time);
        }
        timeseriesMap.put("time", timeValueArray);
        for (int i = 0; i < response.getNumRows(); i++) {
            TimeSeriesRow timeSeriesRow = response.getRow(i);
            for (TimeSeriesMetric metricTimeSeries : timeSeriesRow.getMetrics()) {
                String key = metricTimeSeries.getMetricName();
                if (timeSeriesRow.getDimensionNames() != null && timeSeriesRow.getDimensionNames().size() > 0) {
                    StringBuilder sb = new StringBuilder(key);
                    for (int idx = 0; idx < timeSeriesRow.getDimensionNames().size(); ++idx) {
                        sb.append("||").append(timeSeriesRow.getDimensionNames().get(idx));
                        sb.append("|").append(timeSeriesRow.getDimensionValues().get(idx));
                    }
                    key = sb.toString();
                }
                JSONArray valueArray;
                if (!timeseriesMap.has(key)) {
                    valueArray = new JSONArray();
                    timeseriesMap.put(key, valueArray);
                    keys.add(key);
                } else {
                    valueArray = timeseriesMap.getJSONArray(key);
                }
                valueArray.put(metricTimeSeries.getValue());
            }
        }
        JSONObject summaryMap = new JSONObject();
        summaryMap.put("currentStart", start);
        summaryMap.put("currentEnd", end);
        JSONObject jsonResponseObject = new JSONObject();
        jsonResponseObject.put("timeSeriesData", timeseriesMap);
        jsonResponseObject.put("keys", new JSONArray(keys));
        jsonResponseObject.put("summary", summaryMap);
        jsonResponse = jsonResponseObject.toString();
    } catch (Exception e) {
        throw e;
    }
    LOG.info("Response:{}", jsonResponse);
    return jsonResponse;
}
Also used : TimeSeriesRow(com.linkedin.thirdeye.client.timeseries.TimeSeriesRow) TimeSeriesResponse(com.linkedin.thirdeye.client.timeseries.TimeSeriesResponse) JSONArray(org.json.JSONArray) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) JSONObject(org.json.JSONObject) TimeSeriesHandler(com.linkedin.thirdeye.client.timeseries.TimeSeriesHandler) TreeSet(java.util.TreeSet) TimeSeriesMetric(com.linkedin.thirdeye.client.timeseries.TimeSeriesRow.TimeSeriesMetric) TimeSeriesRequest(com.linkedin.thirdeye.client.timeseries.TimeSeriesRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with MetricExpression

use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.

the class DashboardResource method getHeatMap.

@GET
@Path(value = "/data/heatmap")
@Produces(MediaType.APPLICATION_JSON)
public String getHeatMap(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("metrics") String metricsJson) throws Exception {
    HeatMapViewRequest request = new HeatMapViewRequest();
    request.setCollection(collection);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
    request.setMetricExpressions(metricExpressions);
    long maxDataTime = collectionMaxDataTimeCache.get(collection);
    if (currentEnd > maxDataTime) {
        long delta = currentEnd - maxDataTime;
        currentEnd = currentEnd - delta;
        baselineEnd = baselineEnd - delta;
    }
    // See {@link #getDashboardData} for the reason that the start and end time are stored in a
    // DateTime object with data's timezone.
    DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
    request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
    request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
    request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
    request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
    // filter
    if (filterJson != null && !filterJson.isEmpty()) {
        filterJson = URLDecoder.decode(filterJson, "UTF-8");
        request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
    }
    HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
    HeatMapViewResponse response;
    String jsonResponse = null;
    try {
        response = handler.process(request);
        jsonResponse = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(response);
        LOG.debug("Heatmap response {}", jsonResponse);
    } catch (Exception e) {
        LOG.error("Error generating heatmap response", e);
    }
    return jsonResponse;
}
Also used : HeatMapViewResponse(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse) HeatMapViewRequest(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewRequest) HeatMapViewHandler(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) 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 29 with MetricExpression

use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.

the class DashboardResource method getContributorData.

@GET
@Path(value = "/data/contributor")
@Produces(MediaType.APPLICATION_JSON)
public String getContributorData(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("aggTimeGranularity") String aggTimeGranularity, @QueryParam("metrics") String metricsJson, @QueryParam("dimensions") String groupByDimensions) throws Exception {
    ContributorViewRequest request = new ContributorViewRequest();
    request.setCollection(collection);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
    request.setMetricExpressions(metricExpressions);
    long maxDataTime = collectionMaxDataTimeCache.get(collection);
    if (currentEnd > maxDataTime) {
        long delta = currentEnd - maxDataTime;
        currentEnd = currentEnd - delta;
        baselineEnd = baselineEnd - delta;
    }
    // See {@link #getDashboardData} for the reason that the start and end time are stored in a
    // DateTime object with data's timezone.
    DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
    request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
    request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
    request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
    request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
    if (filterJson != null && !filterJson.isEmpty()) {
        filterJson = URLDecoder.decode(filterJson, "UTF-8");
        request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
    }
    request.setTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
    if (groupByDimensions != null && !groupByDimensions.isEmpty()) {
        request.setGroupByDimensions(Arrays.asList(groupByDimensions.trim().split(",")));
    }
    ContributorViewHandler handler = new ContributorViewHandler(queryCache);
    String jsonResponse = null;
    try {
        ContributorViewResponse response = handler.process(request);
        jsonResponse = OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(response);
        LOG.debug("Contributor response {}", jsonResponse);
    } catch (Exception e) {
        LOG.error("Exception while processing /data/tabular call", e);
    }
    return jsonResponse;
}
Also used : ContributorViewResponse(com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewResponse) ContributorViewHandler(com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewHandler) ContributorViewRequest(com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewRequest) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) 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 30 with MetricExpression

use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.

the class ThirdEyeUtils method getMetricExpressionFromMetricConfig.

public static MetricExpression getMetricExpressionFromMetricConfig(MetricConfigDTO metricConfig) {
    MetricExpression metricExpression = new MetricExpression();
    metricExpression.setExpressionName(metricConfig.getName());
    if (metricConfig.isDerived()) {
        metricExpression.setExpression(metricConfig.getDerivedMetricExpression());
    } else {
        metricExpression.setExpression(MetricConfigBean.DERIVED_METRIC_ID_PREFIX + metricConfig.getId());
    }
    return metricExpression;
}
Also used : MetricExpression(com.linkedin.thirdeye.client.MetricExpression)

Aggregations

MetricExpression (com.linkedin.thirdeye.client.MetricExpression)36 DateTime (org.joda.time.DateTime)24 ArrayList (java.util.ArrayList)19 DateTimeZone (org.joda.time.DateTimeZone)12 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)8 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)8 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)8 Produces (javax.ws.rs.Produces)8 TimeOnTimeComparisonRequest (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest)7 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)7 HashMap (java.util.HashMap)7 TabularViewHandler (com.linkedin.thirdeye.dashboard.views.tabular.TabularViewHandler)6 TabularViewRequest (com.linkedin.thirdeye.dashboard.views.tabular.TabularViewRequest)6 TabularViewResponse (com.linkedin.thirdeye.dashboard.views.tabular.TabularViewResponse)6 JSONException (org.json.JSONException)6 GenericResponse (com.linkedin.thirdeye.dashboard.views.GenericResponse)5 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)5