Skip to content

Commit

Permalink
feat(core, jdbc, webserver): allow to filter logs by triggerId
Browse files Browse the repository at this point in the history
Part-of: #4245
  • Loading branch information
loicmathieu committed Jul 15, 2024
1 parent 2416760 commit 0125d50
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ArrayListTotal<LogEntry> find(
@Nullable String tenantId,
@Nullable String namespace,
@Nullable String flowId,
@Nullable String triggerId,
@Nullable Level minLevel,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ private static LogEntry.LogEntryBuilder logEntry(Level level) {
void all() {
LogEntry.LogEntryBuilder builder = logEntry(Level.INFO);

ArrayListTotal<LogEntry> find = logRepository.find(Pageable.UNPAGED, null, null, null, null, null, null, null);
ArrayListTotal<LogEntry> find = logRepository.find(Pageable.UNPAGED, null, null, null, null, null, null, null, null);
assertThat(find.size(), is(0));

LogEntry save = logRepository.save(builder.build());

find = logRepository.find(Pageable.UNPAGED, "doe", null, null, null, null, null, null);
find = logRepository.find(Pageable.UNPAGED, "doe", null, null, null, null, null, null, null);
assertThat(find.size(), is(1));
assertThat(find.getFirst().getExecutionId(), is(save.getExecutionId()));

find = logRepository.find(Pageable.UNPAGED, "doe", null, null, null, Level.WARN,null, null);
find = logRepository.find(Pageable.UNPAGED, "doe", null, null, null, null, Level.WARN,null, null);
assertThat(find.size(), is(0));

find = logRepository.find(Pageable.UNPAGED, null, null, null, null, null, null, null);
find = logRepository.find(Pageable.UNPAGED, null, null, null, null, null, null, null, null);
assertThat(find.size(), is(1));
assertThat(find.getFirst().getExecutionId(), is(save.getExecutionId()));

logRepository.find(Pageable.UNPAGED, "kestra-io/kestra", null, null, null, null, null, null);
logRepository.find(Pageable.UNPAGED, "kestra-io/kestra", null, null, null, null, null, null, null);
assertThat(find.size(), is(1));
assertThat(find.getFirst().getExecutionId(), is(save.getExecutionId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public AbstractJdbcLogRepository(io.kestra.jdbc.AbstractJdbcRepository<LogEntry>

abstract protected Condition findCondition(String query);

@Override
public ArrayListTotal<LogEntry> find(
Pageable pageable,
@Nullable String query,
@Nullable String tenantId,
@Nullable String namespace,
@Nullable String flowId,
@Nullable String triggerId,
@Nullable Level minLevel,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate
Expand All @@ -54,7 +56,7 @@ public ArrayListTotal<LogEntry> find(
.from(this.jdbcRepository.getTable())
.where(this.defaultFilter(tenantId));

this.filter(select, query, namespace, flowId, minLevel, startDate , endDate);
this.filter(select, query, namespace, flowId, triggerId, minLevel, startDate , endDate);

return this.jdbcRepository.fetchPage(context, select, pageable);
});
Expand All @@ -65,6 +67,7 @@ private <T extends Record> SelectConditionStep<T> filter(
@Nullable String query,
@Nullable String namespace,
@Nullable String flowId,
@Nullable String triggerId,
@Nullable Level minLevel,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate
Expand All @@ -77,6 +80,10 @@ private <T extends Record> SelectConditionStep<T> filter(
select = select.and(field("flow_id").eq(flowId));
}

if (triggerId != null) {
select = select.and(field("trigger_id").eq(triggerId));
}

if (minLevel != null) {
select = select.and(minLevel(minLevel));
}
Expand All @@ -96,6 +103,7 @@ private <T extends Record> SelectConditionStep<T> filter(
return select;
}

@Override
public List<LogStatistics> statistics(
@Nullable String query,
@Nullable String tenantId,
Expand Down Expand Up @@ -130,7 +138,7 @@ public List<LogStatistics> statistics(
.from(this.jdbcRepository.getTable())
.where(this.defaultFilter(tenantId));

this.filter(select, query, namespace, flowId, minLevel, startDate, endDate);
this.filter(select, query, namespace, flowId, null, minLevel, startDate, endDate);

List<Field<?>> groupFields = new ArrayList<>(fields);
groupFields.addAll(dateFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public PagedResults<LogEntry> find(
@Parameter(description = "The sort of current page") @Nullable @QueryValue List<String> sort,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "A trigger id filter") @Nullable @QueryValue String triggerId,
@Parameter(description = "The min log level filter") @Nullable @QueryValue Level minLevel,
@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
) {
validateTimeline(startDate, endDate);

return PagedResults.of(
logRepository.find(PageableUtils.from(page, size, sort), query, tenantService.resolveTenant(), namespace, flowId, minLevel, startDate, endDate)
logRepository.find(PageableUtils.from(page, size, sort), query, tenantService.resolveTenant(), namespace, flowId, triggerId, minLevel, startDate, endDate)
);
}

Expand Down

0 comments on commit 0125d50

Please sign in to comment.