mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): pass LoggingConfig log format and level to the runtime (#6775)
* fix(lambda): pass LoggingConfig log format and level to the runtime A function with LogFormat=JSON logged text: neither launcher set AWS_LAMBDA_LOG_FORMAT or AWS_LAMBDA_LOG_LEVEL, which the runtime interface clients read. Both launchers now pass them, and a JSON function without an ApplicationLogLevel gets INFO, the level the API reports, through one default shared with the response. Closes #6774 * docs(lambda): note the log format and level the runtime receives * refactor(lambda): build the runtime environment in one place for both launchers ContainerLauncher and KubernetesPodLauncher wrote the same AWS_LAMBDA_* lines, the LoggingConfig ones included. LambdaRuntimeEnv.of now builds them once.
This commit is contained in:
1 parent
119b7e9580
commit
481b7f8d6d
8 files changed
+98
-23
No files matched your search
@@ -888,8 +888,7 @@ public class LambdaController {
|
||||
ObjectNode logging = node.putObject("LoggingConfig");
|
||||
logging.put("LogFormat", logFormat);
|
||||
if ("JSON".equals(logFormat)) {
|
||||
logging.put("ApplicationLogLevel",
|
||||
fn.getApplicationLogLevel() != null ? fn.getApplicationLogLevel() : "INFO");
|
||||
logging.put("ApplicationLogLevel", fn.applicationLogLevelOrDefault());
|
||||
logging.put("SystemLogLevel",
|
||||
fn.getSystemLogLevel() != null ? fn.getSystemLogLevel() : "INFO");
|
||||
}
|
||||
|
||||
+1
-11
@@ -246,17 +246,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
String lambdaRegion = extractRegionFromArn(fn.getFunctionArn(), config.defaultRegion());
|
||||
String lambdaAccountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId());
|
||||
|
||||
// Build env vars
|
||||
List<String> env = new ArrayList<>();
|
||||
env.add("AWS_LAMBDA_RUNTIME_API=" + runtimeApiEndpoint);
|
||||
env.add("AWS_LAMBDA_FUNCTION_NAME=" + fn.getFunctionName());
|
||||
env.add("AWS_LAMBDA_FUNCTION_MEMORY_SIZE=" + fn.getMemorySize());
|
||||
env.add("AWS_LAMBDA_FUNCTION_TIMEOUT=" + fn.getTimeout());
|
||||
env.add("AWS_LAMBDA_LOG_GROUP_NAME=" + cwLogGroup);
|
||||
env.add("AWS_LAMBDA_LOG_STREAM_NAME=" + cwLogStream);
|
||||
if (fn.getHandler() != null && !fn.getHandler().isBlank()) {
|
||||
env.add("_HANDLER=" + fn.getHandler());
|
||||
}
|
||||
List<String> env = LambdaRuntimeEnv.of(fn, runtimeApiEndpoint, cwLogGroup, cwLogStream);
|
||||
// Region, credentials and the Floci endpoint the SDK should target: the same baseline
|
||||
// Floci gives every launched container. When the host ~/.aws is mounted (awsConfigPath),
|
||||
// the SDK discovers credentials from /opt/aws-config instead of injected credentials.
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package io.github.hectorvent.floci.services.lambda.launcher;
|
||||
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** The Lambda runtime environment every launcher gives an execution environment, before the SDK baseline. */
|
||||
public final class LambdaRuntimeEnv {
|
||||
|
||||
private LambdaRuntimeEnv() {
|
||||
}
|
||||
|
||||
/** Returns a mutable list, so a launcher can add or override variables after it. */
|
||||
public static List<String> of(LambdaFunction fn, String runtimeApi, String logGroup, String logStream) {
|
||||
List<String> env = new ArrayList<>();
|
||||
env.add("AWS_LAMBDA_RUNTIME_API=" + runtimeApi);
|
||||
env.add("AWS_LAMBDA_FUNCTION_NAME=" + fn.getFunctionName());
|
||||
env.add("AWS_LAMBDA_FUNCTION_MEMORY_SIZE=" + fn.getMemorySize());
|
||||
env.add("AWS_LAMBDA_FUNCTION_TIMEOUT=" + fn.getTimeout());
|
||||
env.add("AWS_LAMBDA_LOG_GROUP_NAME=" + logGroup);
|
||||
env.add("AWS_LAMBDA_LOG_STREAM_NAME=" + logStream);
|
||||
// LoggingConfig: the runtime interface clients read these to pick the log format and the
|
||||
// application log level, so without them a JSON function still logs text.
|
||||
if (fn.getLogFormat() != null) {
|
||||
env.add("AWS_LAMBDA_LOG_FORMAT=" + fn.getLogFormat());
|
||||
}
|
||||
if (fn.applicationLogLevelOrDefault() != null) {
|
||||
env.add("AWS_LAMBDA_LOG_LEVEL=" + fn.applicationLogLevelOrDefault());
|
||||
}
|
||||
if (fn.getHandler() != null && !fn.getHandler().isBlank()) {
|
||||
env.add("_HANDLER=" + fn.getHandler());
|
||||
}
|
||||
return env;
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -14,6 +14,7 @@ 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;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageResolver;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.LambdaRuntimeEnv;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.LambdaRuntimeLauncher;
|
||||
import io.github.hectorvent.floci.services.lambda.model.ContainerState;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
|
||||
@@ -184,16 +185,8 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher {
|
||||
|
||||
Optional<String> caConfigMap = ContainerCaBundle.hostPath(config).map(bundle -> ensureCaConfigMap(namespace, bundle));
|
||||
|
||||
ArrayList<String> env = new ArrayList<>();
|
||||
env.add("AWS_LAMBDA_RUNTIME_API=" + addressResolver.resolve() + ":" + runtimeApiServer.getPort());
|
||||
env.add("AWS_LAMBDA_FUNCTION_NAME=" + fn.getFunctionName());
|
||||
env.add("AWS_LAMBDA_FUNCTION_MEMORY_SIZE=" + fn.getMemorySize());
|
||||
env.add("AWS_LAMBDA_FUNCTION_TIMEOUT=" + fn.getTimeout());
|
||||
env.add("AWS_LAMBDA_LOG_GROUP_NAME=" + cwLogGroup);
|
||||
env.add("AWS_LAMBDA_LOG_STREAM_NAME=" + cwLogStream);
|
||||
if (fn.getHandler() != null && !fn.getHandler().isBlank()) {
|
||||
env.add("_HANDLER=" + fn.getHandler());
|
||||
}
|
||||
List<String> env = LambdaRuntimeEnv.of(fn,
|
||||
addressResolver.resolve() + ":" + runtimeApiServer.getPort(), cwLogGroup, cwLogStream);
|
||||
env.addAll(awsEnv.sdkBaselineEnv(region, Optional.empty(), addressResolver.flociBaseUrl(),
|
||||
Optional.empty(), AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId())));
|
||||
if (fn.getEnvironment() != null) {
|
||||
|
||||
@@ -205,6 +205,17 @@ public class LambdaFunction {
|
||||
public String getApplicationLogLevel() { return applicationLogLevel; }
|
||||
public void setApplicationLogLevel(String applicationLogLevel) { this.applicationLogLevel = applicationLogLevel; }
|
||||
|
||||
/**
|
||||
* The level a JSON-format function logs at: its own, else INFO, as Lambda reports it. None under
|
||||
* Text, where log levels are refused.
|
||||
*/
|
||||
public String applicationLogLevelOrDefault() {
|
||||
if (applicationLogLevel != null) {
|
||||
return applicationLogLevel;
|
||||
}
|
||||
return "JSON".equals(logFormat) ? "INFO" : null;
|
||||
}
|
||||
|
||||
public String getSystemLogLevel() { return systemLogLevel; }
|
||||
public void setSystemLogLevel(String systemLogLevel) { this.systemLogLevel = systemLogLevel; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user