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 readiness probe for Kmesh daemon #1238

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ravjot07
Copy link
Contributor

@ravjot07 ravjot07 commented Feb 12, 2025

  • Implemented an HTTP readiness probe on port 8080 with a /ready endpoint.
  • The probe returns HTTP 200 (OK) when the daemon is ready and HTTP 503 (Not Ready) otherwise.
  • Uses an atomic flag to track readiness state.
  • Integrated with Kubernetes readinessProbe for health checks.
  • Ensures the Kmesh daemon is only marked ready after successful initialisation.

Test
Build kmeshctl
Ensure the daemon is running, then:

./kmeshctl readiness

If the daemon is ready, you see “Kmesh daemon is ready!”, otherwise you see a non-zero exit.

Check Readiness Manually
You can manually check the readiness probe using curl:

curl -X GET http://localhost:8080/ready

If the daemon is ready, it will return:

OK
with HTTP 200 (OK).

If it is not ready, it will return:

Not Ready
with HTTP 503 (Service Unavailable).

Fixes #495

@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kevin-wangzefeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: Ravjot Singh <[email protected]>
Signed-off-by: Ravjot Singh <[email protected]>
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.24%. Comparing base (2eb3f92) to head (7588563).
Report is 6 commits behind head on main.

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

Use: "readiness",
Short: "Check if the Kmesh daemon is healthy and ready",
Run: func(cmd *cobra.Command, args []string) {
readinessURL := "http://localhost:8080/ready"
Copy link
Collaborator

Choose a reason for hiding this comment

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

8080 is a commonly used port. You can choose one after 15000+.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okiee @LiZhenCheng9527 i will use port 15050

}

func init() {
rootCmd.AddCommand(readinessCmd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove it.
Add it to ./ctl/common/common.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okiee

* limitations under the License.
*/

package cmd
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change a more appropriate package name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"kmesh.net/kmesh/pkg/logger"

"github.com/sirupsen/logrus"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Changes to go-lint errors for all packages based on the error message from github action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will change them

var log = logger.NewLoggerScope("main")
log := logger.NewLoggerScope("main")

startReadinessServer(log)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The entrance should not be placed here. It should be placed after kmesh-daemon has finished starting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will update this

@@ -0,0 +1,25 @@
## kmeshctl authz status
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this commit include changes to these files? Did you include changes from another branch?

// startReadinessServer starts an HTTP server on :8080 with /ready
func startReadinessServer(log *logrus.Entry) {
mux := http.NewServeMux()
mux.HandleFunc("/ready", readinessHandler)
Copy link
Member

Choose a reason for hiding this comment

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

Prefer embedding this into status_server.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okiee @hzxuzhonghu i will update this one

@@ -25,4 +11,7 @@ kmeshctl authz [flags]
### SEE ALSO

* [kmeshctl](kmeshctl.md) - Kmesh command line tools to operate and debug Kmesh
* [kmeshctl authz disable](kmeshctl_authz_disable.md) - Disable xdp authz eBPF program for Kmesh's authz offloading
* [kmeshctl authz enable](kmeshctl_authz_enable.md) - Enable xdp authz eBPF program for Kmesh's authz offloading
* [kmeshctl authz status](kmeshctl_authz_status.md) - Display the current authorization status
Copy link
Member

Choose a reason for hiding this comment

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

How could the other pr passed without updating this doc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed to run gen check on other pr, i have raised a pr to solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Health check for Kmesh daemon
4 participants