Search in sources :

Example 1 with DateHistogramQuery

use of io.gravitee.rest.api.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.rest.api.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.rest.api.model.analytics.query.DateHistogramQuery)

Example 2 with DateHistogramQuery

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

the class ApplicationAnalyticsResourceTest method shouldGetDateHistoAnalytics.

@Test
public void shouldGetDateHistoAnalytics() {
    final Response response = target(APPLICATION).path("analytics").queryParam("from", 0).queryParam("to", 100).queryParam("interval", 10_000).queryParam("query", APPLICATION).queryParam("type", "DATE_HISTO").queryParam("aggs", "AVG:hit").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<DateHistogramQuery> queryCaptor = ArgumentCaptor.forClass(DateHistogramQuery.class);
    Mockito.verify(analyticsService).execute(queryCaptor.capture());
    final DateHistogramQuery query = queryCaptor.getValue();
    assertEquals(0, query.getFrom());
    assertEquals(100, query.getTo());
    assertEquals(10_000, query.getInterval());
    assertEquals(ANALYTICS_ROOT_FIELD, query.getRootField());
    assertEquals(APPLICATION, query.getRootIdentifier());
    List<Aggregation> aggregations = query.getAggregations();
    assertNotNull(aggregations);
    assertEquals(1, aggregations.size());
    Aggregation agg = aggregations.get(0);
    assertNotNull(agg);
    assertEquals(AggregationType.AVG, agg.type());
    assertEquals("hit", agg.field());
}
Also used : Response(javax.ws.rs.core.Response) DateHistogramQuery(io.gravitee.rest.api.model.analytics.query.DateHistogramQuery) Aggregation(io.gravitee.rest.api.model.analytics.query.Aggregation) Test(org.junit.Test)

Example 3 with DateHistogramQuery

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

the class EnvironmentAnalyticsResource method executeDateHisto.

private Analytics executeDateHisto(AnalyticsParam analyticsParam, String extraFilter) {
    DateHistogramQuery query = new DateHistogramQuery();
    query.setFrom(analyticsParam.getFrom());
    query.setTo(analyticsParam.getTo());
    query.setInterval(analyticsParam.getInterval());
    query.setQuery(analyticsParam.getQuery());
    List<Aggregation> aggregations = analyticsParam.getAggregations();
    if (aggregations != null) {
        List<io.gravitee.rest.api.model.analytics.query.Aggregation> aggregationList = aggregations.stream().map((Function<Aggregation, io.gravitee.rest.api.model.analytics.query.Aggregation>) aggregation -> new io.gravitee.rest.api.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);
    }
    addExtraFilter(query, extraFilter);
    return analyticsService.execute(query);
}
Also used : AggregationType(io.gravitee.rest.api.model.analytics.query.AggregationType) DateHistogramQuery(io.gravitee.rest.api.model.analytics.query.DateHistogramQuery) Aggregation(io.gravitee.rest.api.management.rest.resource.param.Aggregation) Function(java.util.function.Function)

Aggregations

DateHistogramQuery (io.gravitee.rest.api.model.analytics.query.DateHistogramQuery)3 Aggregation (io.gravitee.rest.api.management.rest.resource.param.Aggregation)1 Aggregation (io.gravitee.rest.api.model.analytics.query.Aggregation)1 AggregationType (io.gravitee.rest.api.model.analytics.query.AggregationType)1 Function (java.util.function.Function)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1