diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ConcordConfiguration.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ConcordConfiguration.java index ee76fa2f16..f986a90e23 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ConcordConfiguration.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ConcordConfiguration.java @@ -58,7 +58,16 @@ public static ConcordRule configure() { .streamAgentLogs(true) .sharedContainerDir(sharedDir) .useLocalMavenRepository(true) - .extraConfigurationSupplier(() -> "concord-agent { prefork { enabled = true } }"); + .extraConfigurationSupplier(() -> """ + concord-agent { + dependencyResolveTimeout = "5 seconds" + logMaxDelay = "250 milliseconds" + pollInterval = "250 milliseconds" + prefork { + enabled = true + } + } + """); boolean localMode = Boolean.parseBoolean(System.getProperty("it.local.mode")); if (localMode) { diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/CryptoIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/CryptoIT.java index cc138f5678..54866dc8f2 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/CryptoIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/CryptoIT.java @@ -36,7 +36,7 @@ public class CryptoIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure(); + public static final ConcordRule concord = ConcordConfiguration.configure(); /** * Tests various methods of the 'crypto' plugin. diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/FormIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/FormIT.java index f652db0411..f22d1ec1cd 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/FormIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/FormIT.java @@ -49,7 +49,7 @@ public class FormIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure(); + public static final ConcordRule concord = ConcordConfiguration.configure(); /** * A straightforward single form process. diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ImportsIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ImportsIT.java index c59cc3289d..0ac2c3e19b 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ImportsIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/ImportsIT.java @@ -40,7 +40,7 @@ public class ImportsIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure() + public static final ConcordRule concord = ConcordConfiguration.configure() .extraConfigurationSupplier(() -> "concord-server { imports { disabledProcessors = [] } }\n" + "concord-agent { imports { disabledProcessors = [] } }"); diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/JsonStoreIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/JsonStoreIT.java index 4143599edf..078f54f690 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/JsonStoreIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/JsonStoreIT.java @@ -35,7 +35,7 @@ public class JsonStoreIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure(); + public static final ConcordRule concord = ConcordConfiguration.configure(); /** * Tests various methods of the 'jsonStore' plugin. diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/KvTaskIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/KvTaskIT.java index 0798ceb330..aab8d0717a 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/KvTaskIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/KvTaskIT.java @@ -32,7 +32,7 @@ public class KvTaskIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure(); + public static final ConcordRule concord = ConcordConfiguration.configure(); /** * Tests various methods of the 'kv' plugin. diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/NodeRosterIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/NodeRosterIT.java index fd72198018..f41bb1e133 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/NodeRosterIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/NodeRosterIT.java @@ -36,7 +36,7 @@ public class NodeRosterIT extends AbstractTest { @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure(); + public static final ConcordRule concord = ConcordConfiguration.configure(); /** * Tests various methods of the 'noderoster' plugin. diff --git a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/SmtpIT.java b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/SmtpIT.java index 453d05f349..2e74d2d1a5 100644 --- a/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/SmtpIT.java +++ b/it/runtime-v2/src/test/java/com/walmartlabs/concord/it/runtime/v2/SmtpIT.java @@ -40,10 +40,11 @@ public class SmtpIT extends AbstractTest { @RegisterExtension - GreenMailExtension mailServer = new GreenMailExtension(new ServerSetup(0, "0.0.0.0", ServerSetup.PROTOCOL_SMTP)); + public static final GreenMailExtension mailServer = new GreenMailExtension(new ServerSetup(0, "0.0.0.0", ServerSetup.PROTOCOL_SMTP)) + .withPerMethodLifecycle(false); @RegisterExtension - public final ConcordRule concord = ConcordConfiguration.configure() + public static final ConcordRule concord = ConcordConfiguration.configure() .containerListener(new ContainerListener() { @Override public void beforeStart(ContainerType type) { diff --git a/it/server/src/test/resources/agent.conf b/it/server/src/test/resources/agent.conf index 3cda4cca14..a3eee4c129 100644 --- a/it/server/src/test/resources/agent.conf +++ b/it/server/src/test/resources/agent.conf @@ -1,5 +1,9 @@ concord-agent { + dependencyResolveTimeout = "5 seconds" + logMaxDelay = "250 milliseconds" + pollInterval = "250 milliseconds" + prefork { enabled = true } diff --git a/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/DefaultEventReportingService.java b/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/DefaultEventReportingService.java index b7edd244a9..4b82894b7d 100644 --- a/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/DefaultEventReportingService.java +++ b/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/DefaultEventReportingService.java @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.List; import java.util.TimerTask; +import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; @@ -53,14 +54,17 @@ public class DefaultEventReportingService implements EventReportingService, Exec private final int maxBatchSize; private final Object batchLock = new Object(); private final ScheduledExecutorService flushScheduler; + private final PersistenceService persistenceService; @Inject public DefaultEventReportingService(InstanceId instanceId, ProcessConfiguration processConfiguration, - ApiClient apiClient) { + ApiClient apiClient, + PersistenceService persistenceService) { this.instanceId = instanceId; this.processEventsApi = new ProcessEventsApi(apiClient); this.maxBatchSize = processConfiguration.events().batchSize(); + this.persistenceService = persistenceService; this.eventQueue = initializeQueue(maxBatchSize); this.flushScheduler = Executors.newSingleThreadScheduledExecutor(); @@ -132,6 +136,9 @@ private void sendBatch(List eventBatch) { try { getProcessEventsApi().batchEvent(instanceId.getValue(), eventBatch); } catch (ApiException e) { + for (var event: eventBatch) { + saveEvent(event); + } log.warn("Error while sending batch of {} event{} to the server: {}", eventBatch.size(), eventBatch.isEmpty() ? "" : "s", e.getMessage()); } @@ -141,6 +148,7 @@ private void sendSingle(ProcessEventRequest req) { try { getProcessEventsApi().event(instanceId.getValue(), req); } catch (ApiException e) { + saveEvent(req); log.warn("error while sending an event to the server: {}", e.getMessage()); } } @@ -171,4 +179,11 @@ public void run() { } } + private void saveEvent(ProcessEventRequest event) { + try { + persistenceService.persistFile("invalid_event_" + UUID.randomUUID() + ".json", out -> processEventsApi.getApiClient().getObjectMapper().writeValue(out, event)); + } catch (Exception e) { + log.warn("can't save event", e); + } + } } diff --git a/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/EventReportingServiceTest.java b/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/EventReportingServiceTest.java index 7cb59158cb..ea9b8705c9 100644 --- a/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/EventReportingServiceTest.java +++ b/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/EventReportingServiceTest.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -81,7 +81,7 @@ private static class MockedEventReportingService extends DefaultEventReportingSe private final AtomicInteger flushCounter; public MockedEventReportingService(ProcessConfiguration processConfiguration) { - super(new InstanceId(UUID.randomUUID()), processConfiguration, mock(ApiClient.class)); + super(new InstanceId(UUID.randomUUID()), processConfiguration, mock(ApiClient.class), mock(PersistenceService.class)); this.mockProcessEventsApi = mock(ProcessEventsApi.class); this.flushCounter = new AtomicInteger(); } diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordObjectMapper.java b/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordObjectMapper.java index 502086d3e7..9709a47bf7 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordObjectMapper.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordObjectMapper.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,6 +29,7 @@ import javax.inject.Singleton; import java.io.IOException; import java.util.Map; +import java.util.regex.Pattern; @Named @Singleton @@ -37,6 +38,8 @@ public class ConcordObjectMapper { public static final TypeReference> MAP_TYPE = new TypeReference>() { }; + private static final Pattern CONTROL_CHARS = Pattern.compile("[\\x00-\\x1F]"); + private final ObjectMapper delegate; @Inject @@ -113,7 +116,7 @@ public T fromString(String s, Class valueType) { } private static String removeUnsupportedEscape(String str) { - return str.replace("\\u0000", ""); + return CONTROL_CHARS.matcher(str).replaceAll(""); } private T deserialize(String o, TypeReference valueTypeRef) {