metrics controller ticker

This commit is contained in:
Joakim Karlsson 2018-02-03 22:49:57 +01:00
parent 12aec99844
commit 4f8f83d6eb
3 changed files with 19 additions and 11 deletions

View File

@ -84,7 +84,7 @@ func (hc *HealthController) CheckHealth() bool {
} }
func (hc *HealthController) Run(healthChan <-chan *ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup) error { func (hc *HealthController) Run(healthChan <-chan *ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup) error {
t := time.NewTicker(3 * time.Second) t := time.NewTicker(1.5 * time.Second)
defer wg.Done() defer wg.Done()
glog.Info("Starting health controller") glog.Info("Starting health controller")
@ -114,7 +114,7 @@ func (hc *HealthController) Run(healthChan <-chan *ControllerHeartbeat, stopCh <
case heartbeat := <-healthChan: case heartbeat := <-healthChan:
hc.HandleHeartbeat(heartbeat) hc.HandleHeartbeat(heartbeat)
case <-t.C: case <-t.C:
glog.Info("Health controller tick") glog.V(4).Info("Health controller tick")
} }
} }

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"sync" "sync"
"time"
"github.com/cloudnativelabs/kube-router/app/options" "github.com/cloudnativelabs/kube-router/app/options"
"github.com/golang/glog" "github.com/golang/glog"
@ -119,6 +120,7 @@ type MetricsController struct {
// Run prometheus metrics controller // Run prometheus metrics controller
func (mc *MetricsController) Run(healthChan chan<- *ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup) error { func (mc *MetricsController) Run(healthChan chan<- *ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup) error {
t := time.NewTicker(3 * time.Second)
defer wg.Done() defer wg.Done()
glog.Info("Starting metrics controller") glog.Info("Starting metrics controller")
@ -136,15 +138,21 @@ func (mc *MetricsController) Run(healthChan chan<- *ControllerHeartbeat, stopCh
glog.Errorf("Metrics controller error: %s", err) glog.Errorf("Metrics controller error: %s", err)
} }
}() }()
for {
sendHeartBeat(healthChan, "MC") sendHeartBeat(healthChan, "MC")
select {
<-stopCh case <-stopCh:
glog.Infof("Shutting down metrics controller") glog.Infof("Shutting down metrics controller")
if err := srv.Shutdown(context.Background()); err != nil { if err := srv.Shutdown(context.Background()); err != nil {
glog.Errorf("could not shutdown: %v", err) glog.Errorf("could not shutdown: %v", err)
}
return nil
case <-t.C:
glog.V(4).Info("Metrics controller tick")
} }
return nil
} }
// NewMetricsController returns new MetricController object // NewMetricsController returns new MetricController object

View File

@ -141,7 +141,7 @@ func (kr *KubeRouter) Run() error {
return errors.New("Failed to create metrics controller: " + err.Error()) return errors.New("Failed to create metrics controller: " + err.Error())
} }
wg.Add(1) wg.Add(1)
go mc.Run(stopCh, &wg) go mc.Run(healthChan, stopCh, &wg)
} else if kr.Config.MetricsPort > 65535 { } else if kr.Config.MetricsPort > 65535 {
glog.Errorf("Metrics port must be over 0 and under 65535, given port: %d", kr.Config.MetricsPort) glog.Errorf("Metrics port must be over 0 and under 65535, given port: %d", kr.Config.MetricsPort)