-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
querier, receiver, sidecar, store: Add gRPC health check endpoints (#…
…2008) * Add gRPC health endpoints Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Add grpc life-cycle methods Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Utilize grpc health check server Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Update CHANGELOG Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Provide more structured way to probe Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Fix linted errors Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Remove white noise Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Add dedicated probe for instrumentation Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com> * Retest Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
- Loading branch information
Showing
17 changed files
with
360 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package prober | ||
|
||
import "sync" | ||
|
||
type combined struct { | ||
mu sync.Mutex | ||
probes []Probe | ||
} | ||
|
||
// Combine folds given probes into one, reflects their statuses in a thread-safe way. | ||
func Combine(probes ...Probe) Probe { | ||
return &combined{probes: probes} | ||
} | ||
|
||
// Ready sets components status to ready. | ||
func (p *combined) Ready() { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
for _, probe := range p.probes { | ||
probe.Ready() | ||
} | ||
} | ||
|
||
// NotReady sets components status to not ready with given error as a cause. | ||
func (p *combined) NotReady(err error) { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
for _, probe := range p.probes { | ||
probe.NotReady(err) | ||
} | ||
} | ||
|
||
// Healthy sets components status to healthy. | ||
func (p *combined) Healthy() { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
for _, probe := range p.probes { | ||
probe.Healthy() | ||
} | ||
} | ||
|
||
// NotHealthy sets components status to not healthy with given error as a cause. | ||
func (p *combined) NotHealthy(err error) { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
for _, probe := range p.probes { | ||
probe.NotHealthy(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package prober | ||
|
||
import ( | ||
"google.golang.org/grpc/health" | ||
grpc_health "google.golang.org/grpc/health/grpc_health_v1" | ||
) | ||
|
||
// GRPCProbe represents health and readiness status of given component, and provides GRPC integration. | ||
type GRPCProbe struct { | ||
h *health.Server | ||
} | ||
|
||
// NewGRPC creates a Probe that wrapped around grpc/healt.Server which reflects status of server. | ||
func NewGRPC() *GRPCProbe { | ||
h := health.NewServer() | ||
h.SetServingStatus("", grpc_health.HealthCheckResponse_NOT_SERVING) | ||
|
||
return &GRPCProbe{h: h} | ||
} | ||
|
||
// HealthServer returns a gRPC health server which responds readiness and liveness checks. | ||
func (p *GRPCProbe) HealthServer() *health.Server { | ||
return p.h | ||
} | ||
|
||
// Ready sets components status to ready. | ||
func (p *GRPCProbe) Ready() { | ||
p.h.SetServingStatus("", grpc_health.HealthCheckResponse_SERVING) | ||
} | ||
|
||
// NotReady sets components status to not ready with given error as a cause. | ||
func (p *GRPCProbe) NotReady(err error) { | ||
p.h.SetServingStatus("", grpc_health.HealthCheckResponse_NOT_SERVING) | ||
} | ||
|
||
// Healthy sets components status to healthy. | ||
func (p *GRPCProbe) Healthy() { | ||
p.h.Resume() | ||
} | ||
|
||
// NotHealthy sets components status to not healthy with given error as a cause. | ||
func (p *GRPCProbe) NotHealthy(err error) { | ||
p.h.Shutdown() | ||
} |
Oops, something went wrong.