use of io.kestra.core.models.executions.statistics.DailyExecutionStatistics in project kestra by kestra-io.
the class ElasticSearchExecutionRepository method dailyStatistics.
@Override
public List<DailyExecutionStatistics> dailyStatistics(@Nullable String query, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, boolean isTaskRun) {
if (startDate == null) {
startDate = ZonedDateTime.now().minusDays(30);
}
if (endDate == null) {
endDate = ZonedDateTime.now();
}
AggregationBuilder agg = dailyExecutionStatisticsFinalAgg(startDate, endDate, isTaskRun);
if (isTaskRun) {
agg = AggregationBuilders.nested(NESTED_AGG, "taskRunList").subAggregation(agg);
}
SearchSourceBuilder sourceBuilder = this.searchSource(this.dateFilters(query, startDate, endDate), Optional.of(Collections.singletonList(agg)), null);
try {
SearchRequest searchRequest = searchRequest(INDEX_NAME, sourceBuilder, false);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
ParsedDateHistogram groupAgg = isTaskRun ? ((ParsedNested) searchResponse.getAggregations().get(NESTED_AGG)).getAggregations().get(DATE_AGG) : searchResponse.getAggregations().get(DATE_AGG);
List<DailyExecutionStatistics> result = new ArrayList<>();
groupAgg.getBuckets().forEach(bucket -> {
ParsedStringTerms countAgg = bucket.getAggregations().get(COUNT_AGG);
ParsedStats durationAgg = bucket.getAggregations().get(DURATION_AGG);
final LocalDate currentStartDate = LocalDate.parse(bucket.getKeyAsString(), DateTimeFormatter.ISO_LOCAL_DATE);
result.add(dailyExecutionStatisticsMap(countAgg, durationAgg, currentStartDate));
});
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.kestra.core.models.executions.statistics.DailyExecutionStatistics in project kestra by kestra-io.
the class ElasticSearchExecutionRepositoryTest method dailyGroupByFlowStatistics.
@Test
void dailyGroupByFlowStatistics() {
for (int i = 0; i < 28; i++) {
executionRepository.save(builder(i < 5 ? State.Type.RUNNING : (i < 8 ? State.Type.FAILED : State.Type.SUCCESS), i < 15 ? null : "second").build());
}
Map<String, Map<String, List<DailyExecutionStatistics>>> result = executionRepository.dailyGroupByFlowStatistics("*", ZonedDateTime.now().minusDays(10), ZonedDateTime.now(), false);
assertThat(result.size(), is(1));
assertThat(result.get("io.kestra.unittest").size(), is(2));
DailyExecutionStatistics full = result.get("io.kestra.unittest").get(FLOW).get(10);
DailyExecutionStatistics second = result.get("io.kestra.unittest").get("second").get(10);
assertThat(full.getDuration().getAvg().getSeconds(), greaterThan(0L));
assertThat(full.getExecutionCounts().size(), is(9));
assertThat(full.getExecutionCounts().get(State.Type.FAILED), is(3L));
assertThat(full.getExecutionCounts().get(State.Type.RUNNING), is(5L));
assertThat(full.getExecutionCounts().get(State.Type.SUCCESS), is(7L));
assertThat(full.getExecutionCounts().get(State.Type.CREATED), is(0L));
assertThat(second.getDuration().getAvg().getSeconds(), greaterThan(0L));
assertThat(second.getExecutionCounts().size(), is(9));
assertThat(second.getExecutionCounts().get(State.Type.SUCCESS), is(13L));
assertThat(second.getExecutionCounts().get(State.Type.CREATED), is(0L));
result = executionRepository.dailyGroupByFlowStatistics("*", ZonedDateTime.now().minusDays(10), ZonedDateTime.now(), true);
assertThat(result.size(), is(1));
assertThat(result.get("io.kestra.unittest").size(), is(1));
full = result.get("io.kestra.unittest").get("*").get(10);
assertThat(full.getDuration().getAvg().getSeconds(), greaterThan(0L));
assertThat(full.getExecutionCounts().size(), is(9));
assertThat(full.getExecutionCounts().get(State.Type.FAILED), is(3L));
assertThat(full.getExecutionCounts().get(State.Type.RUNNING), is(5L));
assertThat(full.getExecutionCounts().get(State.Type.SUCCESS), is(20L));
assertThat(full.getExecutionCounts().get(State.Type.CREATED), is(0L));
}
use of io.kestra.core.models.executions.statistics.DailyExecutionStatistics in project kestra by kestra-io.
the class ElasticSearchExecutionRepository method dailyGroupByFlowStatistics.
@Override
public Map<String, Map<String, List<DailyExecutionStatistics>>> dailyGroupByFlowStatistics(@Nullable String query, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, boolean groupByNamespaceOnly) {
if (startDate == null) {
startDate = ZonedDateTime.now().minusDays(30);
}
if (endDate == null) {
endDate = ZonedDateTime.now();
}
TermsAggregationBuilder agg = AggregationBuilders.terms(NAMESPACE_AGG).size(groupByNamespaceOnly ? 25 : 10000).field("namespace").subAggregation(groupByNamespaceOnly ? dailyExecutionStatisticsFinalAgg(startDate, endDate, false) : AggregationBuilders.terms(FLOW_AGG).size(10000).field("flowId").subAggregation(dailyExecutionStatisticsFinalAgg(startDate, endDate, false)));
SearchSourceBuilder sourceBuilder = this.searchSource(this.dateFilters(query, startDate, endDate), Optional.of(Collections.singletonList(agg)), null);
try {
SearchRequest searchRequest = searchRequest(INDEX_NAME, sourceBuilder, false);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Map<String, Map<String, List<DailyExecutionStatistics>>> result = new HashMap<>();
((ParsedStringTerms) searchResponse.getAggregations().get(NAMESPACE_AGG)).getBuckets().forEach(namespaceBucket -> {
final String namespace = namespaceBucket.getKeyAsString();
if (groupByNamespaceOnly) {
this.parseDateAgg(namespaceBucket, result, namespace, "*");
} else {
((ParsedStringTerms) namespaceBucket.getAggregations().get(FLOW_AGG)).getBuckets().forEach(flowBucket -> {
final String flowId = flowBucket.getKeyAsString();
this.parseDateAgg(flowBucket, result, namespace, flowId);
});
}
});
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.kestra.core.models.executions.statistics.DailyExecutionStatistics in project kestra by kestra-io.
the class ElasticSearchExecutionRepository method dailyExecutionStatisticsMap.
private static DailyExecutionStatistics dailyExecutionStatisticsMap(ParsedStringTerms countAgg, ParsedStats durationAgg, LocalDate startDate) {
DailyExecutionStatistics build = DailyExecutionStatistics.builder().startDate(startDate).duration(DailyExecutionStatistics.Duration.builder().avg(durationFromDouble(durationAgg.getAvg())).min(durationFromDouble(durationAgg.getMin())).max(durationFromDouble(durationAgg.getMax())).sum(durationFromDouble(durationAgg.getSum())).count(durationAgg.getCount()).build()).build();
countAgg.getBuckets().forEach(item -> build.getExecutionCounts().compute(State.Type.valueOf(item.getKeyAsString()), (type, current) -> item.getDocCount()));
return build;
}
Aggregations