mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(lambda): send a function's logs to the log group its LoggingConfig names (#5895)
* fix(lambda): send a function's logs to the log group its LoggingConfig names Floci stored LoggingConfig.LogGroup and read it back, but every execution environment still wrote to /aws/lambda/<name> and told the function so in AWS_LAMBDA_LOG_GROUP_NAME. Measured on AWS (eu-west-1, 2026-10-16): a function whose LoggingConfig names a group writes INIT_START, START, its own output, END and REPORT there, Lambda creates the group when it is missing, and /aws/lambda/<name> is never created. AWS_LAMBDA_LOG_GROUP_NAME and AWS_LAMBDA_LOG_STREAM_NAME name that group and stream. Once LoggingConfig names a group, which several functions can share, each stream's name carries the function's name: 2026/10/16/my-fn[$LATEST]<id> instead of 2026/10/16/[$LATEST]<id>. It does even when the group named is /aws/lambda/<name> itself, so the rule is whether a group is named, not whether it differs from the default. Both launchers, Docker and Kubernetes, and GetFunctionConfiguration's LoggingConfig now take the group and the stream from one place, LambdaLogDestinations. Floci skips delivering a log group to a Lambda subscription destination that writes its own logs there, which would feed the function its own output forever. That check assumed the group was /aws/lambda/<name>, so a forwarder subscribed to the group its LoggingConfig names would loop. It now asks LambdaLogDestinations for the function's group, and falls back to the default name, from the same place, for a function it cannot find. * fix(logs): skip only a function's own streams when it forwards its log group The guard that keeps a subscription from feeding a Lambda destination its own output looked the function up by name in the caller's account and Region at $LATEST, and skipped the whole group once it matched. In a group LoggingConfig names, which several functions can share, a forwarder then lost every other function's logs; a destination naming a published version or alias was checked against $LATEST's group; and a function in another account than the ambient one was not found, so its own custom group was fed back to it. The function is now the one the destination ARN names, through getFunctionByArn, with its account, Region and qualifier, and in a named group only the streams carrying its name are skipped, the shape measured on AWS for a named group (2026/10/16/<name>[$LATEST]<id>); every stream of the default group is still the function's own. A destination ARN that does not parse as a function's is not a loop and is no longer caught as any RuntimeException. Tests: another function's stream in a shared group reaches the forwarder while its own is skipped, and a destination naming a published version is checked against that version's group (both fail on the previous head); the stream ownership rule in LambdaLogDestinationsTest.
This commit is contained in:
1 parent
9dcb1b65ae
commit
58097a832a
11 files changed
+271
-21
No files matched your search
@@ -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]<id>` rather than the default group's `2026/10/16/[$LATEST]<id>`.
|
||||
|
||||
`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
|
||||
|
||||
+33
-10
@@ -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/<name>}. 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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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/<name>}. 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]<id>} rather than
|
||||
* {@code 2026/10/16/[$LATEST]<id>}.
|
||||
*/
|
||||
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/<name>}. */
|
||||
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();
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -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();
|
||||
|
||||
+3
-2
@@ -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<String> layerUrls = imagePackage ? List.of() : layerDownloadUrls(fn, region);
|
||||
|
||||
+4
-2
@@ -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,
|
||||
|
||||
+80
-1
@@ -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
|
||||
|
||||
+64
@@ -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]<id>} in {@code /aws/lambda/<name>}; once LoggingConfig names a log
|
||||
* group, the default one's name included, the stream is {@code 2026/10/16/<name>[$LATEST]<id>}.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
+28
@@ -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<String> 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
|
||||
|
||||
+1
-1
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user