-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jdbc): implementation of log repository
- Loading branch information
1 parent
7e16b71
commit 94aaad9
Showing
23 changed files
with
523 additions
and
131 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
core/src/test/java/io/kestra/core/repositories/AbstractLogRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.kestra.core.repositories; | ||
|
||
import io.kestra.core.models.executions.LogEntry; | ||
import io.kestra.core.utils.IdUtils; | ||
import io.micronaut.data.model.Pageable; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.event.Level; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest(transactional = false) | ||
public abstract class AbstractLogRepositoryTest { | ||
@Inject | ||
protected LogRepositoryInterface logRepository; | ||
|
||
private static LogEntry.LogEntryBuilder logEntry() { | ||
return LogEntry.builder() | ||
.flowId(IdUtils.create()) | ||
.namespace("io.kestra.unittest") | ||
.taskId("taskId") | ||
.executionId(IdUtils.create()) | ||
.taskRunId(IdUtils.create()) | ||
.attemptNumber(0) | ||
.timestamp(Instant.now()) | ||
.level(Level.INFO) | ||
.thread("") | ||
.message("john doe"); | ||
} | ||
|
||
@Test | ||
void all() { | ||
LogEntry.LogEntryBuilder builder = logEntry(); | ||
|
||
ArrayListTotal<LogEntry> find = logRepository.find("*", Pageable.UNPAGED, null); | ||
assertThat(find.size(), is(0)); | ||
|
||
LogEntry save = logRepository.save(builder.build()); | ||
|
||
find = logRepository.find("doe", Pageable.UNPAGED, null); | ||
assertThat(find.size(), is(1)); | ||
assertThat(find.get(0).getExecutionId(), is(save.getExecutionId())); | ||
|
||
find = logRepository.find("*", Pageable.UNPAGED, null); | ||
assertThat(find.size(), is(1)); | ||
assertThat(find.get(0).getExecutionId(), is(save.getExecutionId())); | ||
|
||
List<LogEntry> list = logRepository.findByExecutionId(save.getExecutionId(), null); | ||
assertThat(list.size(), is(1)); | ||
assertThat(list.get(0).getExecutionId(), is(save.getExecutionId())); | ||
|
||
list = logRepository.findByExecutionIdAndTaskId(save.getExecutionId(), save.getTaskId(), null); | ||
assertThat(list.size(), is(1)); | ||
assertThat(list.get(0).getExecutionId(), is(save.getExecutionId())); | ||
|
||
|
||
list = logRepository.findByExecutionIdAndTaskRunId(save.getExecutionId(), save.getTaskRunId(), null); | ||
assertThat(list.size(), is(1)); | ||
assertThat(list.get(0).getExecutionId(), is(save.getExecutionId())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
jdbc-mysql/src/main/java/io/kestra/repository/mysql/MysqlLogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.kestra.repository.mysql; | ||
|
||
import io.kestra.core.models.executions.LogEntry; | ||
import io.kestra.jdbc.repository.AbstractLogRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import org.jooq.Condition; | ||
|
||
import java.util.Arrays; | ||
|
||
@Singleton | ||
@MysqlRepositoryEnabled | ||
public class MysqlLogRepository extends AbstractLogRepository { | ||
@Inject | ||
public MysqlLogRepository(ApplicationContext applicationContext) { | ||
super(new MysqlRepository<>(LogEntry.class, applicationContext)); | ||
} | ||
|
||
@Override | ||
protected Condition findCondition(String query) { | ||
return this.jdbcRepository.fullTextCondition(Arrays.asList("namespace", "flow_id", "task_id", "execution_id", "taskrun_id", "trigger_id", "message", "thread"), query); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
jdbc-mysql/src/test/java/io/kestra/repository/mysql/MysqlLogRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.kestra.repository.mysql; | ||
|
||
import io.kestra.jdbc.repository.AbstractJdbcLogRepositoryTest; | ||
|
||
public class MysqlLogRepositoryTest extends AbstractJdbcLogRepositoryTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
jdbc-postgres/src/main/java/io/kestra/repository/postgres/PostgresLogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.kestra.repository.postgres; | ||
|
||
import io.kestra.core.models.executions.LogEntry; | ||
import io.kestra.core.models.triggers.Trigger; | ||
import io.kestra.core.repositories.LogRepositoryInterface; | ||
import io.kestra.core.repositories.TriggerRepositoryInterface; | ||
import io.kestra.jdbc.repository.AbstractLogRepository; | ||
import io.kestra.jdbc.repository.AbstractTriggerRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import org.jooq.Condition; | ||
|
||
import java.util.Collections; | ||
|
||
@Singleton | ||
@PostgresRepositoryEnabled | ||
public class PostgresLogRepository extends AbstractLogRepository implements LogRepositoryInterface { | ||
@Inject | ||
public PostgresLogRepository(ApplicationContext applicationContext) { | ||
super(new PostgresRepository<>(LogEntry.class, applicationContext)); | ||
} | ||
|
||
@Override | ||
protected Condition findCondition(String query) { | ||
return this.jdbcRepository.fullTextCondition(Collections.singletonList("fulltext"), query); | ||
} | ||
} |
Oops, something went wrong.