diff --git a/docs/services/lambda.md b/docs/services/lambda.md index 0f66bcd99b..b6e75fe83e 100644 --- a/docs/services/lambda.md +++ b/docs/services/lambda.md @@ -817,6 +817,12 @@ is a permanent diff rather than a cosmetic omission. `LoggingConfig` is replaced wholesale on update, not merged — an update naming only `LogFormat` resets `LogGroup` to the default. +A function's execution environments write their logs, `START`, `END` and `REPORT` +included, to the `LogGroup` its `LoggingConfig` names, creating the group when it does not +exist, and `AWS_LAMBDA_LOG_GROUP_NAME` names that group. Once a group is named, which several +functions can share, each stream's name carries the function's name, as on AWS: +`2026/10/16/my-fn[$LATEST]` rather than the default group's `2026/10/16/[$LATEST]`. + `DurableConfig` requires `ExecutionTimeout` on create. A durable function created without a `Timeout` gets `min(ExecutionTimeout, 900)`. It always logs in JSON format, and `LogFormat: Text` is rejected. On update the members are merged, and a function created diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryService.java b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryService.java index da22f6c6a6..4cf071d926 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryService.java @@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudwatch.logs; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.core.common.AwsArnUtils; +import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend; import io.github.hectorvent.floci.core.storage.StorageBackend; @@ -13,8 +14,10 @@ import io.github.hectorvent.floci.services.firehose.FirehoseService; import io.github.hectorvent.floci.services.firehose.model.Record; import io.github.hectorvent.floci.services.kinesis.KinesisService; import io.github.hectorvent.floci.services.lambda.LambdaArnUtils; +import io.github.hectorvent.floci.services.lambda.LambdaLogDestinations; import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambda.model.InvocationType; +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; import io.quarkus.runtime.annotations.RegisterForReflection; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; @@ -46,7 +49,6 @@ public class CloudWatchLogsSubscriptionDeliveryService { private static final Logger LOG = Logger.getLogger(CloudWatchLogsSubscriptionDeliveryService.class); private static final String DATA_MESSAGE = "DATA_MESSAGE"; - private static final String LAMBDA_LOG_PREFIX = "/aws/lambda/"; /** Max compressed record size for Kinesis and Firehose delivery (1 MB). */ private static final int MAX_RECORD_PAYLOAD_BYTES = 1_000_000; @@ -163,9 +165,9 @@ public class CloudWatchLogsSubscriptionDeliveryService { String service = arn.service(); if ("lambda".equals(service)) { - if (isSelfSubscribedLambda(event.logGroupName(), destinationArn)) { - LOG.warnv("Skipping delivery to Lambda destination {0} to prevent recursive loop on its own log group {1}", - destinationArn, event.logGroupName()); + if (isOwnOutput(event, destinationArn)) { + LOG.warnv("Skipping delivery to Lambda destination {0} to prevent recursive loop on its own log stream {1} in {2}", + destinationArn, event.logStreamName(), event.logGroupName()); return; } deliverChunks(filter, event, account, matching, gzipped -> deliverToLambda(destinationArn, gzipped)); @@ -180,17 +182,38 @@ public class CloudWatchLogsSubscriptionDeliveryService { } } - private boolean isSelfSubscribedLambda(String logGroupName, String functionArn) { - if (logGroupName == null || functionArn == null || !logGroupName.startsWith(LAMBDA_LOG_PREFIX)) { + /** + * Whether the event is the destination function's own output, which delivering would feed back + * to it forever. Floci skips only that: the function is the one the destination ARN names, with + * its account, Region and version or alias, and its output is in the group its LoggingConfig + * names, or else {@code /aws/lambda/}. A named group can be shared, so there only the + * function's own streams are skipped, and another function's logs in it still reach it. + */ + private boolean isOwnOutput(LogEventsIngested event, String functionArn) { + String logGroupName = event.logGroupName(); + if (logGroupName == null) { return false; } - String logFunctionName = logGroupName.substring(LAMBDA_LOG_PREFIX.length()); + String functionName; try { - String targetFunctionName = LambdaArnUtils.resolve(functionArn).name(); - return logFunctionName.equals(targetFunctionName); - } catch (Exception e) { + functionName = LambdaArnUtils.resolve(functionArn).name(); + } catch (AwsException e) { + // Not a function ARN: invoking it fails as well, so there is no loop to break. return false; } + LambdaFunction target = null; + if (lambdaService != null) { + try { + target = lambdaService.getFunctionByArn(functionArn); + } catch (AwsException e) { + LOG.debugv("Destination function {0} not found: {1}", functionArn, e.getMessage()); + } + } + if (target == null) { + return logGroupName.equals(LambdaLogDestinations.defaultLogGroup(functionName)); + } + return logGroupName.equals(LambdaLogDestinations.logGroup(target)) + && LambdaLogDestinations.isOwnStream(target, event.logStreamName()); } @FunctionalInterface diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java index 7dfa7a6428..ef172dd697 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java @@ -862,9 +862,7 @@ public class LambdaController { logging.put("SystemLogLevel", fn.getSystemLogLevel() != null ? fn.getSystemLogLevel() : "INFO"); } - logging.put("LogGroup", fn.getLogGroup() != null && !fn.getLogGroup().isBlank() - ? fn.getLogGroup() - : "/aws/lambda/" + fn.getFunctionName()); + logging.put("LogGroup", LambdaLogDestinations.logGroup(fn)); } /** Managed-runtime only: AWS omits it for container images, which pin their own runtime. */ diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinations.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinations.java new file mode 100644 index 0000000000..7434fbae06 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinations.java @@ -0,0 +1,47 @@ +package io.github.hectorvent.floci.services.lambda; + +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; + +/** + * Where a function's execution environments write their logs: the log group its LoggingConfig + * names, else {@code /aws/lambda/}. Once LoggingConfig names a group, which several + * functions can share, AWS puts the function's name in each stream's name, even when the group + * named is the default one: {@code 2026/10/16/my-fn[$LATEST]} rather than + * {@code 2026/10/16/[$LATEST]}. + */ +public final class LambdaLogDestinations { + + private LambdaLogDestinations() { + } + + public static String logGroup(LambdaFunction fn) { + return namesLogGroup(fn) ? fn.getLogGroup() : defaultLogGroup(fn.getFunctionName()); + } + + /** The group of a function whose LoggingConfig names none: {@code /aws/lambda/}. */ + public static String defaultLogGroup(String functionName) { + return "/aws/lambda/" + functionName; + } + + /** The stream's name after its {@code yyyy/MM/dd/} date, for the environment {@code instanceId}. */ + public static String logStreamSuffix(LambdaFunction fn, String instanceId) { + String version = "[$LATEST]" + instanceId; + return namesLogGroup(fn) ? fn.getFunctionName() + version : version; + } + + /** + * Whether {@code logStreamName} in the function's log group is the function's own: every stream + * of the default group is, and in a group LoggingConfig names, which several functions can + * share, the ones that carry its name. + */ + public static boolean isOwnStream(LambdaFunction fn, String logStreamName) { + if (!namesLogGroup(fn)) { + return true; + } + return logStreamName != null && logStreamName.contains("/" + fn.getFunctionName() + "["); + } + + private static boolean namesLogGroup(LambdaFunction fn) { + return fn.getLogGroup() != null && !fn.getLogGroup().isBlank(); + } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncher.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncher.java index 0f6935f339..d68071c8e5 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncher.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncher.java @@ -17,6 +17,7 @@ import io.github.hectorvent.floci.core.common.docker.RetryingTarCopier; import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager; import io.github.hectorvent.floci.services.iam.model.SessionCreds; import io.github.hectorvent.floci.services.lambda.LambdaLayerService; +import io.github.hectorvent.floci.services.lambda.LambdaLogDestinations; import io.github.hectorvent.floci.services.lambda.model.ContainerState; import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; import io.github.hectorvent.floci.services.lambda.model.LambdaLayerVersion; @@ -213,8 +214,9 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { resolveContainerNamePrefix(config), fn.getFunctionName() + "-" + shortId); // CloudWatch log coordinates — computed here so they can be injected as env vars - String cwLogGroup = "/aws/lambda/" + fn.getFunctionName(); - String cwLogStream = LOG_STREAM_DATE_FMT.format(LocalDate.now()) + "/[$LATEST]" + shortId; + String cwLogGroup = LambdaLogDestinations.logGroup(fn); + String cwLogStream = LOG_STREAM_DATE_FMT.format(LocalDate.now()) + "/" + + LambdaLogDestinations.logStreamSuffix(fn, shortId); String lambdaRegion = extractRegionFromArn(fn.getFunctionArn(), config.defaultRegion()); String lambdaAccountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId()); LambdaDockerFlags dockerFlags = configuredDockerFlags(); diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncher.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncher.java index 08df2bc798..19633fffb4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncher.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncher.java @@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.docker.LaunchedContainerAwsEnv; import io.github.hectorvent.floci.services.lambda.LambdaLayerService; +import io.github.hectorvent.floci.services.lambda.LambdaLogDestinations; import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambda.launcher.ContainerHandle; import io.github.hectorvent.floci.services.lambda.launcher.ContainerLauncher; @@ -175,8 +176,8 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher { podName = LambdaPodSpecFactory.podName(fn.getFunctionName(), shortId); String region = AwsArnUtils.regionOrDefault(fn.getFunctionArn(), config.defaultRegion()); String accountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId()); - String cwLogGroup = "/aws/lambda/" + fn.getFunctionName(); - String cwLogStream = logStreamer.logStreamName(shortId); + String cwLogGroup = LambdaLogDestinations.logGroup(fn); + String cwLogStream = logStreamer.logStreamName(fn, shortId); String codeDownloadUrl = imagePackage ? null : codeDownloadUrl(fn, region); List layerUrls = imagePackage ? List.of() : layerDownloadUrls(fn, region); diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLogStreamer.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLogStreamer.java index ce5483d443..8ce62fe308 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLogStreamer.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLogStreamer.java @@ -1,6 +1,8 @@ package io.github.hectorvent.floci.services.lambda.launcher.kubernetes; import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer; +import io.github.hectorvent.floci.services.lambda.LambdaLogDestinations; +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import org.jboss.logging.Logger; @@ -33,8 +35,8 @@ public class KubernetesPodLogStreamer { } /** CloudWatch log stream name for one execution environment, same shape as the docker path. */ - public String logStreamName(String shortId) { - return cloudWatchWriter.generateLogStreamName("[$LATEST]" + shortId); + public String logStreamName(LambdaFunction fn, String shortId) { + return cloudWatchWriter.generateLogStreamName(LambdaLogDestinations.logStreamSuffix(fn, shortId)); } public Closeable attach(String namespace, String podName, String logGroup, diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryServiceTest.java index 4dc7face44..3301ddb74a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsSubscriptionDeliveryServiceTest.java @@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.firehose.model.Record; import io.github.hectorvent.floci.services.kinesis.KinesisService; import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambda.model.InvocationType; +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; import jakarta.enterprise.event.Event; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,13 +32,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; class CloudWatchLogsSubscriptionDeliveryServiceTest { @@ -375,7 +379,82 @@ class CloudWatchLogsSubscriptionDeliveryServiceTest { ), REGION); assertNotNull(nextToken); - verifyNoInteractions(lambdaService); + verify(lambdaService, never()).invokeArn(anyString(), any(), any()); + } + + /** + * A function whose LoggingConfig names a group writes there, so a subscription that sends that + * group to the function itself is skipped too, and delivered again once the function writes to + * its default group instead. + */ + @Test + void aFunctionSubscribedToTheCustomGroupItWritesToIsSkipped() { + String shared = "/shared/app"; + String forwarderArn = "arn:aws:lambda:us-east-1:" + ACCOUNT + ":function:forwarder"; + LambdaFunction forwarder = new LambdaFunction(); + forwarder.setFunctionName("forwarder"); + forwarder.setLogGroup(shared); + when(lambdaService.getFunctionByArn(forwarderArn)).thenReturn(forwarder); + logsService.createLogGroup(shared, null, null, REGION); + logsService.createLogStream(shared, "2026/10/16/forwarder[$LATEST]abc", REGION); + logsService.putSubscriptionFilter(shared, "loop-filter", "", forwarderArn, null, REGION); + + logsService.putLogEvents(shared, "2026/10/16/forwarder[$LATEST]abc", List.of( + Map.of("timestamp", 5000L, "message", "forwarder log line")), REGION); + verify(lambdaService, never()).invokeArn(anyString(), any(), any()); + + forwarder.setLogGroup(null); + logsService.putLogEvents(shared, "2026/10/16/forwarder[$LATEST]abc", List.of( + Map.of("timestamp", 5001L, "message", "another function's log line")), REGION); + verify(lambdaService).invokeArn(eq(forwarderArn), any(), eq(InvocationType.Event)); + } + + /** + * A group LoggingConfig names can be shared: the forwarder subscribed to it gets the other + * functions' streams, and only its own, the ones carrying its name, are skipped. + */ + @Test + void anotherFunctionsLogsInASharedGroupStillReachTheForwarder() { + String shared = "/shared/app"; + String forwarderArn = "arn:aws:lambda:us-east-1:" + ACCOUNT + ":function:forwarder"; + LambdaFunction forwarder = new LambdaFunction(); + forwarder.setFunctionName("forwarder"); + forwarder.setLogGroup(shared); + when(lambdaService.getFunctionByArn(forwarderArn)).thenReturn(forwarder); + logsService.createLogGroup(shared, null, null, REGION); + logsService.createLogStream(shared, "2026/10/17/forwarder[$LATEST]abc", REGION); + logsService.createLogStream(shared, "2026/10/17/billing[$LATEST]def", REGION); + logsService.putSubscriptionFilter(shared, "forward-filter", "", forwarderArn, null, REGION); + + logsService.putLogEvents(shared, "2026/10/17/forwarder[$LATEST]abc", List.of( + Map.of("timestamp", 5000L, "message", "forwarder log line")), REGION); + verify(lambdaService, never()).invokeArn(anyString(), any(), any()); + + logsService.putLogEvents(shared, "2026/10/17/billing[$LATEST]def", List.of( + Map.of("timestamp", 5001L, "message", "billing log line")), REGION); + verify(lambdaService).invokeArn(eq(forwarderArn), any(), eq(InvocationType.Event)); + } + + /** + * A destination naming a published version is checked against that version's LoggingConfig, + * looked up by the ARN with its account and qualifier, not against {@code $LATEST}'s. + */ + @Test + void aPublishedVersionIsCheckedAgainstItsOwnLogGroup() { + String versionGroup = "/forwarder/v1"; + String versionArn = "arn:aws:lambda:us-east-1:" + ACCOUNT + ":function:forwarder:1"; + LambdaFunction version = new LambdaFunction(); + version.setFunctionName("forwarder"); + version.setLogGroup(versionGroup); + when(lambdaService.getFunctionByArn(versionArn)).thenReturn(version); + logsService.createLogGroup(versionGroup, null, null, REGION); + logsService.createLogStream(versionGroup, "2026/10/17/forwarder[$LATEST]abc", REGION); + logsService.putSubscriptionFilter(versionGroup, "loop-filter", "", versionArn, null, REGION); + + logsService.putLogEvents(versionGroup, "2026/10/17/forwarder[$LATEST]abc", List.of( + Map.of("timestamp", 5000L, "message", "version log line")), REGION); + + verify(lambdaService, never()).invokeArn(anyString(), any(), any()); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinationsTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinationsTest.java new file mode 100644 index 0000000000..a6f4145e15 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLogDestinationsTest.java @@ -0,0 +1,64 @@ +package io.github.hectorvent.floci.services.lambda; + +import io.github.hectorvent.floci.services.lambda.model.LambdaFunction; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Measured on AWS (eu-west-1, 2026-10-16): with no LoggingConfig a stream is + * {@code 2026/10/16/[$LATEST]} in {@code /aws/lambda/}; once LoggingConfig names a log + * group, the default one's name included, the stream is {@code 2026/10/16/[$LATEST]}. + */ +class LambdaLogDestinationsTest { + + @Test + void aFunctionWithoutLoggingConfigWritesToItsOwnGroup() { + LambdaFunction fn = function(); + + assertEquals("/aws/lambda/orders", LambdaLogDestinations.logGroup(fn)); + assertEquals("[$LATEST]1a2b3c4d", LambdaLogDestinations.logStreamSuffix(fn, "1a2b3c4d")); + } + + @Test + void aGroupLoggingConfigNamesTakesTheLogsAndTheFunctionNameInEachStream() { + LambdaFunction fn = function(); + fn.setLogGroup("/shared/app-logs"); + + assertEquals("/shared/app-logs", LambdaLogDestinations.logGroup(fn)); + assertEquals("orders[$LATEST]1a2b3c4d", LambdaLogDestinations.logStreamSuffix(fn, "1a2b3c4d")); + } + + @Test + void inASharedGroupOnlyTheStreamsCarryingTheFunctionNameAreItsOwn() { + LambdaFunction fn = function(); + fn.setLogGroup("/shared/app-logs"); + + assertTrue(LambdaLogDestinations.isOwnStream(fn, "2026/10/17/orders[$LATEST]1a2b3c4d")); + assertFalse(LambdaLogDestinations.isOwnStream(fn, "2026/10/17/orders-archive[$LATEST]1a2b3c4d")); + assertFalse(LambdaLogDestinations.isOwnStream(fn, "2026/10/17/billing[$LATEST]1a2b3c4d")); + assertFalse(LambdaLogDestinations.isOwnStream(fn, null)); + } + + @Test + void everyStreamOfTheDefaultGroupIsTheFunctionsOwn() { + assertTrue(LambdaLogDestinations.isOwnStream(function(), "2026/10/17/[$LATEST]1a2b3c4d")); + } + + @Test + void namingTheDefaultGroupStillPutsTheFunctionNameInEachStream() { + LambdaFunction fn = function(); + fn.setLogGroup("/aws/lambda/orders"); + + assertEquals("/aws/lambda/orders", LambdaLogDestinations.logGroup(fn)); + assertEquals("orders[$LATEST]1a2b3c4d", LambdaLogDestinations.logStreamSuffix(fn, "1a2b3c4d")); + } + + private static LambdaFunction function() { + LambdaFunction fn = new LambdaFunction(); + fn.setFunctionName("orders"); + return fn; + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java index 3925936e67..9a3490c5ae 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java @@ -673,6 +673,34 @@ class ContainerLauncherTest { "a partial user-supplied access key must never override the owner-account baseline"); } + @Test + void launchFunction_writesToTheLogGroupLoggingConfigNames() throws Exception { + Path codePath = Files.createDirectory(tempDir.resolve("custom-log-group")); + + LambdaFunction fn = new LambdaFunction(); + fn.setFunctionName("custom-logs-fn"); + fn.setRuntime("nodejs20.x"); + fn.setHandler("index.handler"); + fn.setCodeLocalPath(codePath.toString()); + fn.setFunctionArn("arn:aws:lambda:us-east-1:000000000000:function:custom-logs-fn"); + fn.setLogGroup("/shared/app-logs"); + + launcher.launch(fn); + + List env = captureRealContainerSpec().env(); + assertTrue(env.contains("AWS_LAMBDA_LOG_GROUP_NAME=/shared/app-logs")); + String stream = env.stream() + .filter(e -> e.startsWith("AWS_LAMBDA_LOG_STREAM_NAME=")) + .findFirst().orElseThrow() + .substring("AWS_LAMBDA_LOG_STREAM_NAME=".length()); + assertTrue(stream.matches("\\d{4}/\\d{2}/\\d{2}/custom-logs-fn\\[\\$LATEST][0-9a-f]{8}"), stream); + verify(logStreamer).ensureLogGroupAndStreamForAccount( + eq("000000000000"), eq("/shared/app-logs"), eq(stream), eq("us-east-1")); + verify(logStreamer).attachForAccount( + eq("000000000000"), eq("container-123"), eq("/shared/app-logs"), eq(stream), + eq("us-east-1"), eq("lambda:custom-logs-fn")); + } + @Test void launchFunction_endpointUsesListenPortNotAdvertisedBaseUrlPort() throws Exception { // docker run -p 4811:4566 -e FLOCI_BASE_URL=http://localhost:4811: 4811 exists only on the diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncherTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncherTest.java index 2950d005ac..34a375b582 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncherTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/KubernetesPodLauncherTest.java @@ -127,7 +127,7 @@ class KubernetesPodLauncherTest { logStreamer = mock(KubernetesPodLogStreamer.class); lenient().when(logStreamer.attachForAccount(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(() -> { }); - lenient().when(logStreamer.logStreamName(anyString())).thenReturn("2026/07/25/[$LATEST]test"); + lenient().when(logStreamer.logStreamName(any(), anyString())).thenReturn("2026/07/25/[$LATEST]test"); s3Service = mock(S3Service.class); presignGenerator = mock(PreSignedUrlGenerator.class); lenient().when(presignGenerator.generatePresignedUrl(anyString(), anyString(), anyString(),