mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): refuse a log level under Text as Lambda does (#5920)
Floci accepted ApplicationLogLevel and SystemLogLevel under Text and dropped them, which a test pinned and the docs described as Floci's own call rather than probed behaviour. Measured on Lambda (eu-west-1, 2026-10-18): CreateFunction and UpdateFunctionConfiguration refuse either level under Text, whether LogFormat names Text or is left to that default, with InvalidParameterValueException "LogLevel is not supported when LogFormat is set to "Text". Remove LogLevel from your request or change the LogFormat to "JSON" and try again." In a stack, a valid level under Text passes the template's validation and fails the resource with Lambda's message. Floci now refuses it in validateLoggingConfig, so the API and the CloudFormation update check, which validates through loggingSettings, both do; and its enum errors list the levels in Lambda's order: [FATAL, TRACE, WARN, ERROR, INFO, DEBUG] and [WARN, INFO, DEBUG]. The default format is worked out in one place, logFormat, for the validation and for loggingSettings. Tests: a level under Text refused on create and on update through the API (LambdaVpcSnapStartLoggingIntegrationTest, replacing the test that pinned the old behaviour) and through the SDK (LambdaFunctionConfigTest), by loggingSettings (LambdaServiceTest), and by a stack update (CloudFormationLambdaLoggingConfigIntegrationTest); the enum messages' order. They fail on main.
This commit is contained in:
1 parent
5a4413d63a
commit
d425e2d884
6 files changed
+163
-48
No files matched your search
@@ -2722,13 +2722,28 @@ public class LambdaService implements ResourceProvider {
|
||||
400);
|
||||
}
|
||||
validateEnum(logging.get("LogFormat"), "loggingConfig.logFormat", List.of("JSON", "Text"));
|
||||
// In the order Lambda lists them in the message (measured, eu-west-1, 2026-10-18).
|
||||
validateEnum(logging.get("ApplicationLogLevel"), "loggingConfig.applicationLogLevel",
|
||||
List.of("TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"));
|
||||
List.of("FATAL", "TRACE", "WARN", "ERROR", "INFO", "DEBUG"));
|
||||
validateEnum(logging.get("SystemLogLevel"), "loggingConfig.systemLogLevel",
|
||||
List.of("DEBUG", "INFO", "WARN"));
|
||||
List.of("WARN", "INFO", "DEBUG"));
|
||||
// Measured on Lambda (eu-west-1, 2026-10-18): either level under Text, named or the default
|
||||
// format, is refused on create and update alike, not stored and not ignored.
|
||||
if ("Text".equals(logFormat(logging, durable)) && (nonBlank(logging.get("ApplicationLogLevel")) != null
|
||||
|| nonBlank(logging.get("SystemLogLevel")) != null)) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"LogLevel is not supported when LogFormat is set to \"Text\". Remove LogLevel from your "
|
||||
+ "request or change the LogFormat to \"JSON\" and try again.", 400);
|
||||
}
|
||||
validateLogGroup(logging.get("LogGroup"));
|
||||
}
|
||||
|
||||
/** The LogFormat a LoggingConfig names, else the function's default: JSON if durable, Text otherwise. */
|
||||
private static String logFormat(Map<?, ?> logging, boolean durable) {
|
||||
String named = nonBlank(logging.get("LogFormat"));
|
||||
return named != null ? named : durable ? "JSON" : "Text";
|
||||
}
|
||||
|
||||
static void validateEnum(Object value, String field, List<String> allowed) {
|
||||
if (value == null || allowed.contains(value)) {
|
||||
return;
|
||||
@@ -2914,11 +2929,8 @@ public class LambdaService implements ResourceProvider {
|
||||
* LoggingConfig is replaced wholesale, not merged: AWS resets any member the request omits
|
||||
* back to its default, so an update that names only LogFormat drops a previously set LogGroup.
|
||||
*
|
||||
* <p>ApplicationLogLevel and SystemLogLevel are JSON-format-only: {@link #putLoggingConfig}
|
||||
* never surfaces them for a Text-format function. Storing them anyway would leave state
|
||||
* that is accepted, persisted and then never observable through any read path — the same
|
||||
* accepted-then-forgotten shape this fix removes elsewhere — so they are only kept when the
|
||||
* resolved format is JSON.
|
||||
* <p>ApplicationLogLevel and SystemLogLevel are JSON-format-only: {@link #validateLoggingConfig}
|
||||
* refuses either under Text, as Lambda does, so they are only ever stored for JSON.
|
||||
*/
|
||||
private static void applyLoggingConfig(LambdaFunction fn, Object value) {
|
||||
if (!(value instanceof Map<?, ?> logging)) {
|
||||
@@ -2938,26 +2950,21 @@ public class LambdaService implements ResourceProvider {
|
||||
|
||||
/**
|
||||
* What Lambda stores for a LoggingConfig, once it is valid: an omitted LogFormat is the
|
||||
* function's default, JSON for a durable function and Text otherwise, the two log levels count
|
||||
* only in JSON, and a blank value is an omitted one, an omitted LogGroup meaning
|
||||
* {@code /aws/lambda/<name>}. An invalid value is refused even where it would not be stored,
|
||||
* a log level under Text included, so a comparison of these settings cannot pass it as
|
||||
* unchanged.
|
||||
* function's default, JSON for a durable function and Text otherwise, and a blank value is an
|
||||
* omitted one, an omitted LogGroup meaning {@code /aws/lambda/<name>}. An invalid value is
|
||||
* refused as Lambda refuses it, a log level under Text included, so a comparison of these
|
||||
* settings cannot pass it as unchanged.
|
||||
*/
|
||||
public static LoggingSettings loggingSettings(Map<?, ?> logging, boolean durable) {
|
||||
validateLoggingConfig(logging, durable);
|
||||
String format = logging.get("LogFormat") instanceof String f && !f.isBlank() ? f : durable ? "JSON" : "Text";
|
||||
boolean json = "JSON".equals(format);
|
||||
return new LoggingSettings(format,
|
||||
json ? nonBlank(logging.get("ApplicationLogLevel")) : null,
|
||||
json ? nonBlank(logging.get("SystemLogLevel")) : null,
|
||||
nonBlank(logging.get("LogGroup")));
|
||||
return new LoggingSettings(logFormat(logging, durable), nonBlank(logging.get("ApplicationLogLevel")),
|
||||
nonBlank(logging.get("SystemLogLevel")), nonBlank(logging.get("LogGroup")));
|
||||
}
|
||||
|
||||
/** The function's stored logging settings, its default LogFormat when it has none stored. */
|
||||
public static LoggingSettings loggingSettings(LambdaFunction fn) {
|
||||
return new LoggingSettings(
|
||||
fn.getLogFormat() != null ? fn.getLogFormat() : loggingSettings(Map.of(), fn.isDurable()).logFormat(),
|
||||
fn.getLogFormat() != null ? fn.getLogFormat() : logFormat(Map.of(), fn.isDurable()),
|
||||
fn.getApplicationLogLevel(), fn.getSystemLogLevel(), fn.getLogGroup());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user