-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core,webserver): correlation ID
Automatically set the 'system_correlationId' label to the parent execution id for all child, recursively. This label is the only one that can be set once when starting an execution.
- Loading branch information
1 parent
81c1c3e
commit f169c68
Showing
12 changed files
with
158 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
68 changes: 68 additions & 0 deletions
68
core/src/test/java/io/kestra/plugin/core/flow/CorrelationIdTest.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,68 @@ | ||
package io.kestra.plugin.core.flow; | ||
|
||
import io.kestra.core.models.Label; | ||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.flows.State; | ||
import io.kestra.core.queues.QueueException; | ||
import io.kestra.core.queues.QueueFactoryInterface; | ||
import io.kestra.core.queues.QueueInterface; | ||
import io.kestra.core.runners.AbstractMemoryRunnerTest; | ||
import io.kestra.core.utils.TestsUtils; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import org.junit.jupiter.api.Test; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class CorrelationIdTest extends AbstractMemoryRunnerTest { | ||
@Inject | ||
@Named(QueueFactoryInterface.EXECUTION_NAMED) | ||
private QueueInterface<Execution> executionQueue; | ||
|
||
@Test | ||
void shouldHaveCorrelationId() throws QueueException, TimeoutException, InterruptedException { | ||
CountDownLatch countDownLatch = new CountDownLatch(2); | ||
AtomicReference<Execution> child = new AtomicReference<>(); | ||
AtomicReference<Execution> grandChild = new AtomicReference<>(); | ||
|
||
Flux<Execution> receive = TestsUtils.receive(executionQueue, either -> { | ||
Execution execution = either.getLeft(); | ||
if (execution.getFlowId().equals("subflow-child") && execution.getState().getCurrent().isTerminated()) { | ||
countDownLatch.countDown(); | ||
child.set(execution); | ||
} | ||
if (execution.getFlowId().equals("subflow-grand-child") && execution.getState().getCurrent().isTerminated()) { | ||
countDownLatch.countDown(); | ||
grandChild.set(execution); | ||
} | ||
}); | ||
|
||
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "subflow-parent"); | ||
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); | ||
|
||
assertTrue(countDownLatch.await(1, TimeUnit.MINUTES)); | ||
receive.blockLast(); | ||
|
||
assertThat(child.get(), notNullValue()); | ||
assertThat(child.get().getState().getCurrent(), is(State.Type.SUCCESS)); | ||
Optional<Label> correlationId = child.get().getLabels().stream().filter(label -> label.key().equals(Label.CORRELATION_ID)).findAny(); | ||
assertThat(correlationId.isPresent(), is(true)); | ||
assertThat(correlationId.get().value(), is(execution.getId())); | ||
|
||
assertThat(grandChild.get(), notNullValue()); | ||
assertThat(grandChild.get().getState().getCurrent(), is(State.Type.SUCCESS)); | ||
correlationId = grandChild.get().getLabels().stream().filter(label -> label.key().equals(Label.CORRELATION_ID)).findAny(); | ||
assertThat(correlationId.isPresent(), is(true)); | ||
assertThat(correlationId.get().value(), is(execution.getId())); | ||
} | ||
} |
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
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,8 @@ | ||
id: subflow-child | ||
namespace: io.kestra.tests | ||
|
||
tasks: | ||
- id: subflow | ||
type: io.kestra.plugin.core.flow.Subflow | ||
namespace: io.kestra.tests | ||
flowId: subflow-grand-child |
7 changes: 7 additions & 0 deletions
7
core/src/test/resources/flows/valids/subflow-grand-child.yaml
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 @@ | ||
id: subflow-grand-child | ||
namespace: io.kestra.tests | ||
|
||
tasks: | ||
- id: firstLevel | ||
type: io.kestra.plugin.core.log.Log | ||
message: "My grandparent is {{labels.system_correlationId}}" |
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,8 @@ | ||
id: subflow-parent | ||
namespace: io.kestra.tests | ||
|
||
tasks: | ||
- id: subflow | ||
type: io.kestra.plugin.core.flow.Subflow | ||
namespace: io.kestra.tests | ||
flowId: subflow-child |
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