You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is usually used in a readiness check to wait until consumer is ready and then a service is ready to process incoming requests. Readiness check is a simple function interface
// ReadyCheckFunc defines a function type for implementing a readiness check.typeReadyCheckFuncfunc() ReadyStatus
Currently, every time when one wants to use this feature they have to implement boilerplate readiness check.
Describe the solution
Add new package patron/probe independent from HTTP. It can be used then in gRPC probes.
Extract probes related code into this new package in patron/probe/probe.go
Add deterministic readiness check implementation in this new package in patron/probe/deterministic.go.
Additional context
New package with 2 files
patron/probe
-- probe.go
-- deterministic.go
Move probe related code into probe/probe.go file from component/http/v2/check.go.
Leave code related to http routes there.
package probe
// AliveStatus type representing the liveness of the service.typeAliveStatusint// ReadyStatus type.typeReadyStatusintconst (
// Alive represents a state defining an Alive state.AliveAliveStatus=1// Unhealthy represents an unhealthy alive state.UnhealthyAliveStatus=2// Ready represents a state defining a Ready state.ReadyReadyStatus=1// NotReady represents a state defining a NotReady state.NotReadyReadyStatus=2// AlivePath of the component.AlivePath="/alive"// ReadyPath of the component.ReadyPath="/ready"
)
// ReadyCheckFunc defines a function type for implementing a readiness check.typeReadyCheckFuncfunc() ReadyStatus// LivenessCheckFunc defines a function type for implementing a liveness check.typeLivenessCheckFuncfunc() AliveStatus
Add another file probe/deterministic.go with the following deterministic ready check implementation.
package probe
import (
"sync""time""github.com/beatlabs/patron/log"
)
// DeterministicReadyCheck waits until all the defined channels are closedtypeDeterministicReadyCheckstruct {
sync.Mutexchecksmap[string]*readyCheckstatus v2.ReadyStatus
}
// NewDeterministicReadyCheck creates new deterministic checkfuncNewDeterministicReadyCheck() *DeterministicReadyCheck {
return&DeterministicReadyCheck{
checks: make(map[string]*readyCheck),
status: v2.NotReady,
}
}
// AddCheck add new channel to watch when it's closedfunc (r*DeterministicReadyCheck) AddCheck(namestring, chchanstruct{}) *DeterministicReadyCheck {
r.checks[name] =&readyCheck{name: name, ch: ch, startedAt: time.Now()}
returnr
}
// Status ask when all the checks are readyfunc (r*DeterministicReadyCheck) Status() v2.ReadyStatus {
r.Lock()
deferr.Unlock()
ifr.status==v2.NotReady {
for_, chk:=ranger.checks {
if!chk.isReady() {
returnr.status
}
}
r.status=v2.Ready
}
returnr.status
}
typereadyCheckstruct {
namestringch<-chanstruct{}
startedAt time.Timeclosedbool
}
func (r*readyCheck) isReady() bool {
ifr.closed {
returntrue
}
// if channel was closed, set the flag and log how long it tookselect {
case_, ok:=<-r.ch:
if!ok {
r.closed=truelog.Infof("readiness %s: %v", r.name, time.Since(r.startedAt))
returntrue
}
default:
}
returnfalse
}
The text was updated successfully, but these errors were encountered:
koschos
changed the title
Add Deterministic Start ReadyCheck implementation
Add Deterministic ReadyCheck implementation
Oct 24, 2022
Is your feature request related to a problem? Please describe
In
kafka
component we have a feature which provides info when a consumer is reached current offset (it closes a channel)This is usually used in a readiness check to wait until consumer is ready and then a service is ready to process incoming requests.
Readiness check is a simple function interface
Currently, every time when one wants to use this feature they have to implement boilerplate readiness check.
Describe the solution
patron/probe
independent from HTTP. It can be used then in gRPC probes.patron/probe/probe.go
patron/probe/deterministic.go
.Additional context
New package with 2 files
Move probe related code into
probe/probe.go
file fromcomponent/http/v2/check.go
.Leave code related to http routes there.
Add another file
probe/deterministic.go
with the following deterministic ready check implementation.The text was updated successfully, but these errors were encountered: