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

health check package #242

Closed
yutongp opened this issue Feb 12, 2017 · 1 comment
Closed

health check package #242

yutongp opened this issue Feb 12, 2017 · 1 comment

Comments

@yutongp
Copy link
Contributor

yutongp commented Feb 12, 2017

refer to this: https://github.com/uber-go/fx/blob/master/modules/uhttp/health.go#L32

I like the idea behind our internal gocommon health package. When we used it, we made some twists.

  1. instead of a Check func(), we defined an interface:
// Checkable is anything implemented Health method.
type Checkable interface {
	// Health takes a context and return error if health check failed.
	Health(ctx context.Context) error
}
// also func
type CheckableFunc func(ctx context.Context) error
func (f CheckableFunc) Health(ctx context.Context) error { return f(ctx) }

so all gateway or storage interfaces can be health checked once they implemented this interface. We can even automatically wrap the dependency's meta.thrift to it.

  1. we also add a Checker struct can do:
{
    // Add adds a Checkable map to a given name to Checker as a hard dependency.
    Add(name string, check Checkable)
    
    // AddSoft adds a Checkable map to a given name to Checker as a soft dependency.
    // If the check on soft dependency fails, checker will generate a warning message without make health check fail.
    AddSoft(name string, check Checkable)

    // ThriftHealthFunc returns a thrift health check function.
    ThriftHealthFunc() thrift.HealthFunc

    // HTTPHealthFunc returns a http health check function.
    HTTPHealthFunc(ctx context.Context) http.HandlerFunc
}

I think this is quite flexible compare to one global health checker since nowadays a service can serving more than one "service" with both soft and hard dependencies.
Also http.HandlerFunc can be mount under any route and thrift.HealthFunc can be mounted to tchannel.Service served on this server with Server.RegisterHealthHandler easily.
One issue is YARPC doesn't have Server.RegisterHealthHandler right now. I opened a ticket to track this: yarpc/yarpc-go#733.

  1. The remaining are the same. host name, timestamp, pid, response time, status will all be returned in health report.

What's you guys' thought on these interface/struct? What other features or integrations you think should be included in health check package?

@ascandella
Copy link
Contributor

Yes, we have plans for a much more advanced version where components can expose introspection data in a plugin model that you can then inspect from outside the service. It's on our internal issue tracker. Let's chat tomorrow about how to avoid overlap between GH issues and our internal roadmap.

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

No branches or pull requests

2 participants