Commit Graph
23 Commits
Author SHA1 Message Date
Fabian Fett ddee38c367 LambdaRuntimeClient works with Invocation (#19)
### Motivation:

- We want to store different entities that are needed when executing a handler within the LambdaContext (Logger, EventLoop, ByteBufferAllocator, …)
- Currently the LambdaRuntimeClient creates the LambdaContext. Having the LambdaContext with the Logger, EventLoop and ByteBufferAllocator be created from the LambdaRuntimeClient feels to me too much for me.
- Conceptionally the Lambda control plane api call is “get next Invocation” (API naming)

### Changes:

- LambdaRuntimeClient responds with an Invocation and does not use the LambdaContext at all anymore.
- LambdaRunner creates the LambdaContext with the Invocation, Logger and EventLoop.
- LambdaContext has been renamed to Lambda.Context
- Lambda.Context is a class now, since it is conceptionally not a value type and might be passed around a lot
- Lambda.Context properties `traceId`, `invokedFunctionArn`, `deadline` are not optional anymore since they will be always set when executing a lambda
- Creating an Invocation can fail with LambdaRuntimeClientError.invocationMissingHeader(String), if non optional headers are not present
- the test MockLambdaServer and the performance test MockServer always return headers for deadline, traceId and function arn (static for now – could be changed with Behaviour flag?!)

### Open ends:

- we will need to build some kind of Deadline into the context (See also #9 - probably for a different PR)
- we have a stupid mapping between ByteBuffer and [UInt8] in the LambdaRunner for now (marked with two TODOs). I don’t want to change this in this PR since it will lead to huge merge conflicts down the road with the potentiall API changes we have in mind.
2020-03-08 15:10:03 -07:00
tomer doron 08f75f51c7 refactor (#13)
motivation: simpler concurrency, better tests

changes:
* ensure http client is called in a single-threaded manner and remove locks 
* refactor test
* make mock server more robust
2020-03-08 12:41:09 -07:00
tomer doron b8a6466577 add docker support (#15)
motivation: enable CI

changes: add docker files support for ubuntu 16.04 and 18.04 and swift 5.0 and 5.1

note that eventyally this will need to move to AL2 docker images, but we dont have official ones yet
2020-03-06 18:43:16 -08:00
Fabian Fett df6638d63b Don’t create an EventLoopFuture chain (#4)
motivation: prevent memory bloat

changes: 
* recurse instead of event loop chain
* fix flaky test
2020-03-06 12:27:52 -08:00
tomer doron 0cb1f134db Replaced String(utf8String: value) with String(cString: value) (#2)
String(utf8String: UnsafePointer) is a Foundation API.
Replaced with Swift STL equivalent.
2020-03-05 13:50:59 -08:00
Tom Doron 209906d390 performance improvments (#17)
motivation: better performance

changes:
* simply url configuration to ip and port so we can reoslve the socket add ress faster
* skip happy eyeballs
* limit eventloop group to 1 thread
* remove use of UUID and URL
* fix backtrace url
2020-03-04 13:54:55 -08:00
Tom Doron c3d4ad5a39 performance tests (#16)
motivation: benchmark for comparison of warm/cold runs

changes:
* refactor configuration
* add mock server that can be used by perf tests
* add simple perf test script
* change redundant classes to structs, make remaining classes final
* make offloading opt-in
* safer locking
* fix format
2020-03-04 11:01:15 -08:00
Tom Doron 4803c61152 remove NIOAny wrapper (#15)
motivation: wrapper was a workarund for swift build issue on amazon linux

changes: remove wrapper, since root cause was fixed
2019-10-08 18:03:50 -07:00
Tom Doron fb6de922de more refactoring (#14)
motivation: improve code quality, handle keep-alive

changes:
* refactor http client to keep warm connection to runtime engine when possible and handle request timeouts
* refactor configuration into the main lambda class to surface it more clearly
* refactor lifecycle code handle shutdown properly and easier to reason about
* add tests
2019-09-26 07:11:12 -07:00
Tom Doron 2201da9944 more refactoring (#13)
motivation: make lambda execution sequence easier to reason about

changes:
* add `peekFailure` extension to `EventLoopFuture` to handle error without side effects
* update process chain to make use of `peekFailure`
2019-09-18 08:46:53 -07:00
Tom Doron c31ee33105 refactor (#12)
motivation: make code simpler to reason about, better use of swift-nio

changes:
* remove main loop on global queue + wait, replace with recursion
* make better use of EvenLoopFuture, instead of result types to signal errors
* inject lifecycleId so we can share offloading queue
* improve logging
* adjust and improve tests
* update sanity and generate linux tests script to work better with dates and swiftformat
2019-09-16 10:05:02 +01:00
George Barnett 5206176688 Add lambda initialization (#11)
Motivation:

When initialization is expensive it's useful for it to be done upfront
instead of for each invocation of the lambda. Similarly, it's helpful
for errors thrown during initialization to be reported to the runtime.

Modifications:

- Add support for initialization in 'LambdaHandler'
- Report init errors to '/init/error'

Result:

Implementers of 'LambdaHandler' can run their own initialization and have
errors reported.
2019-09-10 11:01:18 -04:00
Tom Doron 4b9cd8350c update code to swift5 and nio2 (#10)
* update code to swift5 and nio2

motivation: support newer version of swift and underlying dependencies

changes:
* adjust code to swift 5
* use swift 5 result type and better error handling for json encoding/decoding
* adjust code to nio 2
* add dependency on swift-log for logging instead of print statements
* make logger as part of context
* improve error handling
* add dependecy on swift-backtrace to capture crashes
* improve lifecycle 
* adjust tests
* add default formatting rules and fix formatting
* improve readme
2019-08-05 14:05:48 -07:00
Tom Doron 20309e2ad7 code style (#9)
motivation: nicer code

changes
* rename Result to ResultType since swift is getting formal Result soon
* use Handler instead of T for generics in CodableLambda which is more readable
* simpler bytes->String decoding
2018-12-03 18:25:46 -08:00
Tom Doron e3f3a979ee add docs (#8)
motivation: help users better undersatnd how to use the library

changes:
* add API docs to public APIs
* add narattive docs in README
2018-11-30 15:35:37 -08:00
Tom Doron 61a90e123c hide LambdaLifecycleResult from users (#6)
hide LambdaLifecycleResult from users

motivation: cleaner end-user API

changes:
* make LambdaLifecycleResult internal
* change run, _run method signatures to hide LambdaLifecycleResult from end-user API
* adjust tests
2018-11-30 15:11:53 -08:00
Tom Doron 7084c7c881 add public constructor to LambdaContext (#7)
motivation: default ctor is internal, which means we cant use it in external programs

changes: add public ctor
2018-11-27 11:46:02 -08:00
Tom Doron 6d618f2c33 shutdown handler, lambda api adjustment, latest swift-nio (#5)
* shutdown handler, lambda api adjustment, latest swift-nio

motivation:
* shutdown: while not required, demonstrate better example for shutdown
* latest nio and api adjustments: fixes runtime issues observed when running for realz

changes:
* add signal based shutdown hook that terminates and cleans up resources
* pull latest swift-nio to get fix to thread renaming
* adjust aws lambda api prefix and headers
* reformat linux tests code
2018-11-21 12:57:10 -05:00
Norman Maurer a9c8c1cb5f Refactor code to be more robust and more swift-like. (#4)
- Ensure we fail all promises when the Channel is closed or we receive an error to prevent any promise leaks.
- Replace class by enum to ensure people not init it by mistake
- Use struct where class is not needed.
2018-11-15 13:49:32 -08:00
Tom Doron 39b0140b80 http client event loop cleanup (#3)
motivation: EventLoop is also an EventLoopGroup, no need in wrapping

changes: remove SingleEventLoopGroup wrapper, use EventLoop directly
2018-11-15 13:49:32 -08:00
tomer doron 6c9c1616d0 cleanup and refactoring
motivation: cleaner code base

changes:
* define generic Result type, and make LambdaResult a type alias
* rename RunLambdaResult to LambdaRunResult
* remove redundant test and dead code
2018-11-15 13:49:32 -08:00
Johannes Weiss 9e8135ee2b make more Swift-like 2018-11-14 11:53:49 +00:00
tomer doron 93c9cfdf63 initial commit 2018-11-13 17:48:44 -08:00