forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.go
40 lines (33 loc) · 1.41 KB
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2014, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vttablet
// This file handles the health check. It is enabled by passing a
// target_tablet_type command line parameter. The tablet will then go
// to the target tablet type if healthy, and to 'spare' if not.
import (
"flag"
"time"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/vt/tabletmanager"
"github.com/youtube/vitess/go/vt/tabletmanager/actionnode"
"github.com/youtube/vitess/go/vt/topo"
)
var (
healthCheckInterval = flag.Duration("health_check_interval", 20*time.Second, "Interval between health checks")
targetTabletType = flag.String("target_tablet_type", "", "The tablet type we are thriving to be when healthy. When not healthy, we'll go to spare.")
lockTimeout = flag.Duration("lock_timeout", actionnode.DefaultLockTimeout, "lock time for wrangler/topo operations")
)
func initHeathCheck(agent *tabletmanager.ActionAgent) {
if *targetTabletType == "" {
log.Infof("No target_tablet_type specified, disabling any health check")
return
}
log.Infof("Starting up periodic health check every %v with target_tablet_type=%v", *healthCheckInterval, *targetTabletType)
go func() {
t := time.NewTicker(*healthCheckInterval)
for _ = range t.C {
agent.RunHealthCheck(topo.TabletType(*targetTabletType), *lockTimeout)
}
}()
}