Skip to content

Conversation

ItalyPaleAle
Copy link
Contributor

@ItalyPaleAle ItalyPaleAle commented Apr 16, 2023

This PR changes the HTTP server's listeners from fasthttp to net/http and fixes (or enables fixing) a lot of the scenarios that are blocked by #4979. Immediately, this should enable the web server to use HTTP/2 when TLS is enabled.

Included and not included

What this PR includes:

  • Changes the listeners for the 3 HTTP servers (app, healthz, pprof) from using fasthttp to using the standard library (net/http)
  • Changes all built-in middlewares used by the servers above to be based on net/http

What this PR does NOT include:

  • No handler has been updated from fasthttp to net/http, and handlers continue to work thanks to the "adapters"
    • This is not something new as in Dapr 1.10, all requests go through adapters twice to be converted fasthttp(listener + built-in middlewares)->net/http (middleware components)->fasthttp (handlers). Now there's only one conversion: net/http(everything but handlers)->fasthttp(handlers)
  • Does not change the router, which is still the fasthttp one. This is blocking updating handlers from fasthttp to net/http, and needs to be done in a separate PR.
  • Does not enable H2C. Should be done in a separate PR.
  • Some unit tests, including many (not all) in pkg/http still use fasthttp to create the test server. This isn't a concern at least until the handlers are migrated, but it should be changed in the future.

All features continue to work as expected, as testified by the fact that tests have not changed. Only one exception to this rule is that when performing HTTP->gRPC invocations, the "dapr-host" metadata is not included anymore (this is probably ok also because HTTP->gRPC service invocation is being deprecated)

Next steps

  • Update the router to one based on net/http, and apply the adapters only on individual handlers rather than on the router itself.
  • Migrate the Universal API adapter from fasthttp to net/http
  • Migrate APIs that can use streaming (such as service invocation) to be based on net/http and leverage streaming for input and output
  • Migrate all other APIs from fasthttp to either net/http handlers or Universal APIs.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
See dapr#6246

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@ItalyPaleAle ItalyPaleAle requested review from a team as code owners April 16, 2023 21:58

statusCode := int(resp.Status().Code)

// TODO @ItalyPaleAle: Make this the only path once streaming is finalized
if a.isStreamingEnabled {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reviewers: this was removed for now since it's not effective (see #6246 )

}

func (s *server) useCors(next fasthttp.RequestHandler) fasthttp.RequestHandler {
func (s *server) useCors(next http.Handler) http.Handler {
// TODO: Technically, if "AllowedOrigins" is "*", all origins should be allowed
Copy link
Contributor Author

@ItalyPaleAle ItalyPaleAle Apr 16, 2023

Choose a reason for hiding this comment

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

Reviewers: Dapr is likely behaving incorrectly here. Setting * in CORS should mean "allow all origins", but Dapr <=1.10 was actually omitting the CORS headers entirely. Since this is a backwards-incompatible change, I am not touching it now.

@codecov
Copy link

codecov bot commented Apr 16, 2023

Codecov Report

Merging #6248 (0cd9e3c) into master (054df8c) will increase coverage by 0.04%.
The diff coverage is 76.43%.

@@            Coverage Diff             @@
##           master    #6248      +/-   ##
==========================================
+ Coverage   65.80%   65.84%   +0.04%     
==========================================
  Files         194      195       +1     
  Lines       18995    19021      +26     
==========================================
+ Hits        12499    12524      +25     
+ Misses       5487     5480       -7     
- Partials     1009     1017       +8     
Impacted Files Coverage Δ
pkg/http/responses.go 88.23% <ø> (+33.68%) ⬆️
pkg/messaging/direct_messaging.go 52.39% <0.00%> (ø)
pkg/messaging/v1/invoke_method_request.go 83.83% <0.00%> (-1.73%) ⬇️
utils/nethttpadaptor/nethttpadaptor.go 72.34% <33.33%> (-2.66%) ⬇️
pkg/diagnostics/utils/trace_utils.go 8.77% <45.45%> (-3.96%) ⬇️
pkg/grpc/api_daprinternal.go 38.96% <50.00%> (+0.14%) ⬆️
pkg/http/server.go 61.67% <59.25%> (-2.30%) ⬇️
utils/responsewriter/response_writer.go 71.11% <71.11%> (ø)
pkg/messaging/v1/util.go 51.09% <71.42%> (-1.09%) ⬇️
utils/streams/limitreadcloser.go 84.61% <77.77%> (+84.61%) ⬆️
... and 7 more

... and 2 files with indirect coverage changes

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@daixiang0
Copy link
Member

/ok-to-test

@dapr-bot

This comment was marked as outdated.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@ItalyPaleAle
Copy link
Contributor Author

/ok-to-perf

@dapr-bot
Copy link
Collaborator

dapr-bot commented Apr 17, 2023

Dapr perf test

🔗 Link to Action run

Commit ref: 947ec61

✅ Build succeeded

  • Image tag: daprprfac9c242881
  • Test image tag: daprprfac9c242881

✅ Infrastructure deployed

  • Resource group name: Dapr-Perf-daprprfac9c242881
  • Azure region: westus3

✅ Perf tests succeeded

  • Image tag: daprprfac9c242881
  • Test image tag: daprprfac9c242881

@yaron2
Copy link
Member

yaron2 commented Apr 17, 2023

/ok-to-perf

Long have we waited for this change... Very curious about the perf results

@ItalyPaleAle
Copy link
Contributor Author

ItalyPaleAle commented Apr 17, 2023

@yaron2 all perf tests are passing, and looks like perf may actually be improving

Looking at the service invocation perf test (which is particularly useful here as it is among those more sensitive to the web server's own perf):

This PR: 1 2

  • P50: 1.38ms / 1.42ms
  • P90: 1.98ms / 2.13ms

Three recent perf tests from master (1 2 3)

  • Added latency avg: 1.76ms / 1.50ms / 1.47ms
  • P90: 2.86ms / 2.13ms /2.09ms

@yaron2
Copy link
Member

yaron2 commented May 30, 2023

/ok-to-perf

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 30, 2023

Dapr perf test

🔗 Link to Action run

Commit ref: e6e4cbd

✅ Build succeeded

  • Image tag: daprprf3811325376
  • Test image tag: daprprf3811325376

✅ Infrastructure deployed

  • Resource group name: Dapr-Perf-daprprf3811325376
  • Azure region: westus3

✅ Perf tests succeeded

  • Image tag: daprprf3811325376
  • Test image tag: daprprf3811325376

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 30, 2023

Dapr perf test

🔗 Link to Action run

Commit ref: e6e4cbd

✅ Build succeeded

  • Image tag: daprprfb757de21a9
  • Test image tag: daprprfb757de21a9

✅ Infrastructure deployed

  • Resource group name: Dapr-Perf-daprprfb757de21a9
  • Azure region: westus3

✅ Perf tests succeeded

  • Image tag: daprprfb757de21a9
  • Test image tag: daprprfb757de21a9

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 30, 2023

Dapr perf test

🔗 Link to Action run

Commit ref: e6e4cbd

✅ Build succeeded

  • Image tag: daprprf9520bd677c
  • Test image tag: daprprf9520bd677c

✅ Infrastructure deployed

  • Resource group name: Dapr-Perf-daprprf9520bd677c
  • Azure region: westus3

✅ Perf tests succeeded

  • Image tag: daprprf9520bd677c
  • Test image tag: daprprf9520bd677c

@artursouza
Copy link
Contributor

/test-sdk-all

@dapr-bot

This comment has been minimized.

@dapr-bot

This comment was marked as outdated.

@dapr-bot

This comment was marked as outdated.

@dapr-bot

This comment was marked as outdated.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@ItalyPaleAle
Copy link
Contributor Author

/test-sdk-all

@dapr-bot

This comment was marked as outdated.

@dapr-bot

This comment was marked as resolved.

@dapr-bot

This comment was marked as outdated.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@ItalyPaleAle
Copy link
Contributor Author

/ok-to-test

@ItalyPaleAle
Copy link
Contributor Author

/test-sdk-all

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 31, 2023

Dapr SDK Python test

🔗 Link to Action run

Commit ref: d150ce1

✅ Python SDK tests passed

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 31, 2023

Dapr SDK Java test

🔗 Link to Action run

Commit ref: d150ce1

✅ Java SDK tests passed

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 31, 2023

Dapr E2E test

🔗 Link to Action run

Commit ref: d150ce1

✅ Build succeeded for linux/arm64

  • Image tag: dapre2ed7d8620e8bla
  • Test image tag: dapre2ed7d8620e8bla

✅ Infrastructure deployed

Cluster Resource group name Azure region
Linux Dapr-E2E-dapre2ed7d8620e8bl westus3
Windows Dapr-E2E-dapre2ed7d8620e8bw westus3
Linux/arm64 Dapr-E2E-dapre2ed7d8620e8bla eastus

✅ Build succeeded for linux/amd64

  • Image tag: dapre2ed7d8620e8bl
  • Test image tag: dapre2ed7d8620e8bl

✅ Build succeeded for windows/amd64

  • Image tag: dapre2ed7d8620e8bw
  • Test image tag: dapre2ed7d8620e8bw

⚠️ Tests skipped on linux/arm64

  • Image tag: dapre2ed7d8620e8bla
  • Test image tag: dapre2ed7d8620e8bla

✅ Tests succeeded on linux/amd64

  • Image tag: dapre2ed7d8620e8bl
  • Test image tag: dapre2ed7d8620e8bl

✅ Tests succeeded on windows/amd64

  • Image tag: dapre2ed7d8620e8bw
  • Test image tag: dapre2ed7d8620e8bw

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 31, 2023

Dapr SDK JS test

🔗 Link to Action run

Commit ref: d150ce1

✅ JS SDK tests passed

@ItalyPaleAle
Copy link
Contributor Author

@artursouza

Fixed all the issues reported by the SDK tests:

  • Java: issue was with the shutdown sequence. Stopping a net/http server returns an error always, which normally is ErrServerClosed, and had to be ignored.
  • Python: issue was related to trace headers not being converted between net/http and fasthttp. The routes are still implemented as fasthttp, but the middleware that sets the tracing span now uses net/http. I added a temporary compatibility layer to make it work (until the routes are converted to net/http)

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@yaron2 yaron2 merged commit 5aba3c9 into dapr:master May 31, 2023
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.

Migrate HTTP server from fasthttp to net/http
5 participants