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

[dbnode] Emit metric with dbnode health status #2588

Merged
merged 7 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/dbnode/client/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import (
"github.com/m3db/m3/src/dbnode/generated/thrift/rpc"
"github.com/m3db/m3/src/dbnode/topology"
xclose "github.com/m3db/m3/src/x/close"
"github.com/m3db/stackmurmur3/v2"
murmur3 "github.com/m3db/stackmurmur3/v2"

"github.com/uber-go/tally"
"github.com/uber/tchannel-go/thrift"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -63,6 +64,7 @@ type connPool struct {
sleepHealth sleepFn
sleepHealthRetry sleepFn
status status
healthStatus tally.Gauge
}

type conn struct {
Expand Down Expand Up @@ -94,6 +96,7 @@ func newConnectionPool(host topology.Host, opts Options) connectionPool {
sleepConnect: time.Sleep,
sleepHealth: time.Sleep,
sleepHealthRetry: time.Sleep,
healthStatus: opts.InstrumentOptions().MetricsScope().Gauge("health-status"),
}

return p
Expand Down Expand Up @@ -186,11 +189,13 @@ func (p *connPool) connectEvery(interval time.Duration, stutter time.Duration) {

// Health check the connection
if err := p.healthCheckNewConn(client, p.opts); err != nil {
p.healthStatus.Update(float64(healthStatusCheckFailed))
log.Debug("could not connect, failed health check", zap.String("host", address), zap.Error(err))
channel.Close()
return
}

p.healthStatus.Update(float64(healthStatusOK))
p.Lock()
if p.status == statusOpen {
p.pool = append(p.pool, conn{channel, client})
Expand Down
7 changes: 7 additions & 0 deletions src/dbnode/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,13 @@ const (
statusClosed
)

type healthStatus int

const (
healthStatusCheckFailed healthStatus = iota
healthStatusOK
)

type op interface {
// Size returns the effective size of inner operations.
Size() int
Expand Down