From 6fa7109b5563ec4217f055b4745f0b01be0b17cf Mon Sep 17 00:00:00 2001 From: YannC Date: Wed, 31 Jul 2024 18:24:19 +0200 Subject: [PATCH] feat(): filter state on dashboard and graph on execution list close #4397 --- .../models/collectors/ExecutionUsage.java | 9 +++-- .../ExecutionRepositoryInterface.java | 7 ++-- .../AbstractExecutionRepositoryTest.java | 8 ++--- .../AbstractJdbcExecutionRepository.java | 27 ++++++++++---- ui/src/components/home/Home.vue | 35 +++++++++++++++++-- ui/src/mixins/dataTableActions.js | 2 +- .../controllers/api/StatsController.java | 12 ++++--- 7 files changed, 73 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/io/kestra/core/models/collectors/ExecutionUsage.java b/core/src/main/java/io/kestra/core/models/collectors/ExecutionUsage.java index 0e7c8986c5..22c430ee73 100644 --- a/core/src/main/java/io/kestra/core/models/collectors/ExecutionUsage.java +++ b/core/src/main/java/io/kestra/core/models/collectors/ExecutionUsage.java @@ -8,7 +8,6 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; -import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.List; @@ -36,8 +35,8 @@ public static ExecutionUsage of(final String tenantId, from, to, DateUtils.GroupType.DAY, - true - ); + null, + true); } catch (UnsupportedOperationException ignored) { } @@ -51,8 +50,8 @@ public static ExecutionUsage of(final String tenantId, from, to, DateUtils.GroupType.DAY, - false - )) + null, + false)) .dailyTaskRunsCount(dailyTaskRunsCount) .build(); } diff --git a/core/src/main/java/io/kestra/core/repositories/ExecutionRepositoryInterface.java b/core/src/main/java/io/kestra/core/repositories/ExecutionRepositoryInterface.java index 11267bb345..340a875ba8 100644 --- a/core/src/main/java/io/kestra/core/repositories/ExecutionRepositoryInterface.java +++ b/core/src/main/java/io/kestra/core/repositories/ExecutionRepositoryInterface.java @@ -8,18 +8,18 @@ import io.kestra.core.models.flows.State; import io.kestra.core.utils.DateUtils; import io.micronaut.data.model.Pageable; +import jakarta.annotation.Nullable; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import reactor.core.publisher.Flux; import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Function; -import jakarta.annotation.Nullable; -import jakarta.validation.constraints.NotNull; -import reactor.core.publisher.Flux; public interface ExecutionRepositoryInterface extends SaveRepositoryInterface { Boolean isTaskRunEnabled(); @@ -122,6 +122,7 @@ List dailyStatistics( @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable DateUtils.GroupType groupBy, + List state, boolean isTaskRun ); diff --git a/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java b/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java index b9e107f7c9..61a84f592e 100644 --- a/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java +++ b/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java @@ -427,8 +427,8 @@ protected void dailyStatistics() throws InterruptedException { ZonedDateTime.now().minusDays(10), ZonedDateTime.now(), null, - false - ); + null, + false); assertThat(result.size(), is(11)); assertThat(result.get(10).getExecutionCounts().size(), is(11)); @@ -456,8 +456,8 @@ protected void taskRunsDailyStatistics() { ZonedDateTime.now().minusDays(10), ZonedDateTime.now(), null, - true - ); + null, + true); assertThat(result.size(), is(11)); assertThat(result.get(10).getExecutionCounts().size(), is(11)); diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java index e65ed16a34..238044df2c 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java @@ -326,7 +326,8 @@ public List dailyStatisticsForAllTenants( null, startDate, endDate, - groupBy + groupBy, + null ); return dailyStatisticsQueryMapRecord( @@ -348,6 +349,7 @@ public List dailyStatistics( @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable DateUtils.GroupType groupBy, + @Nullable List states, boolean isTaskRun ) { if (isTaskRun) { @@ -365,7 +367,8 @@ public List dailyStatistics( null, startDate, endDate, - groupBy + groupBy, + states ); return dailyStatisticsQueryMapRecord( @@ -414,7 +417,8 @@ private Results dailyStatisticsQueryForAllTenants( List flows, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, - @Nullable DateUtils.GroupType groupBy + @Nullable DateUtils.GroupType groupBy, + @Nullable List state ) { return dailyStatisticsQuery( this.defaultFilter(), @@ -425,7 +429,8 @@ private Results dailyStatisticsQueryForAllTenants( flows, startDate, endDate, - groupBy + groupBy, + state ); } @@ -438,7 +443,8 @@ private Results dailyStatisticsQuery( List flows, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, - @Nullable DateUtils.GroupType groupBy + @Nullable DateUtils.GroupType groupBy, + @Nullable List state ) { return dailyStatisticsQuery( this.defaultFilter(tenantId), @@ -449,7 +455,8 @@ private Results dailyStatisticsQuery( flows, startDate, endDate, - groupBy + groupBy, + state ); } @@ -462,7 +469,8 @@ private Results dailyStatisticsQuery( List flows, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, - @Nullable DateUtils.GroupType groupBy + @Nullable DateUtils.GroupType groupBy, + @Nullable List state ) { ZonedDateTime finalStartDate = startDate == null ? ZonedDateTime.now().minusDays(30) : startDate; ZonedDateTime finalEndDate = endDate == null ? ZonedDateTime.now() : endDate; @@ -491,6 +499,10 @@ private Results dailyStatisticsQuery( select = filteringQuery(select, namespace, flowId, flows, query, null, null, null); + if (state != null) { + select = select.and(this.statesFilter(state)); + } + List> groupFields = new ArrayList<>(fields); groupFields.addAll(dateFields); @@ -583,6 +595,7 @@ public Map>> dailyGroupByFlow flows, startDate, endDate, + null, null ); diff --git a/ui/src/components/home/Home.vue b/ui/src/components/home/Home.vue index 407219a1db..35a4726c57 100644 --- a/ui/src/components/home/Home.vue +++ b/ui/src/components/home/Home.vue @@ -22,6 +22,23 @@ @update:model-value="onNamespaceSelect" /> + + + + + 0) { + this.$router.push({query: {...this.$route.query, state: state}}); + } else { + let query = {...this.$route.query} + delete query["state"] + this.$router.push({query: query}); + } + + this.load(this.onDataLoaded); + }, }, computed: { ...mapState("stat", ["daily", "dailyGroupByFlow"]), diff --git a/ui/src/mixins/dataTableActions.js b/ui/src/mixins/dataTableActions.js index c77c303554..e95ad62b99 100644 --- a/ui/src/mixins/dataTableActions.js +++ b/ui/src/mixins/dataTableActions.js @@ -74,7 +74,7 @@ export default { let query = {...this.$route.query}; for (const [key, value] of Object.entries(values)) { - if (value === undefined || value === "" || value === null) { + if (value === undefined || value === "" || value === null || value.length === 0) { delete query[key] } else { query[key] = value; diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java index 84ab002fa2..61c86e2d25 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java @@ -3,6 +3,7 @@ import io.kestra.core.models.executions.Execution; import io.kestra.core.models.executions.statistics.DailyExecutionStatistics; import io.kestra.core.models.executions.statistics.LogStatistics; +import io.kestra.core.models.flows.State; import io.kestra.core.repositories.ExecutionRepositoryInterface; import io.kestra.core.repositories.LogRepositoryInterface; import io.kestra.core.tenant.TenantService; @@ -51,8 +52,8 @@ public List dailyStatistics(@Body @Valid StatisticRequ statisticRequest.startDate() != null ? statisticRequest.startDate().withZoneSameInstant(ZoneId.systemDefault()) : null, statisticRequest.endDate() != null ? statisticRequest.endDate().withZoneSameInstant(ZoneId.systemDefault()) : null, null, - false - ); + statisticRequest.state(), + false); } @ExecuteOn(TaskExecutors.IO) @@ -67,8 +68,8 @@ public List taskRunsDailyStatistics(@Body @Valid Stati statisticRequest.startDate() != null ? statisticRequest.startDate().withZoneSameInstant(ZoneId.systemDefault()) : null, statisticRequest.endDate() != null ? statisticRequest.endDate().withZoneSameInstant(ZoneId.systemDefault()) : null, null, - true - ); + statisticRequest.state(), + true); } @ExecuteOn(TaskExecutors.IO) @@ -121,7 +122,8 @@ public record StatisticRequest( @Parameter(description = "A namespace filter prefix") @Nullable String namespace, @Parameter(description = "A flow id filter") @Nullable String flowId, @Parameter(description = "The start datetime, default to now") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") ZonedDateTime startDate, - @Parameter(description = "The end datetime, default to now") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]")ZonedDateTime endDate + @Parameter(description = "The end datetime, default to now") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]")ZonedDateTime endDate, + @Parameter(description = "the state of the execution") @Nullable List state ) {} @Introspected