-
Notifications
You must be signed in to change notification settings - Fork 118
Added header when reporting failing invocations or initializations #116 #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If we want to use The NIOHTTP1TestServer for testing connections we need to use its ip and port. The default (currently unchangeable) port of the RuntimeEngine is 7000, the one of of NIOHTTP1TestServer is 0
- use runtimClient instead of runner - remove extensions for requests and test directly in the method
|
Can one of the admins verify this patch? |
3 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
@swift-server-bot test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ro-M Thanks for this great pr. Have you tested this by any chance on Lambda itself?
I think we need to clarify the HTTPClients API first. Should the HTTPClient have static headers it merges with injected once or should the Lambda.RuntimeClient inject all headers on every call.
I think I would vote for the later but let's wait what @tomerd thinks.
| func post(url: String, body: ByteBuffer?, timeout: TimeAmount? = nil, additionalHeaders: HTTPHeaders? = nil) -> EventLoopFuture<Response> { | ||
| var headers = HTTPClient.headers | ||
| additionalHeaders.flatMap { headers.add(contentsOf: $0) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomerd I would vote to inject all headers on every call and to not have them split over two files. wdyt? In hindsight having static headers directly on the HTTPClient doesn't make much sense IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @fabianfett do you mean have RuntimeClient fully control the headers instead of injecting "additional" ones? if so, that sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be ok to include that change in this PR or should I make a separate one for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we fix it in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I moved the static header declaration into an extension on RuntimeClient. The get and post methods on HTTPClient now have a non-optional headers parameter (without a default value). I also moved the headers parameter to come after the urlparameter ... that ordering made a more cohesive impression to me ^^
| XCTAssertNoThrow(try result.wait()) | ||
| } | ||
|
|
||
| func testSuccessHeaders() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would rename this to testInvocationResponse because it isn't as generic as SuccessHeaders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I think Headers is generally wrong at this point because the method is also testing a lot of other things as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is testInvocationSuccessResponseok with you as well? To disambiguate between success and error tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ro-M yes testInvocationSuccessResponse is perfect
|
@swift-server-bot test this please |
happy to explore other names but keep in mind that Lambda will always bind to a localhost IP address, and AWS provides that as an env variables that combines the two as parsed by the code |
@tomerd I didn't think about that, thanks! I would prefer the latter approach: providing the option to set them through an initializer but falling back to the environment and also default the |
using only env variables makes testing hard, so I also prefer the approach of being able to set it via the config and falling back to the env variable name wise, maybe "address"? |
|
@swift-server-bot test this please |
| import NIOHTTP1 | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty lines
| private let allocator = ByteBufferAllocator() | ||
| private let httpClient: HTTPClient | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run ./scripts/sanity
|
@swift-server-bot test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Ro-M for contributing. This looks really good now!
|
thanks @Ro-M |
Motivation
This fixes #116
We need to send a special header when we are reporting a failing invocation or when the runtime encounters an error during initialization.
Changes
lambda-runtime-function-error-typeheader is added by theRuntimeClient. As of my understanding this should not be done by theHTTPClientpostmethod ofHTTPClient. Those headers will be added to the default headers of theHTTPClientNIOHTTP1TestServerinstead of theMockLambdaServer.RuntimeEngine'sbaseURLparameter as the primary source to set theipandportproperty, falling back to searching in the environment if it wasn't provided.baseURLdid exist as a parameter before but was unused. I needed a settablebaseURLfor theNIOHTTP1TestServerDiscussion
additionalHeadersparameter to thepostmethod of theHTTPClient, should this parameter also be available in thegetmethod? (It's not needed needed for this PR)NIOHTTP1TestServeris ok but evaluating the inbound reads and outbound writes is too much boilerplate code: Should this evaluation be refactored into helper methods? (similar helper methods are internally used in theswift-niopackage)baseURLparameter ofRuntimeEngine's initializer: Directly mapping a url to theipandportproperty does not sound right: I would not expect anipproperty to contain a url. Maybe renameiptohost?