Compare commits
No commits in common. "b906789967f9724b227dd49d9a56b7c3a0711779" and "429db2d8ed1c10c78940de386ed41f4e7f318cfd" have entirely different histories.
b906789967
...
429db2d8ed
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,15 +1,3 @@
|
|||||||
## [1.2.0-rc.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.1.0...v1.2.0-rc.1) (2024-03-01)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **handlers:** add individual handlers fetching ([bb108ad](https://git.ext.icikowski.pl/go/kubeprobes/commit/bb108ad9baf7a14c7e39709a58987706a713d4ce))
|
|
||||||
|
|
||||||
|
|
||||||
### Refactoring
|
|
||||||
|
|
||||||
* **kubeprobes:** refactor code ([d33e9f1](https://git.ext.icikowski.pl/go/kubeprobes/commit/d33e9f19ea353cd320d584ad093c311f66eb1b28))
|
|
||||||
|
|
||||||
## [1.1.0](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.0.0...v1.1.0) (2024-02-29)
|
## [1.1.0](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.0.0...v1.1.0) (2024-02-29)
|
||||||
|
|
||||||
|
|
||||||
|
56
README.md
56
README.md
@ -10,23 +10,19 @@ go get -u pkg.icikowski.pl/kubeprobes
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The package provides `kubeprobes.New` function which returns a probes handler of type `kubeprobes.Kubeprobes`, which is compliant with `http.Handler` interface.
|
The package provides `kubeprobes.New` function which returns a probes handler compliant with `http.Handler` interface.
|
||||||
|
|
||||||
The handler serves two endpoints, which are used to implement liveness and readiness probes by returning either `200` (healthy) or `503` (unhealthy) status:
|
The handler serves two endpoints, which are used to implement liveness and readiness probes by returning either `200` (healthy) or `503` (unhealthy) status:
|
||||||
|
|
||||||
- `/live` - endpoint for liveness probe;
|
- `/live` - endpoint for liveness probe;
|
||||||
- `/ready` - endpoint for readiness probe.
|
- `/ready` - endpoint for readiness probe.
|
||||||
|
|
||||||
Default paths can be overriden with options described below. Accessing any other endpoint will return `404` status. In order to provide maximum performance, no body is ever returned.
|
Accessing any other endpoint will return `404` status. In order to provide maximum performance, no body is ever returned.
|
||||||
|
|
||||||
The `kubeprobes.New` function accepts following options as arguments:
|
The `kubeprobes.New` function accepts following options-applying functions as arguments:
|
||||||
|
|
||||||
- `kubeprobes.WithLivenessProbes(...)` - adds particular [probe functions](#probe-functions) to the list of liveness probes;
|
- `kubeprobes.WithLivenessProbes(/* ... */)` - adds particular [probes](#probes) to the list of liveness probes;
|
||||||
- `kubeprobes.WithLivenessStatefulProbes(...)` - adds particular [`StatefulProbe`s](#stateful-probes) to the list of liveness probes;
|
- `kubeprobes.WithReadinessProbes(/* ... */)` - adds particular [probes](#probes) to the list of readiness probes.
|
||||||
- `kubeprobes.WithLivenessPath("/some/liveness/path")` - sets liveness probe path to given path (default is `/live`);
|
|
||||||
- `kubeprobes.WithReadinessProbes(...)` - adds particular [probe functions](#probe-functions) to the list of readiness probes;
|
|
||||||
- `kubeprobes.WithReadinessStatefulProbes(...)` - adds particular [`StatefulProbe`s](#stateful-probes) to the list of readiness probes;
|
|
||||||
- `kubeprobes.WithReadinessPath("/some/readiness/path")` - sets readiness probe path to given path (default is `/ready`).
|
|
||||||
|
|
||||||
## Probes
|
## Probes
|
||||||
|
|
||||||
@ -51,7 +47,7 @@ someOtherProbe := func() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use functions in probes handler
|
// Use functions in probes handler
|
||||||
kp, _ := kubeprobes.New(
|
kp := kubeprobes.New(
|
||||||
kubeprobes.WithLivenessProbes(someOtherProbe),
|
kubeprobes.WithLivenessProbes(someOtherProbe),
|
||||||
kubeprobes.WithReadinessProbes(someProbe),
|
kubeprobes.WithReadinessProbes(someProbe),
|
||||||
)
|
)
|
||||||
@ -67,52 +63,24 @@ someProbe := kubeprobes.NewStatefulProbe()
|
|||||||
someOtherProbe := kubeprobes.NewStatefulProbe()
|
someOtherProbe := kubeprobes.NewStatefulProbe()
|
||||||
|
|
||||||
// Use it in probes handler
|
// Use it in probes handler
|
||||||
kp, _ := kubeprobes.New(
|
kp := kubeprobes.New(
|
||||||
kubeprobes.WithLivenessStatefulProbes(someProbe),
|
kubeprobes.WithLivenessProbes(someProbe.GetProbeFunction()),
|
||||||
kubeprobes.WithReadinessStatefulProbes(someOtherProbe),
|
kubeprobes.WithReadinessProbes(someOtherProbe.GetProbeFunction()),
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Direct handler access
|
|
||||||
|
|
||||||
It is possible to fetch `http.Handler`s for liveness & readiness probes from `kubeprobes.Kubeprobes` instance as follows:
|
|
||||||
|
|
||||||
```go
|
|
||||||
kp, _ := kubeprobes.New(
|
|
||||||
// ...
|
|
||||||
)
|
|
||||||
|
|
||||||
livenessHandler := kp.GetLivenessHandler()
|
|
||||||
readinessHandler := kp.GetReadinessHandler()
|
|
||||||
```
|
|
||||||
|
|
||||||
Those handler can be used for manually mounting them on other servers/routers/muxes (eg. `go-chi/chi`, `gorilla/mux`, `http`'s `ServeMux` etc.).
|
|
||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Create probe functions
|
|
||||||
appProbe := func() error {
|
|
||||||
// Some logic for checking app status
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create stateful probes
|
// Create stateful probes
|
||||||
live := kubeprobes.NewStatefulProbe()
|
live := kubeprobes.NewStatefulProbe()
|
||||||
ready := kubeprobes.NewStatefulProbe()
|
ready := kubeprobes.NewStatefulProbe()
|
||||||
|
|
||||||
// Prepare handler
|
// Prepare handler
|
||||||
kp, err := kubeprobes.New(
|
kp := kubeprobes.New(
|
||||||
kubeprobes.WithLivenessStatefulProbes(live),
|
kubeprobes.WithLivenessProbes(live.GetProbeFunction()),
|
||||||
kubeprobes.WithReadinessStatefulProbes(ready),
|
kubeprobes.WithReadinessProbes(ready.GetProbeFunction()),
|
||||||
kubeprobes.WithReadinessProbes(appProbe),
|
|
||||||
kubeprobes.WithLivenessPath("/livez"),
|
|
||||||
kubeprobes.WithReadinessPath("/readyz"),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
// Kubeprobes object is validated for invalid or conflicting paths! ;)
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the probes server
|
// Start the probes server
|
||||||
probes := &http.Server{
|
probes := &http.Server{
|
||||||
|
@ -2,6 +2,11 @@ package kubeprobes
|
|||||||
|
|
||||||
import "sync"
|
import "sync"
|
||||||
|
|
||||||
|
// ProbeFunction is a function that determines whether
|
||||||
|
// the given metric may be marked as correctly functioning.
|
||||||
|
// It not, the error should be returned.
|
||||||
|
type ProbeFunction func() error
|
||||||
|
|
||||||
type statusQuery struct {
|
type statusQuery struct {
|
||||||
allGreen bool
|
allGreen bool
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
@ -1,7 +0,0 @@
|
|||||||
package kubeprobes
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultLivenessPath string = "/live"
|
|
||||||
defaultReadinessPath string = "/ready"
|
|
||||||
verboseOutputFlag string = "v"
|
|
||||||
)
|
|
67
options.go
67
options.go
@ -1,67 +0,0 @@
|
|||||||
package kubeprobes
|
|
||||||
|
|
||||||
type option struct {
|
|
||||||
fn func(*kubeprobes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *option) apply(kp *kubeprobes) {
|
|
||||||
o.fn(kp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithLivenessProbes adds given probe functions to the set of liveness probes.
|
|
||||||
func WithLivenessProbes(probes ...ProbeFunction) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
kp.livenessProbes = append(kp.livenessProbes, probes...)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithLivenessStatefulProbes adds given [StatefulProbe]s to the set of liveness probes.
|
|
||||||
func WithLivenessStatefulProbes(probes ...*StatefulProbe) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
for _, p := range probes {
|
|
||||||
kp.livenessProbes = append(kp.livenessProbes, p.GetProbeFunction())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithLivenessPath sets custom path for liveness probe (default is "/live").
|
|
||||||
func WithLivenessPath(path string) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
kp.pathLive = path
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithReadinessProbes adds given probe functions to the set of readiness probes.
|
|
||||||
func WithReadinessProbes(probes ...ProbeFunction) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
kp.readinessProbes = append(kp.readinessProbes, probes...)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithReadinessProbes adds given [StatefulProbe]s to the set of readiness probes.
|
|
||||||
func WithReadinessStatefulProbes(probes ...*StatefulProbe) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
for _, p := range probes {
|
|
||||||
kp.readinessProbes = append(kp.readinessProbes, p.GetProbeFunction())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithReadinessPath sets custom path for readiness probe (default is "/ready").
|
|
||||||
func WithReadinessPath(path string) Option {
|
|
||||||
return &option{
|
|
||||||
fn: func(kp *kubeprobes) {
|
|
||||||
kp.pathReady = path
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "kubeprobes",
|
"name": "kubeprobes",
|
||||||
"version": "1.2.0-rc.1",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "kubeprobes",
|
"name": "kubeprobes",
|
||||||
"version": "1.2.0-rc.1",
|
"version": "1.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@saithodev/semantic-release-gitea": "^2.1.0",
|
"@saithodev/semantic-release-gitea": "^2.1.0",
|
||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "kubeprobes",
|
"name": "kubeprobes",
|
||||||
"version": "1.2.0-rc.1",
|
"version": "1.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"release": "./node_modules/.bin/semantic-release"
|
"release": "./node_modules/.bin/semantic-release"
|
||||||
},
|
},
|
||||||
|
146
probes.go
146
probes.go
@ -1,8 +1,6 @@
|
|||||||
package kubeprobes
|
package kubeprobes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -10,107 +8,57 @@ import (
|
|||||||
type kubeprobes struct {
|
type kubeprobes struct {
|
||||||
livenessProbes []ProbeFunction
|
livenessProbes []ProbeFunction
|
||||||
readinessProbes []ProbeFunction
|
readinessProbes []ProbeFunction
|
||||||
|
|
||||||
pathLive string
|
|
||||||
pathReady string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new instance of a Kubernetes probes with given options.
|
// ServeHTTP implements http.Handler interface
|
||||||
func New(options ...Option) (Kubeprobes, error) {
|
|
||||||
kp := &kubeprobes{
|
|
||||||
livenessProbes: []ProbeFunction{},
|
|
||||||
readinessProbes: []ProbeFunction{},
|
|
||||||
pathLive: "/live",
|
|
||||||
pathReady: "/ready",
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, option := range options {
|
|
||||||
option.apply(kp)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := kp.validate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return kp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (kp *kubeprobes) validate() error {
|
|
||||||
errs := []error{}
|
|
||||||
|
|
||||||
if kp.pathLive == "" {
|
|
||||||
errs = append(
|
|
||||||
errs,
|
|
||||||
fmt.Errorf("liveness probe path must not be empty"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if kp.pathReady == "" {
|
|
||||||
errs = append(
|
|
||||||
errs,
|
|
||||||
fmt.Errorf("readiness probe path must not be empty"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(kp.pathLive, "/") {
|
|
||||||
errs = append(
|
|
||||||
errs,
|
|
||||||
fmt.Errorf("liveness probe path must start with slash (current: %q)", kp.pathLive),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(kp.pathReady, "/") {
|
|
||||||
errs = append(
|
|
||||||
errs,
|
|
||||||
fmt.Errorf("readiness probe path must start with slash (current: %q)", kp.pathReady),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if kp.pathLive == kp.pathReady {
|
|
||||||
errs = append(
|
|
||||||
errs,
|
|
||||||
fmt.Errorf("liveness and readiness probes have the same values (both %q)", kp.pathLive),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.Join(errs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (kp *kubeprobes) handleLiveness(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
sq := newStatusQuery(kp.livenessProbes)
|
|
||||||
if sq.isAllGreen() {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (kp *kubeprobes) handleReadiness(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...))
|
|
||||||
if sq.isAllGreen() {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLivenessHandler implements Kubeprobes.
|
|
||||||
func (kp *kubeprobes) GetLivenessHandler() http.Handler {
|
|
||||||
return http.HandlerFunc(kp.handleLiveness)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetReadinessHandler implements Kubeprobes.
|
|
||||||
func (kp *kubeprobes) GetReadinessHandler() http.Handler {
|
|
||||||
return http.HandlerFunc(kp.handleReadiness)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeHTTP implements Kubeprobes.
|
|
||||||
func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
subs := strings.Split(strings.TrimSuffix(r.URL.Path, "/"), "/")
|
||||||
case kp.pathLive:
|
switch subs[len(subs)-1] {
|
||||||
kp.handleLiveness(w, r)
|
case "live":
|
||||||
case kp.pathReady:
|
sq := newStatusQuery(kp.livenessProbes)
|
||||||
kp.handleReadiness(w, r)
|
if sq.isAllGreen() {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
}
|
||||||
|
case "ready":
|
||||||
|
sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...))
|
||||||
|
if sq.isAllGreen() {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type option func(*kubeprobes)
|
||||||
|
|
||||||
|
// New returns a new instance of a Kubernetes probes
|
||||||
|
func New(options ...option) *kubeprobes {
|
||||||
|
kp := &kubeprobes{
|
||||||
|
livenessProbes: []ProbeFunction{},
|
||||||
|
readinessProbes: []ProbeFunction{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, option := range options {
|
||||||
|
option(kp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kp
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithLivenessProbes adds given liveness probes to the set of probes
|
||||||
|
func WithLivenessProbes(probes ...ProbeFunction) option {
|
||||||
|
return func(kp *kubeprobes) {
|
||||||
|
kp.livenessProbes = append(kp.livenessProbes, probes...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithReadinessProbes adds given readiness probes to the set of probes
|
||||||
|
func WithReadinessProbes(probes ...ProbeFunction) option {
|
||||||
|
return func(kp *kubeprobes) {
|
||||||
|
kp.readinessProbes = append(kp.readinessProbes, probes...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,9 +50,9 @@ func TestKubeprobes(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
kp, _ := New(
|
kp := New(
|
||||||
WithLivenessStatefulProbes(live),
|
WithLivenessProbes(live.GetProbeFunction()),
|
||||||
WithReadinessStatefulProbes(ready),
|
WithReadinessProbes(ready.GetProbeFunction()),
|
||||||
)
|
)
|
||||||
|
|
||||||
srv := httptest.NewServer(kp)
|
srv := httptest.NewServer(kp)
|
||||||
@ -65,8 +65,8 @@ func TestKubeprobes(t *testing.T) {
|
|||||||
test.livenessProbeTransformation(t, live)
|
test.livenessProbeTransformation(t, live)
|
||||||
test.readinessProbeTransformation(t, ready)
|
test.readinessProbeTransformation(t, ready)
|
||||||
|
|
||||||
liveStatus := getStatusFromEndpoint(t, client, srv.URL+defaultLivenessPath)
|
liveStatus := getStatusFromEndpoint(t, client, srv.URL+"/live")
|
||||||
readyStatus := getStatusFromEndpoint(t, client, srv.URL+defaultReadinessPath)
|
readyStatus := getStatusFromEndpoint(t, client, srv.URL+"/ready")
|
||||||
otherStatus := getStatusFromEndpoint(t, client, srv.URL+"/something")
|
otherStatus := getStatusFromEndpoint(t, client, srv.URL+"/something")
|
||||||
|
|
||||||
if liveStatus != test.expectedLiveStatus {
|
if liveStatus != test.expectedLiveStatus {
|
||||||
|
@ -5,13 +5,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errProbeDown = errors.New("probe is down")
|
var errProbeDown = errors.New("DOWN")
|
||||||
|
|
||||||
// StatefulProbe represents the simple probe that can be either
|
// StatefulProbe represents the simple probe that can be either
|
||||||
// marked as "up" (healthy) or "down" (unhealthy).
|
// marked as "up" (healthy) or "down" (unhealthy).
|
||||||
type StatefulProbe struct {
|
type StatefulProbe struct {
|
||||||
mux sync.Mutex
|
|
||||||
status bool
|
status bool
|
||||||
|
mux sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStatefulProbe returns a new instance of a stateful probe
|
// NewStatefulProbe returns a new instance of a stateful probe
|
||||||
@ -19,19 +19,19 @@ type StatefulProbe struct {
|
|||||||
// The probe is initially marked as "down".
|
// The probe is initially marked as "down".
|
||||||
func NewStatefulProbe() *StatefulProbe {
|
func NewStatefulProbe() *StatefulProbe {
|
||||||
return &StatefulProbe{
|
return &StatefulProbe{
|
||||||
mux: sync.Mutex{},
|
|
||||||
status: false,
|
status: false,
|
||||||
|
mux: sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkAsUp marks the probe as healthy.
|
// MarkAsUp marks the probe as healthy
|
||||||
func (sp *StatefulProbe) MarkAsUp() {
|
func (sp *StatefulProbe) MarkAsUp() {
|
||||||
sp.mux.Lock()
|
sp.mux.Lock()
|
||||||
defer sp.mux.Unlock()
|
defer sp.mux.Unlock()
|
||||||
sp.status = true
|
sp.status = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkAsDown marks the probe as unhealthy.
|
// MarkAsDown marks the probe as unhealthy
|
||||||
func (sp *StatefulProbe) MarkAsDown() {
|
func (sp *StatefulProbe) MarkAsDown() {
|
||||||
sp.mux.Lock()
|
sp.mux.Lock()
|
||||||
defer sp.mux.Unlock()
|
defer sp.mux.Unlock()
|
||||||
|
23
types.go
23
types.go
@ -1,23 +0,0 @@
|
|||||||
package kubeprobes
|
|
||||||
|
|
||||||
import "net/http"
|
|
||||||
|
|
||||||
// Kubeprobes represents liveness & readiness probes handler.
|
|
||||||
type Kubeprobes interface {
|
|
||||||
http.Handler
|
|
||||||
|
|
||||||
// GetLivenessHandler returns [http.Handler] for liveness probes.
|
|
||||||
GetLivenessHandler() http.Handler
|
|
||||||
// GetReadinessHandler returns [http.Handler] for readiness probes.
|
|
||||||
GetReadinessHandler() http.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
// Option represents a [Kubeprobes] constructor option.
|
|
||||||
type Option interface {
|
|
||||||
apply(kp *kubeprobes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProbeFunction is a function that determines whether
|
|
||||||
// the given metric may be marked as correctly functioning.
|
|
||||||
// It not, the error should be returned.
|
|
||||||
type ProbeFunction func() error
|
|
Loading…
Reference in New Issue
Block a user