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

Refactor http handlers and instrument graceful shutdown #139

Merged

Conversation

chrisdoherty4
Copy link
Member

@chrisdoherty4 chrisdoherty4 commented Oct 31, 2022

This change set seeks to separate HTTP handler configuration from HTTP server configuration and serving. Separating the handlers from the server that serves the endpoints makes the endpoint testing much easier as it doesn't require real HTTP server's, therefore no port juggling.

To create a better separation the following changes were made:

  • Create a handler package with a single API: New. The New function constructs the endpoints that need exposing based on a parameter. This facilitates the Hegel API that was under development.
  • Handler construction is now invoked in the main func.
  • Middleware configuration has been pulled up to the main func.
  • http.Serve is still called from main but no longer launched in a separate goroutine.
  • http.Serve now facilitates proper graceful shutdown.

A suite of tests have been deleted that were targetting internal APIs. When evaluating the tests it became evident that they weren't really testing anything useful as we had to construct the application in a consistent way for the tests to be useful. Additional handler tests will be written and placed in ec2_test.go or wherever that lands.

Similarly, some tests that were valuable, namely the XFF tests, were re-written and moved to the XFF package. The tests are much more thorough in establishing expected XFF middleware behavior.

Next steps

#143 begins the process of further splitting apart handlers and removing the ambiguity created from the 'export' concept in the backend implementations. This may result in a further separation of packages as #143 indicates with its /internal/http/ec2 package.

@chrisdoherty4 chrisdoherty4 force-pushed the feat/refactor-http-handlers branch from e670bf0 to 0041484 Compare October 31, 2022 01:46
@chrisdoherty4 chrisdoherty4 force-pushed the feat/refactor-http-handlers branch 2 times, most recently from fd8aba6 to 682f4d6 Compare November 1, 2022 02:00
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #139 (fd3eeb5) into main (9d420dc) will decrease coverage by 0.48%.
The diff coverage is 42.16%.

@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   20.68%   20.19%   -0.49%     
==========================================
  Files           7       11       +4     
  Lines         672      703      +31     
==========================================
+ Hits          139      142       +3     
- Misses        514      540      +26     
- Partials       19       21       +2     
Impacted Files Coverage Δ
internal/hardware/client.go 0.00% <ø> (ø)
internal/hardware/kubernetes.go 39.51% <0.00%> (-0.65%) ⬇️
internal/hardware/tink.go 0.00% <0.00%> (ø)
internal/http/handler/hegel.go 0.00% <ø> (ø)
internal/http/handler/health_check.go 4.54% <4.54%> (ø)
internal/http/handler/version.go 9.09% <9.09%> (ø)
internal/http/server.go 55.55% <46.15%> (-17.42%) ⬇️
internal/http/handler/handler.go 70.00% <70.00%> (ø)
internal/http/handler/ec2.go 37.71% <100.00%> (ø)
internal/xff/xff.go 92.30% <100.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@chrisdoherty4 chrisdoherty4 force-pushed the feat/refactor-http-handlers branch 2 times, most recently from a9f4d48 to 532763c Compare November 3, 2022 17:08
@chrisdoherty4 chrisdoherty4 force-pushed the feat/refactor-http-handlers branch from 532763c to fd3eeb5 Compare November 3, 2022 17:13
@chrisdoherty4 chrisdoherty4 marked this pull request as ready for review November 3, 2022 17:29
Copy link
Member

@jacobweinstock jacobweinstock left a comment

Choose a reason for hiding this comment

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

i like the clear and understandability of this! thanks!

@jacobweinstock jacobweinstock added the ready-to-merge Signal to Mergify to merge the PR. label Nov 3, 2022
@chrisdoherty4
Copy link
Member Author

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented Nov 3, 2022

queue

✅ The pull request has been merged manually

The pull request has been merged manually at 1aafdbe

@chrisdoherty4 chrisdoherty4 merged commit 1aafdbe into tinkerbell:main Nov 3, 2022
@chrisdoherty4 chrisdoherty4 deleted the feat/refactor-http-handlers branch November 3, 2022 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants