Skip to content

Commit

Permalink
feat(core,jdbc,repository-memory,ui,webserver): allow filtering taskr…
Browse files Browse the repository at this point in the history
…un on label
  • Loading branch information
loicmathieu committed Sep 12, 2023
1 parent 75b0551 commit 8c47569
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ ArrayListTotal<TaskRun> findTaskRun(
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate,
@Nullable List<State.Type> states
@Nullable List<State.Type> states,
@Nullable Map<String, String> labels
);

Execution delete(Execution execution);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.core.repositories;

import com.devskiller.friendly_id.FriendlyId;
import io.kestra.core.models.Label;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.executions.TaskRun;
import io.kestra.core.models.executions.statistics.DailyExecutionStatistics;
Expand Down Expand Up @@ -94,7 +95,8 @@ static State randomDuration(State.Type state) {


protected void inject() {
for (int i = 0; i < 28; i++) {
executionRepository.save(builder(State.Type.RUNNING, null).labels(List.of(new Label("key", "value"))).build());
for (int i = 1; i < 28; i++) {
executionRepository.save(builder(
i < 5 ? State.Type.RUNNING : (i < 8 ? State.Type.FAILED : State.Type.SUCCESS),
i < 15 ? null : "second"
Expand All @@ -112,6 +114,9 @@ protected void find() {

executions = executionRepository.find(Pageable.from(1, 10), null, null, null, null, null, List.of(State.Type.RUNNING, State.Type.FAILED), null);
assertThat(executions.getTotal(), is(8L));

executions = executionRepository.find(Pageable.from(1, 10), null, null, null, null, null, null, Map.of("key", "value"));
assertThat(executions.getTotal(), is(1L));
}

@Test
Expand All @@ -130,9 +135,13 @@ protected void findWithSort() {
protected void findTaskRun() {
inject();

ArrayListTotal<TaskRun> executions = executionRepository.findTaskRun(Pageable.from(1, 10), null, null, null, null, null, null);
assertThat(executions.getTotal(), is(71L));
assertThat(executions.size(), is(10));
ArrayListTotal<TaskRun> taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), null, null, null, null, null, null, null);
assertThat(taskRuns.getTotal(), is(71L));
assertThat(taskRuns.size(), is(10));

taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), null, null, null, null, null, null, Map.of("key", "value"));
assertThat(taskRuns.getTotal(), is(1L));
assertThat(taskRuns.size(), is(1));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public ArrayListTotal<TaskRun> findTaskRun(
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate,
@Nullable List<State.Type> states
@Nullable List<State.Type> states,
@Nullable Map<String, String> labels
) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Flowable<Execution> find(@Nullable String query, @Nullable String namespa
}

@Override
public ArrayListTotal<TaskRun> findTaskRun(Pageable pageable, @Nullable String query, @Nullable String namespace, @Nullable String flowId, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable List<State.Type> states) {
public ArrayListTotal<TaskRun> findTaskRun(Pageable pageable, @Nullable String query, @Nullable String namespace, @Nullable String flowId, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable List<State.Type> states, @Nullable Map<String, String> labels) {
throw new UnsupportedOperationException();
}

Expand Down
10 changes: 9 additions & 1 deletion ui/src/components/taskruns/TaskRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
@update:model-value="onDataTableValue($event)"
/>
</el-form-item>
<el-form-item>
<label-filter
:model-value="$route.query.labels"
@update:model-value="onDataTableValue('labels', $event)"
/>
</el-form-item>
<el-form-item>
<refresh-button class="float-right" @refresh="load" />
</el-form-item>
Expand Down Expand Up @@ -150,6 +156,7 @@
import Id from "../Id.vue";
import _merge from "lodash/merge";
import {stateGlobalChartTypes} from "../../utils/constants";
import LabelFilter from "../labels/LabelFilter.vue";
export default {
mixins: [RouteContext, RestoreUrl, DataTableActions],
Expand All @@ -165,7 +172,8 @@
StateGlobalChart,
DateAgo,
Kicon,
Id
Id,
LabelFilter
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.kestra.core.repositories.ExecutionRepositoryInterface;
import io.kestra.webserver.responses.PagedResults;
import io.kestra.webserver.utils.PageableUtils;
import io.kestra.webserver.utils.RequestUtils;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.convert.format.Format;
Expand Down Expand Up @@ -40,7 +41,8 @@ public PagedResults<TaskRun> findTaskRun(
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
@Parameter(description = "The end datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime endDate,
@Parameter(description = "A state filter") @Nullable @QueryValue List<State.Type> state
@Parameter(description = "A state filter") @Nullable @QueryValue List<State.Type> state,
@Parameter(description = "A labels filter as a list of 'key:value'") @Nullable @QueryValue List<String> labels
) {
return PagedResults.of(executionRepository.findTaskRun(
PageableUtils.from(page, size, sort, executionRepository.sortMapping()),
Expand All @@ -49,7 +51,8 @@ public PagedResults<TaskRun> findTaskRun(
flowId,
startDate,
endDate,
state
state,
RequestUtils.toMap(labels)
));
}

Expand Down

0 comments on commit 8c47569

Please sign in to comment.