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

Remove pkg level state #95

Merged
merged 3 commits into from
May 5, 2022

Conversation

chrisdoherty4
Copy link
Member

@chrisdoherty4 chrisdoherty4 commented May 2, 2022

The branch got messed up during a rebase and Github automatically closed the previous PR (#87). All comments from the previous PR have been addressed.

The primary purpose of this PR is to strip package level state from the service. Global state contributes to application complexity that is considered the cause for many bugs. Package state is 1 notch behind global state.

Package state has been replaced with explicit dependency declarations in functions and, consequently, injected dependencies. This lays a foundation for further refactoring to bring about cleaner code that's easier to work with.

With the state removal some additional fixes and restructuring was done; specifics:

  • all http handlers are now high-order functions returning an http.Handler that leverages the injected dependencies.
  • metrics gathered by polling the health function of clients has been isolated in the metrics package and is launched as a distinct goroutine.
  • a series of bugs in the http health check handler have been fixed. Namely continuing on to write payloads after http.StatusInternalServerError codes are written.
  • removal of redundant Content-Type headers as the setter was called after WriteHeader() meaning it has no effect.
  • changed the version end-point to return a known JSON structure in contrast to the previous implementation that, presumably, relied on build time information being injected; the structure used is modeled after the health check endpoint and uses git_rev as the JSON key.
  • changed http-server package to http and grpc-server package to grpc; these changes have been isolated on their own commit for ease of reviewing.

Metric package state is untouched given it'll likely require a more thought out refactor than simply removing the state and injecting a dependency.

Similarly, I've purposely avoided writing additional tests as I'd like to do a hoslitic rework of unit and e2e testing.

The only behavioral change is that the /_packet/version endpoint payload is now structured and may be different to existing expectations.

@codecov
Copy link

codecov bot commented May 2, 2022

Codecov Report

Merging #95 (59f53c2) into main (a509fa4) will increase coverage by 2.67%.
The diff coverage is 49.28%.

❗ Current head 59f53c2 differs from pull request most recent head 4f6bc9e. Consider uploading reports for the commit 4f6bc9e to get more accurate results

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
+ Coverage   51.87%   54.54%   +2.67%     
==========================================
  Files           3        3              
  Lines         401      374      -27     
==========================================
- Hits          208      204       -4     
+ Misses        164      140      -24     
- Partials       29       30       +1     
Impacted Files Coverage Δ
grpc/server.go 56.96% <20.00%> (ø)
http/handlers.go 45.55% <37.23%> (ø)
http/server.go 88.88% <88.88%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a509fa4...4f6bc9e. Read the comment docs.

@chrisdoherty4 chrisdoherty4 force-pushed the cpd/remove-package-state branch 2 times, most recently from 219f89a to 769ef57 Compare May 2, 2022 17:22
jacobweinstock
jacobweinstock previously approved these changes May 2, 2022
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.

lgtm

micahhausler
micahhausler previously approved these changes May 2, 2022
Copy link
Contributor

@micahhausler micahhausler left a comment

Choose a reason for hiding this comment

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

LGTM. Just one minor change on test log initialization

http/server_test.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 dismissed stale reviews from micahhausler and jacobweinstock via 59f53c2 May 2, 2022 17:51
@chrisdoherty4 chrisdoherty4 force-pushed the cpd/remove-package-state branch from 59f53c2 to 8902d05 Compare May 2, 2022 17:52
@displague
Copy link
Member

The only behavioral change is that the /_packet/version endpoint payload is now structured and may be different to existing expectations.

@mmlb is this potentially a problem?
I wonder if a new endpoint would be preferable for this change.

@chrisdoherty4
Copy link
Member Author

The only behavioral change is that the /_packet/version endpoint payload is now structured and may be different to existing expectations.

@mmlb is this potentially a problem?
I wonder if a new endpoint would be preferable for this change.

As part of 0.7 id like to see these deprecated anyway, removed in 0.8. The endpoint retrieved its data from a variable that didn't have any definition other than indicating it was JSON. The variable was unset suggesting it was set during build time so I felt comfortable removing that instead returning a defined payload.

The fact this is v0 and that this data had no structure to it, it felt appropriate to strip it out.

@chrisdoherty4 chrisdoherty4 force-pushed the cpd/remove-package-state branch from 8902d05 to 4f6bc9e Compare May 5, 2022 20:12
@jacobweinstock jacobweinstock added the ready-to-merge Signal to Mergify to merge the PR. label May 5, 2022
@mergify mergify bot merged commit 50983c3 into tinkerbell:main May 5, 2022
mergify bot added a commit that referenced this pull request May 9, 2022
## Description

Builds on #95 (rebased after PR was created)

This feature builds on #81 and realizes the Hegel portion of the [Kubernetes back-end proposal](https://github.com/tinkerbell/proposals/tree/main/proposals/0026).

Having generalized the client used to acquire metadata, this PR implements a Kubernetes client that leverages an internal client caching mechanism so as to reduce load on the Kubernetes API Server.

Additionally, I put some effort into reworking the Hegel Dockerfile so it could leverage layer caching for Go module dependencies and added an image build command to the Makefile.

The `Watch` API for the client is unimplemented and scheduled for a follow up. This is so we can get off the ground for machine provisioning. The `Watch` API is used for subscription capabilities so doesn't feature in metadata retrieval. 

## How Has This Been Tested?

Built and ran the image with the Kubernetes back-end enabled talking to a KinD cluster containing the necessary CRDs and a `Hardware` resource. 

## How are existing users impacted? What migration steps/scripts do we need?

None. Users enable the Kubernetes back-end by setting the `DATA_MODEL_VERSION=kubernetes` plus some additional env vars.

## Future work

- Implement the `Watch` API for consistency with other back-ends.
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.

4 participants