Skip to content

Commit

Permalink
Merge pull request #6155 from planetscale/ds-new-healthcheck
Browse files Browse the repository at this point in the history
Healthcheck: new simpler implementation
  • Loading branch information
sougou authored May 27, 2020
2 parents 33b03b7 + 3343c21 commit bcbee47
Show file tree
Hide file tree
Showing 78 changed files with 6,942 additions and 1,968 deletions.
6 changes: 3 additions & 3 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (

ts *topo.Server
resilientServer *srvtopo.ResilientServer
healthCheck discovery.HealthCheck
healthCheck discovery.LegacyHealthCheck
)

func init() {
Expand Down Expand Up @@ -118,7 +118,7 @@ func main() {

// vtgate configuration and init
resilientServer = srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")
healthCheck = discovery.NewHealthCheck(1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/)
healthCheck := discovery.NewLegacyHealthCheck(1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/)
tabletTypesToWait := []topodatapb.TabletType{
topodatapb.TabletType_MASTER,
topodatapb.TabletType_REPLICA,
Expand All @@ -128,7 +128,7 @@ func main() {
vtgate.QueryLogHandler = "/debug/vtgate/querylog"
vtgate.QueryLogzHandler = "/debug/vtgate/querylogz"
vtgate.QueryzHandler = "/debug/vtgate/queryz"
vtg := vtgate.Init(context.Background(), healthCheck, resilientServer, tpb.Cells[0], 2 /*retryCount*/, tabletTypesToWait)
vtg := vtgate.LegacyInit(context.Background(), healthCheck, resilientServer, tpb.Cells[0], 2 /*retryCount*/, tabletTypesToWait)

// vtctld configuration and init
vtctld.InitVtctld(ts)
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtcombo/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func addStatusParts(vtg *vtgate.VTGate) {
servenv.AddStatusPart("Gateway Status", vtgate.StatusTemplate, func() interface{} {
return vtg.GetGatewayCacheStatus()
})
servenv.AddStatusPart("Health Check Cache", discovery.HealthCheckTemplate, func() interface{} {
servenv.AddStatusPart("Health Check Cache", discovery.LegacyHealthCheckTemplate, func() interface{} {
return healthCheck.CacheStatus()
})
}
12 changes: 9 additions & 3 deletions go/cmd/vtgate/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ func addStatusParts(vtg *vtgate.VTGate) {
servenv.AddStatusPart("Gateway Status", vtgate.StatusTemplate, func() interface{} {
return vtg.GetGatewayCacheStatus()
})
servenv.AddStatusPart("Health Check Cache", discovery.HealthCheckTemplate, func() interface{} {
return healthCheck.CacheStatus()
})
if *vtgate.GatewayImplementation == vtgate.GatewayImplementationDiscovery {
servenv.AddStatusPart("Health Check Cache", discovery.LegacyHealthCheckTemplate, func() interface{} {
return legacyHealthCheck.CacheStatus()
})
} else {
servenv.AddStatusPart("Health Check Cache", discovery.HealthCheckTemplate, func() interface{} {
return vtg.Gateway().HealthCheck().CacheStatus()
})
}
}
30 changes: 20 additions & 10 deletions go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ import (
)

var (
cell = flag.String("cell", "test_nj", "cell to use")
retryCount = flag.Int("retry-count", 2, "retry count")
healthCheckRetryDelay = flag.Duration("healthcheck_retry_delay", 2*time.Millisecond, "health check retry delay")
healthCheckTimeout = flag.Duration("healthcheck_timeout", time.Minute, "the health check timeout period")
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
cell = flag.String("cell", "test_nj", "cell to use")
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
)

var resilientServer *srvtopo.ResilientServer
var healthCheck discovery.HealthCheck
var legacyHealthCheck discovery.LegacyHealthCheck

func init() {
rand.Seed(time.Now().UnixNano())
Expand All @@ -63,9 +60,6 @@ func main() {

resilientServer = srvtopo.NewResilientServer(ts, "ResilientSrvTopoServer")

healthCheck = discovery.NewHealthCheck(*healthCheckRetryDelay, *healthCheckTimeout)
healthCheck.RegisterStats()

tabletTypes := make([]topodatapb.TabletType, 0, 1)
if len(*tabletTypesToWait) != 0 {
for _, ttStr := range strings.Split(*tabletTypesToWait, ",") {
Expand All @@ -78,12 +72,28 @@ func main() {
}
}

vtg := vtgate.Init(context.Background(), healthCheck, resilientServer, *cell, *retryCount, tabletTypes)
var vtg *vtgate.VTGate
if *vtgate.GatewayImplementation == vtgate.GatewayImplementationDiscovery {
// default value
legacyHealthCheck = discovery.NewLegacyHealthCheck(*vtgate.HealthCheckRetryDelay, *vtgate.HealthCheckTimeout)
legacyHealthCheck.RegisterStats()

vtg = vtgate.LegacyInit(context.Background(), legacyHealthCheck, resilientServer, *cell, *vtgate.RetryCount, tabletTypes)
} else {
// use new Init otherwise
vtg = vtgate.Init(context.Background(), resilientServer, *cell, tabletTypes)
}

servenv.OnRun(func() {
// Flags are parsed now. Parse the template using the actual flag value and overwrite the current template.
discovery.ParseTabletURLTemplateFromFlag()
addStatusParts(vtg)
})
servenv.OnClose(func() {
_ = vtg.Gateway().Close(context.Background())
if legacyHealthCheck != nil {
_ = legacyHealthCheck.Close()
}
})
servenv.RunDefault()
}
Loading

0 comments on commit bcbee47

Please sign in to comment.