AnalyticsServiceElasticsearch extends AbstractAnalyticsService { @Override public List<TimeseriesStatistics> getEndpointResponseTimeseriesStatistics(String tenantId, Criteria criteria, long interval) { String index = client.getIndex(tenantId); if (!refresh(index)) { return null; } StatsBuilder statsBuilder = AggregationBuilders .stats("stats") .field(ElasticsearchUtil.ELAPSED_FIELD); FilterAggregationBuilder faultCountBuilder = AggregationBuilders .filter("faults") .filter(FilterBuilders.queryFilter(QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery(ElasticsearchUtil.PROPERTIES_NAME_FIELD, Constants.PROP_FAULT)))); NestedBuilder nestedFaultCountBuilder = AggregationBuilders .nested("nested") .path(ElasticsearchUtil.PROPERTIES_FIELD) .subAggregation(faultCountBuilder); DateHistogramBuilder histogramBuilder = AggregationBuilders .dateHistogram("histogram") .interval(interval) .field(ElasticsearchUtil.TIMESTAMP_FIELD) .subAggregation(statsBuilder) .subAggregation(nestedFaultCountBuilder); BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, NodeDetails.class); query.must(QueryBuilders.termQuery(ElasticsearchUtil.TYPE_FIELD, "Consumer")); SearchRequestBuilder request = getNodeDetailsRequest(index, criteria, query, 0) .addAggregation(histogramBuilder); SearchResponse response = getSearchResponse(request); DateHistogram histogram = response.getAggregations().get("histogram"); return histogram.getBuckets().stream() .map(AnalyticsServiceElasticsearch::toTimeseriesStatistics) .collect(Collectors.toList()); }  @Override List<TransactionInfo> getTransactionInfo(String tenantId, Criteria criteria); @Override List<PropertyInfo> getPropertyInfo(String tenantId, Criteria criteria); @Override long getTraceCompletionCount(String tenantId, Criteria criteria); @Override long getTraceCompletionFaultCount(String tenantId, Criteria criteria); @Override List<CompletionTime> getTraceCompletions(String tenantId, Criteria criteria); @Override Percentiles getTraceCompletionPercentiles(String tenantId, Criteria criteria); @Override List<TimeseriesStatistics> getTraceCompletionTimeseriesStatistics(String tenantId, Criteria criteria, long interval); @Override List<Cardinality> getTraceCompletionFaultDetails(String tenantId, Criteria criteria); @Override List<Cardinality> getTraceCompletionPropertyDetails(String tenantId, Criteria criteria, String property); @Override List<NodeTimeseriesStatistics> getNodeTimeseriesStatistics(String tenantId, Criteria criteria, long interval); @Override Collection<NodeSummaryStatistics> getNodeSummaryStatistics(String tenantId, Criteria criteria); @Override List<TimeseriesStatistics> getEndpointResponseTimeseriesStatistics(String tenantId, Criteria criteria, long interval); @Override Set<String> getHostNames(String tenantId, Criteria criteria); @Override void storeCommunicationDetails(String tenantId, List<CommunicationDetails> communicationDetails); @Override void storeNodeDetails(String tenantId, List<NodeDetails> nodeDetails); @Override void storeTraceCompletions(String tenantId, List<CompletionTime> completionTimes); @Override void clear(String tenantId);  }
@Test public void testGetEndpointResponseTimeseriesStatistics() throws StoreException { NodeDetails nd1 = new NodeDetails(); nd1.setTimestamp(1500); nd1.setActual(100); nd1.setElapsed(400); nd1.setType(NodeType.Consumer); NodeDetails nd2 = new NodeDetails(); nd2.setTimestamp(1500); nd2.setActual(100); nd2.setElapsed(200); nd2.setType(NodeType.Component); nd2.setComponentType(Constants.COMPONENT_DATABASE); analytics.storeNodeDetails(null, Arrays.asList(nd1, nd2)); Criteria criteria = new Criteria().setStartTime(1).setEndTime(10000); Wait.until(() -> analytics.getEndpointResponseTimeseriesStatistics(null, criteria, 1000).size() == 1 ); List<TimeseriesStatistics> stats = analytics.getEndpointResponseTimeseriesStatistics(null, criteria, 1000); assertNotNull(stats); assertEquals(1, stats.size()); assertEquals(1000, stats.get(0).getTimestamp()); assertEquals(1, stats.get(0).getCount()); assertTrue(stats.get(0).getMin() == 400); assertTrue(stats.get(0).getAverage() == 400); assertTrue(stats.get(0).getMax() == 400); assertEquals(0, stats.get(0).getFaultCount()); }