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 ( ...@@ -44,6 +44,10 @@ import (
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
) )
const (
vclSpecErr = "VCLspecError"
)
// SpecUpdaterConfig represents the user configuration for k8s // SpecUpdaterConfig represents the user configuration for k8s
// resources that are considered for a VCL update. // resources that are considered for a VCL update.
type SpecUpdaterConfig struct { type SpecUpdaterConfig struct {
...@@ -386,8 +390,8 @@ func (updater *SpecUpdater) Update() error { ...@@ -386,8 +390,8 @@ func (updater *SpecUpdater) Update() error {
updater.latestVCLMtime()) updater.latestVCLMtime())
spec, err := updater.getSpec() spec, err := updater.getSpec()
if err != nil { if err != nil {
// XXX generate Warn event updater.vc.ErrorEvt(vclSpecErr, "Cannot create VCL spec: %+v",
updater.log.Errorf("Cannot create spec: %s", err) err)
return err return err
} }
cfgMap, err := updater.cfgMap.ConfigMaps(spec.CfgMap.Namespace). cfgMap, err := updater.cfgMap.ConfigMaps(spec.CfgMap.Namespace).
......
...@@ -51,24 +51,6 @@ const ( ...@@ -51,24 +51,6 @@ const (
monitorGood = "MonitorGood" 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 { func (vc *Controller) checkInst() bool {
metrics.monitorChecks.Inc() metrics.monitorChecks.Inc()
...@@ -83,7 +65,7 @@ func (vc *Controller) checkInst() bool { ...@@ -83,7 +65,7 @@ func (vc *Controller) checkInst() bool {
addr, secret, err := vc.getAddrSecret() addr, secret, err := vc.getAddrSecret()
if err != nil { if err != nil {
metrics.vsmFails.Inc() metrics.vsmFails.Inc()
vc.errorEvt(vsmErr, "Error reading admin address and secret: "+ vc.ErrorEvt(vsmErr, "Error reading admin address and secret: "+
"%v", err) "%v", err)
return false return false
} }
...@@ -93,7 +75,7 @@ func (vc *Controller) checkInst() bool { ...@@ -93,7 +75,7 @@ func (vc *Controller) checkInst() bool {
timer.ObserveDuration() timer.ObserveDuration()
if err != nil { if err != nil {
metrics.connectFails.Inc() metrics.connectFails.Inc()
vc.errorEvt(connectErr, "Error connecting: %v", err) vc.ErrorEvt(connectErr, "Error connecting: %v", err)
return false return false
} }
defer adm.Close() defer adm.Close()
...@@ -103,7 +85,7 @@ func (vc *Controller) checkInst() bool { ...@@ -103,7 +85,7 @@ func (vc *Controller) checkInst() bool {
pong, err := adm.Ping() pong, err := adm.Ping()
if err != nil { if err != nil {
metrics.pingFails.Inc() metrics.pingFails.Inc()
vc.errorEvt(pingErr, "Error pinging: %v", err) vc.ErrorEvt(pingErr, "Error pinging: %v", err)
return false return false
} }
metrics.pings.Inc() metrics.pings.Inc()
...@@ -111,7 +93,7 @@ func (vc *Controller) checkInst() bool { ...@@ -111,7 +93,7 @@ func (vc *Controller) checkInst() bool {
state, err := adm.Status() state, err := adm.Status()
if err != nil { if err != nil {
vc.errorEvt(statusErr, "Error getting status: %v", err) vc.ErrorEvt(statusErr, "Error getting status: %v", err)
return false return false
} }
if state == admin.Running { if state == admin.Running {
...@@ -119,44 +101,44 @@ func (vc *Controller) checkInst() bool { ...@@ -119,44 +101,44 @@ func (vc *Controller) checkInst() bool {
vc.log.Debugf("Status: %s", state) vc.log.Debugf("Status: %s", state)
} else { } else {
metrics.childNotRunning.Inc() metrics.childNotRunning.Inc()
vc.warnEvt(statusNotRun, "Status: %s", state) vc.WarnEvt(statusNotRun, "Status: %s", state)
// XXX configure whether to auto-start // XXX configure whether to auto-start
if state == admin.Stopped { if state == admin.Stopped {
vc.log.Debug("Attempting restart") vc.log.Debug("Attempting restart")
if err := adm.Start(); err != nil { if err := adm.Start(); err != nil {
vc.warnEvt(restartErr, "Cannot restart: %v", vc.WarnEvt(restartErr, "Cannot restart: %v",
err) err)
metrics.restartFails.Inc() metrics.restartFails.Inc()
return false return false
} }
vc.infoEvt(restart, "Child restarted") vc.InfoEvt(restart, "Child restarted")
metrics.restarts.Inc() metrics.restarts.Inc()
} }
} }
panic, err := adm.GetPanic() panic, err := adm.GetPanic()
if err != nil { if err != nil {
vc.errorEvt(panicErr, "Error getting panic: %v", err) vc.ErrorEvt(panicErr, "Error getting panic: %v", err)
return false return false
} }
if panic == "" { if panic == "" {
vc.log.Debug("No panic") vc.log.Debug("No panic")
} else { } else {
metrics.panics.Inc() metrics.panics.Inc()
vc.errorEvt(panic, "Panic: %s", panic) vc.ErrorEvt(panic, "Panic: %s", panic)
// XXX clear the panic? Should be configurable // XXX clear the panic? Should be configurable
} }
vcls, err := adm.VCLList() vcls, err := adm.VCLList()
if err != nil { if err != nil {
vc.errorEvt(vclListErr, vc.ErrorEvt(vclListErr,
"Error getting VCL list: %v", err) "Error getting VCL list: %v", err)
return false return false
} }
for _, vcl := range vcls { for _, vcl := range vcls {
if vcl.Temperature == admin.ColdTemp { if vcl.Temperature == admin.ColdTemp {
if err = adm.VCLDiscard(vcl.Name); err != nil { if err = adm.VCLDiscard(vcl.Name); err != nil {
vc.errorEvt(discardErr, vc.ErrorEvt(discardErr,
"Error discarding VCL %s: %v", "Error discarding VCL %s: %v",
vcl.Name, err) vcl.Name, err)
return false return false
...@@ -187,17 +169,17 @@ func (vc *Controller) monitor(monitorIntvl time.Duration) { ...@@ -187,17 +169,17 @@ func (vc *Controller) monitor(monitorIntvl time.Duration) {
} }
if vc.updater == nil { if vc.updater == nil {
vc.errorEvt(updateErr, "Updater not initialized") vc.ErrorEvt(updateErr, "Updater not initialized")
metrics.updateErrs.Inc() metrics.updateErrs.Inc()
good = false good = false
} else if err := vc.updater.Update(); err != nil { } else if err := vc.updater.Update(); err != nil {
vc.errorEvt(updateErr, "Errors updating Varnish: %+v", vc.ErrorEvt(updateErr, "Errors updating Varnish: %+v",
err) err)
metrics.updateErrs.Inc() metrics.updateErrs.Inc()
good = false good = false
} }
if good { if good {
vc.infoEvt(monitorGood, "Monitor check good") vc.InfoEvt(monitorGood, "Monitor check good")
} }
} }
} }
...@@ -290,3 +290,27 @@ func (vc *Controller) Quit() { ...@@ -290,3 +290,27 @@ func (vc *Controller) Quit() {
"finish") "finish")
vc.wg.Wait() 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