Search in sources :

Example 1 with Summary

use of com.linkedin.thirdeye.dashboard.views.diffsummary.Summary in project pinot by linkedin.

the class PinotThirdEyeSummaryClient method main.

public static void main(String[] args) throws Exception {
    String oFileName = "Cube.json";
    // An interesting data set that difficult to tell because too many dark reds and blues (Granularity: DAYS)
    //    String collection = "thirdeyeKbmi";
    //    String metricName = "pageViews";
    //    DateTime baselineStart = new DateTime(1467788400000L);
    //    DateTime baselineEnd =   new DateTime(1469862000000L);
    //    DateTime currentStart =  new DateTime(1468393200000L);
    //    DateTime currentEnd =    new DateTime(1470466800000L);
    // An interesting data set that difficult to tell because most cells are light red or blue (Granularity: HOURS)
    //    String collection = "thirdeyeKbmi";
    //    String metricName = "mobilePageViews";
    //    DateTime baselineStart = new DateTime(1469628000000L);
    //    DateTime baselineEnd =   new DateTime(1469714400000L);
    //    DateTime currentStart =  new DateTime(1470232800000L);
    //    DateTime currentEnd =    new DateTime(1470319200000L);
    // A migration of Asia connections from other data center to lsg data center (Granularity: DAYS)
    // Most contributors: India and China
    //    String collection = "thirdeyeAbook";
    //    String metricName = "totalFlows";
    //    DateTime baselineStart = new DateTime(2016, 7, 11, 00, 00);
    //    DateTime baselineEnd =   new DateTime(2016, 7, 12, 00, 00);
    //    DateTime currentStart =  new DateTime(2016, 7, 18, 00, 00);
    //    DateTime currentEnd =    new DateTime(2016, 7, 19, 00, 00);
    // National Holidays in India and several countries in Europe and Latin America. (Granularity: DAYS)
    String collection = "thirdeyeKbmi";
    String metricName = "desktopPageViews";
    DateTime baselineStart = new DateTime(1470589200000L);
    DateTime baselineEnd = new DateTime(1470675600000L);
    DateTime currentStart = new DateTime(1471194000000L);
    DateTime currentEnd = new DateTime(1471280400000L);
    //    String collection = "ptrans_additive";
    //    String metricName = "txProcessTime/__COUNT";
    //    DateTime baselineStart = new DateTime(1470938400000L);
    //    DateTime baselineEnd =   new DateTime(1471024800000L);
    //    DateTime currentStart =  new DateTime(1471543200000L);
    //    DateTime currentEnd =    new DateTime(1471629600000L);
    // Create ThirdEye client
    List<String> argList = new ArrayList<String>(Arrays.asList(args));
    if (argList.size() == 1) {
        argList.add(0, "server");
    }
    int lastIndex = argList.size() - 1;
    String thirdEyeConfigDir = argList.get(lastIndex);
    String persistenceConfig = thirdEyeConfigDir + "/persistence.yml";
    DaoProviderUtil.init(new File(persistenceConfig));
    ThirdEyeConfiguration thirdEyeConfig = new ThirdEyeDashboardConfiguration();
    thirdEyeConfig.setWhitelistCollections(collection);
    thirdEyeConfig.setRootDir(thirdEyeConfigDir);
    ThirdEyeCacheRegistry.initializeCaches(thirdEyeConfig);
    ThirdEyeCacheRegistry CACHE_REGISTRY_INSTANCE = ThirdEyeCacheRegistry.getInstance();
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricName, MetricAggFunction.SUM, collection);
    System.out.println(metricExpressions);
    OLAPDataBaseClient pinotClient = new PinotThirdEyeSummaryClient(CACHE_REGISTRY_INSTANCE.getQueryCache());
    pinotClient.setCollection(collection);
    pinotClient.setMetricExpression(metricExpressions.get(0));
    pinotClient.setCurrentStartInclusive(currentStart);
    pinotClient.setCurrentEndExclusive(currentEnd);
    pinotClient.setBaselineStartInclusive(baselineStart);
    pinotClient.setBaselineEndExclusive(baselineEnd);
    List<List<String>> hierarchies = new ArrayList<>();
    hierarchies.add(Lists.newArrayList("continent", "countryCode"));
    hierarchies.add(Lists.newArrayList("browser_name", "browser_version"));
    Dimensions dimensions;
    try {
        dimensions = new Dimensions(Utils.getSchemaDimensionNames(collection));
    } catch (Exception e1) {
        System.out.println("Failed to get dimensions names of the collection: " + collection);
        String[] dimensionNames = { "browserName", "continent", "countryCode", "deviceName", "environment", "locale", "osName", "pageKey", "service", "sourceApp" };
        System.out.println("Default dimension names are used:" + dimensionNames);
        dimensions = new Dimensions(Lists.newArrayList(dimensionNames));
    }
    int maxDimensionSize = 3;
    // Build the cube for computing the summary
    Cube initCube = new Cube();
    initCube.buildWithAutoDimensionOrder(pinotClient, dimensions, maxDimensionSize, hierarchies);
    //    initCube.buildWithManualDimensionOrder(pinotClient, dimensions);
    int answerSize = 10;
    boolean oneSideErrors = true;
    Summary summary = new Summary(initCube);
    System.out.println(summary.computeSummary(answerSize, oneSideErrors, maxDimensionSize));
    try {
        initCube.toJson(oFileName);
        Cube cube = Cube.fromJson(oFileName);
        System.out.println("Restored Cube:");
        System.out.println(cube);
        summary = new Summary(cube);
        System.out.println(summary.computeSummary(answerSize, oneSideErrors, maxDimensionSize));
    } catch (IOException e) {
        System.err.println("WARN: Unable to save the cube to the file: " + oFileName);
        e.printStackTrace();
    }
    // closing
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) ThirdEyeConfiguration(com.linkedin.thirdeye.common.ThirdEyeConfiguration) ThirdEyeDashboardConfiguration(com.linkedin.thirdeye.dashboard.ThirdEyeDashboardConfiguration) ThirdEyeCacheRegistry(com.linkedin.thirdeye.client.ThirdEyeCacheRegistry) Summary(com.linkedin.thirdeye.dashboard.views.diffsummary.Summary) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 2 with Summary

use of com.linkedin.thirdeye.dashboard.views.diffsummary.Summary in project pinot by linkedin.

the class SummaryResource method buildSummary.

@GET
@Path(value = "/summary/autoDimensionOrder")
@Produces(MediaType.APPLICATION_JSON)
public String buildSummary(@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("topDimensions") @DefaultValue(DEFAULT_TOP_DIMENSIONS) int topDimensions, @QueryParam("hierarchies") @DefaultValue(DEFAULT_HIERARCHIES) String hierarchiesPayload, @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)));
        Dimensions dimensions;
        if (groupByDimensions == null || groupByDimensions.length() == 0 || groupByDimensions.equals("undefined")) {
            dimensions = new Dimensions(Utils.getSchemaDimensionNames(collection));
        } else {
            dimensions = new Dimensions(Arrays.asList(groupByDimensions.trim().split(",")));
        }
        List<List<String>> hierarchies = OBJECT_MAPPER.readValue(hierarchiesPayload, new TypeReference<List<List<String>>>() {
        });
        Cube cube = new Cube();
        cube.buildWithAutoDimensionOrder(olapClient, dimensions, topDimensions, hierarchies);
        Summary summary = new Summary(cube);
        response = summary.computeSummary(summarySize, doOneSideError, topDimensions);
        response.setMetricName(metric);
    } catch (Exception e) {
        LOG.error("Exception while generating difference summary", e);
        response = SummaryResponse.buildNotAvailableResponse();
        response.setMetricName(metric);
    }
    return OBJECT_MAPPER.writeValueAsString(response);
}
Also used : OLAPDataBaseClient(com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient) Dimensions(com.linkedin.thirdeye.client.diffsummary.Dimensions) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) SummaryResponse(com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse) Cube(com.linkedin.thirdeye.client.diffsummary.Cube) Summary(com.linkedin.thirdeye.dashboard.views.diffsummary.Summary) PinotThirdEyeSummaryClient(com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Summary

use of com.linkedin.thirdeye.dashboard.views.diffsummary.Summary 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)

Aggregations

MetricExpression (com.linkedin.thirdeye.client.MetricExpression)3 Summary (com.linkedin.thirdeye.dashboard.views.diffsummary.Summary)3 DateTime (org.joda.time.DateTime)3 Cube (com.linkedin.thirdeye.client.diffsummary.Cube)2 Dimensions (com.linkedin.thirdeye.client.diffsummary.Dimensions)2 OLAPDataBaseClient (com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient)2 PinotThirdEyeSummaryClient (com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient)2 SummaryResponse (com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ThirdEyeCacheRegistry (com.linkedin.thirdeye.client.ThirdEyeCacheRegistry)1 ThirdEyeConfiguration (com.linkedin.thirdeye.common.ThirdEyeConfiguration)1 ThirdEyeDashboardConfiguration (com.linkedin.thirdeye.dashboard.ThirdEyeDashboardConfiguration)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1