types.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017 by the contributors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package healthcheck
  15. import (
  16. "net/http"
  17. )
  18. // Check is a health/readiness check.
  19. type Check func() error
  20. // Handler is an http.Handler with additional methods that register health and
  21. // readiness checks. It handles handle "/live" and "/ready" HTTP
  22. // endpoints.
  23. type Handler interface {
  24. // The Handler is an http.Handler, so it can be exposed directly and handle
  25. // /live and /ready endpoints.
  26. http.Handler
  27. // AddLivenessCheck adds a check that indicates that this instance of the
  28. // application should be destroyed or restarted. A failed liveness check
  29. // indicates that this instance is unhealthy, not some upstream dependency.
  30. // Every liveness check is also included as a readiness check.
  31. AddLivenessCheck(name string, check Check)
  32. // AddReadinessCheck adds a check that indicates that this instance of the
  33. // application is currently unable to serve requests because of an upstream
  34. // or some transient failure. If a readiness check fails, this instance
  35. // should no longer receiver requests, but should not be restarted or
  36. // destroyed.
  37. AddReadinessCheck(name string, check Check)
  38. // LiveEndpoint is the HTTP handler for just the /live endpoint, which is
  39. // useful if you need to attach it into your own HTTP handler tree.
  40. LiveEndpoint(http.ResponseWriter, *http.Request)
  41. // ReadyEndpoint is the HTTP handler for just the /ready endpoint, which is
  42. // useful if you need to attach it into your own HTTP handler tree.
  43. ReadyEndpoint(http.ResponseWriter, *http.Request)
  44. }