AnalyticsServiceElasticsearch extends AbstractAnalyticsService { @Override public List<NodeTimeseriesStatistics> getNodeTimeseriesStatistics(String tenantId, Criteria criteria, long interval) { String index = client.getIndex(tenantId); if (!refresh(index)) { return null; } AvgBuilder avgBuilder = AggregationBuilders .avg("avg") .field(ElasticsearchUtil.ACTUAL_FIELD); TermsBuilder componentsBuilder = AggregationBuilders .terms("components") .field("componentType") .size(criteria.getMaxResponseSize()) .subAggregation(avgBuilder); DateHistogramBuilder histogramBuilder = AggregationBuilders .dateHistogram("histogram") .interval(interval) .field(ElasticsearchUtil.TIMESTAMP_FIELD) .subAggregation(componentsBuilder); BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, NodeDetails.class); 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::toNodeTimeseriesStatistics) .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 testGetNodeTimeseriesStatistics() throws StoreException { NodeDetails ct1_1 = new NodeDetails(); ct1_1.setTransaction(TXN); ct1_1.setTimestamp(1500); ct1_1.setActual(100); ct1_1.setComponentType(Constants.COMPONENT_DATABASE); NodeDetails ct1_2 = new NodeDetails(); ct1_2.setTransaction(TXN); ct1_2.setTimestamp(1600); ct1_2.setActual(300); ct1_2.setComponentType(Constants.COMPONENT_DATABASE); NodeDetails ct1_3 = new NodeDetails(); ct1_3.setTransaction(TXN); ct1_3.setTimestamp(1700); ct1_3.setActual(150); ct1_3.setComponentType(Constants.COMPONENT_EJB); NodeDetails ct2 = new NodeDetails(); ct2.setTransaction(TXN); ct2.setTimestamp(2100); ct2.setActual(500); ct2.setComponentType(Constants.COMPONENT_DATABASE); analytics.storeNodeDetails(null, Arrays.asList(ct1_1, ct1_2, ct1_3, ct2)); Criteria criteria = new Criteria(); criteria.setStartTime(1).setEndTime(10000); Wait.until(() -> analytics.getNodeTimeseriesStatistics(null, criteria, 1000).size() == 2 ); List<NodeTimeseriesStatistics> stats = analytics.getNodeTimeseriesStatistics(null, criteria, 1000); assertNotNull(stats); assertEquals(2, stats.size()); assertEquals(1000, stats.get(0).getTimestamp()); assertEquals(2000, stats.get(1).getTimestamp()); assertEquals(2, stats.get(0).getComponentTypes().size()); assertEquals(1, stats.get(1).getComponentTypes().size()); assertTrue(stats.get(0).getComponentTypes().containsKey(Constants.COMPONENT_DATABASE)); assertTrue(stats.get(0).getComponentTypes().containsKey(Constants.COMPONENT_EJB)); assertTrue(stats.get(1).getComponentTypes().containsKey(Constants.COMPONENT_DATABASE)); assertTrue(stats.get(0).getComponentTypes().get(Constants.COMPONENT_DATABASE).getDuration() == 200); assertTrue(stats.get(0).getComponentTypes().get(Constants.COMPONENT_DATABASE).getCount() == 2); assertTrue(stats.get(0).getComponentTypes().get(Constants.COMPONENT_EJB).getDuration() == 150); assertTrue(stats.get(0).getComponentTypes().get(Constants.COMPONENT_EJB).getCount() == 1); assertTrue(stats.get(1).getComponentTypes().get(Constants.COMPONENT_DATABASE).getDuration() == 500); assertTrue(stats.get(1).getComponentTypes().get(Constants.COMPONENT_DATABASE).getCount() == 1); }