Skip to content
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

Transition HBResponder to be async/await, removing HBAsyncResponder in the process #256

Merged
merged 8 commits into from
Oct 31, 2023

Conversation

Joannis
Copy link
Member

@Joannis Joannis commented Oct 29, 2023

This PR provides a compatibility helper for APIs still working with ELFs, primarily the Middleware

@Joannis Joannis requested a review from adam-fowler October 29, 2023 18:01
@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Files Coverage Δ
...ces/Hummingbird/Middleware/MetricsMiddleware.swift 100.00% <100.00%> (ø)
Sources/Hummingbird/Middleware/Middleware.swift 100.00% <100.00%> (ø)
Sources/Hummingbird/Router/RouteHandler.swift 62.50% <100.00%> (+8.65%) ⬆️
Sources/Hummingbird/Router/Router.swift 100.00% <100.00%> (ø)
Sources/Hummingbird/Router/RouterBuilder.swift 100.00% <100.00%> (ø)
Sources/Hummingbird/Router/RouterGroup.swift 100.00% <ø> (ø)
Sources/Hummingbird/Router/RouterMethods.swift 100.00% <100.00%> (+16.34%) ⬆️
...Hummingbird/Server/Application+HTTPResponder.swift 100.00% <100.00%> (ø)
Sources/Hummingbird/Server/RequestContext.swift 68.33% <100.00%> (-15.00%) ⬇️
Sources/Hummingbird/Server/Responder.swift 100.00% <100.00%> (ø)
... and 5 more

... and 3 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

return endpointPath
}()

return context.withSpan(operationName, serviceContext: serviceContext, ofKind: .server) { context, span in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't use context.withSpan here. You need to use ServiceContext.withSpan. The whole of ServiceContext.swift needs to be deleted. It is there to preserve the service context between async and non-async contexts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this applicable only after we land the HBMiddleware PR?

Sources/Hummingbird/Router/RouterBuilder.swift Outdated Show resolved Hide resolved
Sources/Hummingbird/Router/RouterMethods.swift Outdated Show resolved Hide resolved
var serviceContext = context.serviceContext
serviceContext.testID = "testMiddleware"

return try await context.withSpan("TestSpan", serviceContext: serviceContext, ofKind: .server) { context, _ in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use InstrumentationSystem.tracer.withSpan

@@ -323,7 +323,7 @@ final class TracingTests: XCTestCase {
app.router.get("/") { _, context -> HTTPResponseStatus in
var serviceContext = context.serviceContext
serviceContext.testID = "test"
return context.withSpan("TestSpan", serviceContext: serviceContext, ofKind: .client) { _, span in
return try await context.withSpan("TestSpan", serviceContext: serviceContext, ofKind: .client) { _, span in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use InstrumentationSystem.tracer.withSpan

Tests/HummingbirdTests/TracingTests.swift Outdated Show resolved Hide resolved
@@ -449,7 +452,7 @@ extension TracingTests {
app.middleware.add(AsyncSpanMiddleware())
app.router.get("/") { _, context -> HTTPResponseStatus in
try await Task.sleep(nanoseconds: 1000)
return context.withSpan("testing", ofKind: .server) { _, _ in
return try await context.withSpan("testing", ofKind: .server) { _, _ in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use InstrumentationSystem.tracer.withSpan

@@ -49,7 +49,7 @@ struct User: Decodable {
app.router.post("user") { request -> EventLoopFuture<HTTPResponseStatus> in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice documentation update. Not many people consider that

Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good start

// respond to request
self.responder.respond(to: request, context: context).whenComplete { result in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this for another PR

@Joannis Joannis force-pushed the jo/hb-responder-async branch from 79e8382 to 0994b39 Compare October 31, 2023 11:18
Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor issue

Tests/HummingbirdTests/TracingTests.swift Show resolved Hide resolved
@Joannis Joannis merged commit 7d25b52 into 2.x.x Oct 31, 2023
6 of 7 checks passed
@Joannis Joannis deleted the jo/hb-responder-async branch October 31, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants