From a12674ef2204bd249d29ba9159bbaeb86e1d2a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Sat, 26 Oct 2024 14:12:46 +0200 Subject: [PATCH 1/4] set the log level to LOG_LEVEL env variable --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 908e2ab2..c3b9082c 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -23,7 +23,7 @@ import NIOCore public final class LambdaRuntime: @unchecked Sendable where Handler: StreamingLambdaHandler { // TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore let handlerMutex: NIOLockedValueBox - let logger: Logger + var logger: Logger let eventLoop: EventLoop public init( @@ -55,6 +55,11 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St throw LambdaRuntimeError(code: .runtimeCanOnlyBeStartedOnce) } + // by setting the log level here, we understand it can not be changed dynamically at runtime + // developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change + // this approach is less flexible but more performant than reading the value of the environment variable at each invocation + self.logger.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info + try await LambdaRuntimeClient.withRuntimeClient( configuration: .init(ip: ip, port: port), eventLoop: self.eventLoop, From 7114adbbac3fad53a88a02298b27432144631616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 30 Oct 2024 21:49:11 +0100 Subject: [PATCH 2/4] remove need for `var logger` --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index c3b9082c..67a07622 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -23,7 +23,7 @@ import NIOCore public final class LambdaRuntime: @unchecked Sendable where Handler: StreamingLambdaHandler { // TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore let handlerMutex: NIOLockedValueBox - var logger: Logger + let logger: Logger let eventLoop: EventLoop public init( @@ -33,6 +33,12 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St ) { self.handlerMutex = NIOLockedValueBox(handler) self.eventLoop = eventLoop + + // by setting the log level here, we understand it can not be changed dynamically at runtime + // developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change + // this approach is less flexible but more performant than reading the value of the environment variable at each invocation + var log = logger + log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info self.logger = logger } @@ -55,11 +61,6 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St throw LambdaRuntimeError(code: .runtimeCanOnlyBeStartedOnce) } - // by setting the log level here, we understand it can not be changed dynamically at runtime - // developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change - // this approach is less flexible but more performant than reading the value of the environment variable at each invocation - self.logger.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info - try await LambdaRuntimeClient.withRuntimeClient( configuration: .init(ip: ip, port: port), eventLoop: self.eventLoop, From c8a799e5e16c5f58849e0bfbea691e03916f2b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 30 Oct 2024 22:15:51 +0100 Subject: [PATCH 3/4] swift-format --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 67a07622..726c39a4 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -38,7 +38,7 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St // developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change // this approach is less flexible but more performant than reading the value of the environment variable at each invocation var log = logger - log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info + log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info self.logger = logger } From 6d5e83bb01370335f38cc7f7ffbaa9f909f4eafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 30 Oct 2024 22:24:07 +0100 Subject: [PATCH 4/4] [ci] update static sdk to 6.0.2 --- .github/workflows/pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 5e9a8fc5..09b17cdf 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -47,12 +47,12 @@ jobs: # https://github.com/swiftlang/github-workflows/issues/34 musl: runs-on: ubuntu-latest - container: swift:6.0-noble + container: swift:6.0.2-noble timeout-minutes: 30 steps: - name: Check out code uses: actions/checkout@v4 - name: Install SDK - run: swift sdk install https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481 + run: swift sdk install https://download.swift.org/swift-6.0.2-release/static-sdk/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum aa5515476a403797223fc2aad4ca0c3bf83995d5427fb297cab1d93c68cee075 - name: Build run: swift build --swift-sdk x86_64-swift-linux-musl