Search in sources :

Example 1 with DateHistogramQuery

use of io.gravitee.management.model.analytics.query.DateHistogramQuery in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAnalyticsResource method executeDateHisto.

private Analytics executeDateHisto(String application, AnalyticsParam analyticsParam) {
    DateHistogramQuery query = new DateHistogramQuery();
    query.setFrom(analyticsParam.getFrom());
    query.setTo(analyticsParam.getTo());
    query.setInterval(analyticsParam.getInterval());
    query.setQuery(analyticsParam.getQuery());
    query.setRootField("application");
    query.setRootIdentifier(application);
    List<Aggregation> aggregations = analyticsParam.getAggregations();
    if (aggregations != null) {
        List<io.gravitee.management.model.analytics.query.Aggregation> aggregationList = aggregations.stream().map((Function<Aggregation, io.gravitee.management.model.analytics.query.Aggregation>) aggregation -> new io.gravitee.management.model.analytics.query.Aggregation() {

            @Override
            public AggregationType type() {
                return AggregationType.valueOf(aggregation.getType().name().toUpperCase());
            }

            @Override
            public String field() {
                return aggregation.getField();
            }
        }).collect(Collectors.toList());
        query.setAggregations(aggregationList);
    }
    return analyticsService.execute(query);
}
Also used : AggregationType(io.gravitee.management.model.analytics.query.AggregationType) DateHistogramQuery(io.gravitee.management.model.analytics.query.DateHistogramQuery) Aggregation(io.gravitee.management.rest.resource.param.Aggregation) Function(java.util.function.Function)

Example 2 with DateHistogramQuery

use of io.gravitee.management.model.analytics.query.DateHistogramQuery in project gravitee-management-rest-api by gravitee-io.

the class ApiAnalyticsResource method executeDateHisto.

private Analytics executeDateHisto(String api, AnalyticsParam analyticsParam) {
    DateHistogramQuery query = new DateHistogramQuery();
    query.setFrom(analyticsParam.getFrom());
    query.setTo(analyticsParam.getTo());
    query.setInterval(analyticsParam.getInterval());
    query.setQuery(analyticsParam.getQuery());
    query.setRootField("api");
    query.setRootIdentifier(api);
    List<Aggregation> aggregations = analyticsParam.getAggregations();
    if (aggregations != null) {
        List<io.gravitee.management.model.analytics.query.Aggregation> aggregationList = aggregations.stream().map((Function<Aggregation, io.gravitee.management.model.analytics.query.Aggregation>) aggregation -> new io.gravitee.management.model.analytics.query.Aggregation() {

            @Override
            public AggregationType type() {
                return AggregationType.valueOf(aggregation.getType().name().toUpperCase());
            }

            @Override
            public String field() {
                return aggregation.getField();
            }
        }).collect(Collectors.toList());
        query.setAggregations(aggregationList);
    }
    return analyticsService.execute(query);
}
Also used : AggregationType(io.gravitee.management.model.analytics.query.AggregationType) DateHistogramQuery(io.gravitee.management.model.analytics.query.DateHistogramQuery) Aggregation(io.gravitee.management.rest.resource.param.Aggregation) Function(java.util.function.Function)

Example 3 with DateHistogramQuery

use of io.gravitee.management.model.analytics.query.DateHistogramQuery in project gravitee-management-rest-api by gravitee-io.

the class ApiHealthResource method executeDateHisto.

private Analytics executeDateHisto(final String api, final AnalyticsAverageParam analyticsAverageParam) {
    final DateHistogramQuery query = new DateHistogramQuery();
    query.setFrom(analyticsAverageParam.getFrom());
    query.setTo(analyticsAverageParam.getTo());
    query.setInterval(analyticsAverageParam.getInterval());
    query.setRootField("api");
    query.setRootIdentifier(api);
    query.setAggregations(singletonList(new io.gravitee.management.model.analytics.query.Aggregation() {

        @Override
        public AggregationType type() {
            switch(analyticsAverageParam.getType()) {
                case AVAILABILITY:
                    return AggregationType.FIELD;
                default:
                    return AggregationType.AVG;
            }
        }

        @Override
        public String field() {
            switch(analyticsAverageParam.getType()) {
                case AVAILABILITY:
                    return "available";
                default:
                    return "response-time";
            }
        }
    }));
    return healthCheckService.query(query);
}
Also used : DateHistogramQuery(io.gravitee.management.model.analytics.query.DateHistogramQuery) Aggregation(io.gravitee.management.rest.resource.param.Aggregation)

Aggregations

DateHistogramQuery (io.gravitee.management.model.analytics.query.DateHistogramQuery)3 Aggregation (io.gravitee.management.rest.resource.param.Aggregation)3 AggregationType (io.gravitee.management.model.analytics.query.AggregationType)2 Function (java.util.function.Function)2