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

Add readiness endpoint #43

Merged
merged 7 commits into from
Jan 9, 2024
Merged

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Dec 20, 2023

Resolves #5

cmd/lingo/main.go Outdated Show resolved Hide resolved
readinessProbe:
httpGet:
path: /readyz
port: 8081
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The healthz endpoint was setup already in main. This adds port/path to make use of it. Not sure about the time values here

deploy/lingo_deploy.yaml Show resolved Hide resolved
pkg/deployments/manager.go Show resolved Hide resolved
pkg/deployments/manager.go Show resolved Hide resolved
pkg/deployments/readiness.go Outdated Show resolved Hide resolved
pkg/deployments/readiness.go Outdated Show resolved Hide resolved
pkg/deployments/readiness.go Outdated Show resolved Hide resolved
pkg/deployments/readiness.go Outdated Show resolved Hide resolved
@nstogner
Copy link
Contributor

Much needed! Will give this a thorough review soon.

Copy link
Contributor

@nstogner nstogner left a comment

Choose a reason for hiding this comment

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

This is a very important feature to have!

I have a question on whether the client returned from mgr is ready to use before the call to mgr.Start()... It is a cache-backed client and I am not sure the cache will be synced when the readiness check calls it (perhaps leading to a .List() that returns fewer than actual items - resulting in a false-positive readiness check).

By default, when the controller starts up, it will automatically reconcile all Deployments... as far as I could tell there is no way to check when that initial run has completed, so I think it makes sense to do what you are doing here. However, I wonder if a cleaner way of accomplishing this would be to run a one-time List() (after cache is synced - or using a non-cache client) and iterate through and call Reconcile() (i.e. a forced full-reconciliation), then register an always-200 readiness handler.

PS: I don't know if there is any value in using this controller-runtime pkg to do the health checks or not, but might be worth a look: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/healthz#Handler

@alpe
Copy link
Contributor Author

alpe commented Dec 21, 2023

Good questions!
I did some manual tests before but the caching may be outdated indeed. A single List() seems more effective with the Reconcile() called.

I had looked at https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/healthz#Handler before but this is just a generic framework to customize the healthz server handlers. Most examples point to the Ping handler as generic 200 response.

cmd/lingo/main.go Outdated Show resolved Hide resolved
@@ -103,10 +105,15 @@ func run() error {
return fmt.Errorf("starting manager: %w", err)
}

if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the always 200 handler

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this start serving after mgr.Start()? If so, I think we need to move .Bootstrap() above mgr.Start().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit of a chicken/ egg problem. The mgr.Start() call also starts the cache syncs that we need for the bootstrap call. So with this implementation, the container may be "ready" but not alive, yet.
This can be solved with a custom handler that checks bootstrap was called once.
Good 👁️

pkg/deployments/manager.go Outdated Show resolved Hide resolved
cmd/lingo/main.go Outdated Show resolved Hide resolved
pkg/deployments/manager.go Outdated Show resolved Hide resolved
pkg/deployments/manager.go Outdated Show resolved Hide resolved
@@ -103,10 +105,15 @@ func run() error {
return fmt.Errorf("starting manager: %w", err)
}

if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this start serving after mgr.Start()? If so, I think we need to move .Bootstrap() above mgr.Start().

@alpe alpe marked this pull request as ready for review January 8, 2024 11:10
@alpe alpe changed the title Start readiness endpoint Add readiness endpoint Jan 8, 2024
@nstogner nstogner merged commit e51569a into substratusai:main Jan 9, 2024
3 checks passed
@alpe alpe deleted the 5_healthz_endpoint branch January 10, 2024 15:18
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.

add /healthz endpoint that responds 200 OK
2 participants