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

feat: add /status/ready function #454

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tao12345666333
Copy link
Member

ref: Kong/kubernetes-ingress-controller#5068

This endpoint should be used to health-check Kong nodes. This can be health checks from orchestration frameworks like k8s or by load-balancers fronting Kong nodes that proxy traffic. This endpoint returns 200 only after the Kong node has configured itself and is ready to start proxying traffic.

https://docs.konghq.com/gateway/api/status/latest/#/default/get_status_ready

@tao12345666333 tao12345666333 requested review from a team as code owners July 17, 2024 07:50
@CLAassistant
Copy link

CLAassistant commented Jul 17, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 60.86957% with 18 lines in your changes missing coverage. Please review.

Project coverage is 59.58%. Comparing base (afe0c7b) to head (a2bc45b).

Files Patch % Lines
kong/client.go 52.63% 14 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #454      +/-   ##
==========================================
- Coverage   59.61%   59.58%   -0.04%     
==========================================
  Files          71       71              
  Lines        4408     4449      +41     
==========================================
+ Hits         2628     2651      +23     
- Misses       1166     1180      +14     
- Partials      614      618       +4     
Flag Coverage Δ
2.1 35.62% <23.91%> (-0.20%) ⬇️
2.2 48.03% <23.91%> (-0.32%) ⬇️
2.3 48.66% <23.91%> (-0.32%) ⬇️
2.4 48.70% <23.91%> (-0.32%) ⬇️
2.5 48.70% <23.91%> (-0.32%) ⬇️
2.6 48.70% <23.91%> (-0.32%) ⬇️
2.7 50.39% <23.91%> (-0.34%) ⬇️
2.8 50.39% <23.91%> (-0.34%) ⬇️
3.0 54.52% <23.91%> (-0.38%) ⬇️
3.1 56.14% <23.91%> (-0.39%) ⬇️
3.2 56.14% <23.91%> (-0.39%) ⬇️
3.3 56.52% <60.86%> (-0.01%) ⬇️
3.4 58.88% <60.86%> (-0.03%) ⬇️
3.5 56.70% <60.86%> (-0.01%) ⬇️
3.6 56.70% <60.86%> (-0.01%) ⬇️
community 43.78% <60.86%> (+0.11%) ⬆️
enterprise 57.96% <56.52%> (-0.07%) ⬇️
integration 59.58% <60.86%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tao12345666333 tao12345666333 force-pushed the feat-add-status-ready branch 3 times, most recently from c0ba631 to a8b4e6e Compare July 20, 2024 17:48
@tao12345666333 tao12345666333 marked this pull request as ready for review July 20, 2024 19:00
kong/client.go Outdated Show resolved Hide resolved
kong/client.go Outdated Show resolved Hide resolved
}

func parseStatusListen(listen string) string {
re := regexp.MustCompile(`^([\w\.:]+)\s*(.*)?`)
Copy link
Member

Choose a reason for hiding this comment

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

Can we extract the regex to not compile it on every call?

Comment on lines +141 to +142
address := matches[1]
extraParams := matches[2]
Copy link
Member

Choose a reason for hiding this comment

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

What if matches is 1 or 2 entries long? This will blow up then. Can we check for that as well here?

@@ -391,6 +455,21 @@ func (c *Client) Status(ctx context.Context) (*Status, error) {
return &s, nil
}

// Ready returns 200 only after the Kong node has configured itself and is ready to start proxying traffic.
Copy link
Member

Choose a reason for hiding this comment

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

Can we link to the official docs here? Specifically to https://docs.konghq.com/gateway/latest/production/monitoring/healthcheck-probes/#types-of-health-checks

I'd consider mentioning that this function uses Kong's "Readiness" endpoint.

kong/client_test.go Outdated Show resolved Hide resolved

sm, err := client.Ready(defaultCtx)
if err != nil {
// for dbless mode, the ready endpoint returns 503
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about moving this message to assertion so that it's logged when the test fails?

assert.Equal("HTTP status 503 (message: \"no configuration available (empty configuration present)\")", err.Error())
assert.Nil(sm)
} else {
// for db-mode, the ready endpoint returns 200
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about moving this message to assertion so that it's logged when the test fails?

assert.NotNil(client)

sm, err := client.Ready(defaultCtx)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This can produce false positives when the err != nil and we use db-mode. Can we use a different method here to inspect which flavor of Kong we're running against? e.g. inspecting the configuration?

@tao12345666333 tao12345666333 self-assigned this Jul 23, 2024
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.

4 participants