Skip to content

Commit

Permalink
Generic health check via producer
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Sep 4, 2024
1 parent 4a221d1 commit 85f83c5
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 104 deletions.
16 changes: 16 additions & 0 deletions balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ type SubConn interface {
// indicate the shutdown operation. This may be delivered before
// in-progress RPCs are complete and the actual connection is closed.
Shutdown()
RegisterConnectivityListner(StateListener)
UnregisterConnectivityListner(StateListener)
}

// NewSubConnOptions contains options to create new SubConn.
Expand Down Expand Up @@ -261,6 +263,8 @@ type BuildOptions struct {
// metrics. Balancer implementations which do not register metrics on
// metrics registry and record on them can ignore this field.
MetricsRecorder estats.MetricsRecorder

HealthCheckOptions HealthCheckOptions
}

// Builder creates a balancer.
Expand Down Expand Up @@ -462,3 +466,15 @@ type ProducerBuilder interface {
// other methods to provide additional functionality, e.g. configuration or
// subscription registration.
type Producer any

type StateListener interface {
OnStateChange(SubConnState)
}

// HealthCheckOptions are the options to configure the health check producer.
type HealthCheckOptions struct {
DisableHealthCheckDialOpt bool
ServiceName func() string
HealthCheckFunc internal.HealthChecker
EnableHealthCheck bool
}
1 change: 1 addition & 0 deletions balancer/base/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *testClientConn) NewSubConn(addrs []resolver.Address, opts balancer.NewS
func (c *testClientConn) UpdateState(balancer.State) {}

type testSubConn struct {
balancer.SubConn
updateState func(balancer.SubConnState)
}

Expand Down
8 changes: 7 additions & 1 deletion balancer/endpointsharding/endpointsharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ func (es *endpointSharding) UpdateClientConnState(state balancer.ClientConnState
bal = child.(*balancerWrapper)
} else {
bal = &balancerWrapper{
childState: ChildState{Endpoint: endpoint},
childState: ChildState{
Endpoint: endpoint,
State: balancer.State{
ConnectivityState: connectivity.Connecting,
Picker: base.NewErrPicker(balancer.ErrNoSubConnAvailable),
},
},
ClientConn: es.cc,
es: es,
}
Expand Down
Loading

0 comments on commit 85f83c5

Please sign in to comment.