Commit 74fb1ce3 authored by Geoff Simmons's avatar Geoff Simmons

Generate a Warn event if the creation of a VCL spec fails.

For this we make the event generating functions public, and move
their definitions into varnish.go, where most of the Controller
class is defined.
parent e45e4496
......@@ -44,6 +44,10 @@ import (
"k8s.io/client-go/tools/cache"
)
const (
vclSpecErr = "VCLspecError"
)
// SpecUpdaterConfig represents the user configuration for k8s
// resources that are considered for a VCL update.
type SpecUpdaterConfig struct {
......@@ -386,8 +390,8 @@ func (updater *SpecUpdater) Update() error {
updater.latestVCLMtime())
spec, err := updater.getSpec()
if err != nil {
// XXX generate Warn event
updater.log.Errorf("Cannot create spec: %s", err)
updater.vc.ErrorEvt(vclSpecErr, "Cannot create VCL spec: %+v",
err)
return err
}
cfgMap, err := updater.cfgMap.ConfigMaps(spec.CfgMap.Namespace).
......
......@@ -51,24 +51,6 @@ const (
monitorGood = "MonitorGood"
)
func (vc *Controller) infoEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Infof(msgFmt, args...)
vc.evt.PodInfoEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("info", reason).Inc()
}
func (vc *Controller) warnEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Warnf(msgFmt, args...)
vc.evt.PodWarnEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("warning", reason).Inc()
}
func (vc *Controller) errorEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Errorf(msgFmt, args...)
vc.evt.PodWarnEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("error", reason).Inc()
}
func (vc *Controller) checkInst() bool {
metrics.monitorChecks.Inc()
......@@ -83,7 +65,7 @@ func (vc *Controller) checkInst() bool {
addr, secret, err := vc.getAddrSecret()
if err != nil {
metrics.vsmFails.Inc()
vc.errorEvt(vsmErr, "Error reading admin address and secret: "+
vc.ErrorEvt(vsmErr, "Error reading admin address and secret: "+
"%v", err)
return false
}
......@@ -93,7 +75,7 @@ func (vc *Controller) checkInst() bool {
timer.ObserveDuration()
if err != nil {
metrics.connectFails.Inc()
vc.errorEvt(connectErr, "Error connecting: %v", err)
vc.ErrorEvt(connectErr, "Error connecting: %v", err)
return false
}
defer adm.Close()
......@@ -103,7 +85,7 @@ func (vc *Controller) checkInst() bool {
pong, err := adm.Ping()
if err != nil {
metrics.pingFails.Inc()
vc.errorEvt(pingErr, "Error pinging: %v", err)
vc.ErrorEvt(pingErr, "Error pinging: %v", err)
return false
}
metrics.pings.Inc()
......@@ -111,7 +93,7 @@ func (vc *Controller) checkInst() bool {
state, err := adm.Status()
if err != nil {
vc.errorEvt(statusErr, "Error getting status: %v", err)
vc.ErrorEvt(statusErr, "Error getting status: %v", err)
return false
}
if state == admin.Running {
......@@ -119,44 +101,44 @@ func (vc *Controller) checkInst() bool {
vc.log.Debugf("Status: %s", state)
} else {
metrics.childNotRunning.Inc()
vc.warnEvt(statusNotRun, "Status: %s", state)
vc.WarnEvt(statusNotRun, "Status: %s", state)
// XXX configure whether to auto-start
if state == admin.Stopped {
vc.log.Debug("Attempting restart")
if err := adm.Start(); err != nil {
vc.warnEvt(restartErr, "Cannot restart: %v",
vc.WarnEvt(restartErr, "Cannot restart: %v",
err)
metrics.restartFails.Inc()
return false
}
vc.infoEvt(restart, "Child restarted")
vc.InfoEvt(restart, "Child restarted")
metrics.restarts.Inc()
}
}
panic, err := adm.GetPanic()
if err != nil {
vc.errorEvt(panicErr, "Error getting panic: %v", err)
vc.ErrorEvt(panicErr, "Error getting panic: %v", err)
return false
}
if panic == "" {
vc.log.Debug("No panic")
} else {
metrics.panics.Inc()
vc.errorEvt(panic, "Panic: %s", panic)
vc.ErrorEvt(panic, "Panic: %s", panic)
// XXX clear the panic? Should be configurable
}
vcls, err := adm.VCLList()
if err != nil {
vc.errorEvt(vclListErr,
vc.ErrorEvt(vclListErr,
"Error getting VCL list: %v", err)
return false
}
for _, vcl := range vcls {
if vcl.Temperature == admin.ColdTemp {
if err = adm.VCLDiscard(vcl.Name); err != nil {
vc.errorEvt(discardErr,
vc.ErrorEvt(discardErr,
"Error discarding VCL %s: %v",
vcl.Name, err)
return false
......@@ -187,17 +169,17 @@ func (vc *Controller) monitor(monitorIntvl time.Duration) {
}
if vc.updater == nil {
vc.errorEvt(updateErr, "Updater not initialized")
vc.ErrorEvt(updateErr, "Updater not initialized")
metrics.updateErrs.Inc()
good = false
} else if err := vc.updater.Update(); err != nil {
vc.errorEvt(updateErr, "Errors updating Varnish: %+v",
vc.ErrorEvt(updateErr, "Errors updating Varnish: %+v",
err)
metrics.updateErrs.Inc()
good = false
}
if good {
vc.infoEvt(monitorGood, "Monitor check good")
vc.InfoEvt(monitorGood, "Monitor check good")
}
}
}
......@@ -290,3 +290,27 @@ func (vc *Controller) Quit() {
"finish")
vc.wg.Wait()
}
// InfoEvt generates an event with type Info for the Varnish pod, and
// logs a message at the Info level.
func (vc *Controller) InfoEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Infof(msgFmt, args...)
vc.evt.PodInfoEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("info", reason).Inc()
}
// WarnEvt generates an event with type Warning for the Varnish pod,
// and logs a message at the Warn level.
func (vc *Controller) WarnEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Warnf(msgFmt, args...)
vc.evt.PodWarnEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("warning", reason).Inc()
}
// ErrorEvt generates an event with type Warning for the Varnish pod,
// and logs a message at the Error level.
func (vc *Controller) ErrorEvt(reason, msgFmt string, args ...interface{}) {
vc.log.Errorf(msgFmt, args...)
vc.evt.PodWarnEvent(reason, msgFmt, args...)
monResultCtr.WithLabelValues("error", reason).Inc()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment