Metrics: Fix `nginx_ingress_controller_config_last_reload_successful`. (#13860)
Signed-off-by: Roman Orudzhov <roman.orudzhov@flant.com> Co-authored-by: Roman Orudzhov <roman.orudzhov@flant.com>
This commit is contained in:
parent
a8fae7cf75
commit
4dd49959fa
|
|
@ -192,7 +192,18 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
||||||
n.metricCollector.SetSSLExpireTime(servers)
|
n.metricCollector.SetSSLExpireTime(servers)
|
||||||
n.metricCollector.SetSSLInfo(servers)
|
n.metricCollector.SetSSLInfo(servers)
|
||||||
|
|
||||||
|
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
|
||||||
|
TagName: "json",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("unexpected error hashing configuration: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if n.runningConfig.Equal(pcfg) {
|
if n.runningConfig.Equal(pcfg) {
|
||||||
|
if !n.lastConfigSuccess {
|
||||||
|
n.metricCollector.ConfigSuccess(hash, true)
|
||||||
|
n.lastConfigSuccess = true
|
||||||
|
}
|
||||||
klog.V(3).Infof("No configuration change detected, skipping backend reload")
|
klog.V(3).Infof("No configuration change detected, skipping backend reload")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -202,19 +213,13 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
||||||
if !utilingress.IsDynamicConfigurationEnough(pcfg, n.runningConfig) {
|
if !utilingress.IsDynamicConfigurationEnough(pcfg, n.runningConfig) {
|
||||||
klog.InfoS("Configuration changes detected, backend reload required")
|
klog.InfoS("Configuration changes detected, backend reload required")
|
||||||
|
|
||||||
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
|
|
||||||
TagName: "json",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("unexpected error hashing configuration: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash)
|
pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash)
|
||||||
|
|
||||||
err = n.OnUpdate(*pcfg)
|
err = n.OnUpdate(*pcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.metricCollector.IncReloadErrorCount()
|
n.metricCollector.IncReloadErrorCount()
|
||||||
n.metricCollector.ConfigSuccess(hash, false)
|
n.metricCollector.ConfigSuccess(hash, false)
|
||||||
|
n.lastConfigSuccess = false
|
||||||
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
|
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
|
||||||
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
|
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
|
||||||
return err
|
return err
|
||||||
|
|
@ -223,6 +228,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
||||||
klog.InfoS("Backend successfully reloaded")
|
klog.InfoS("Backend successfully reloaded")
|
||||||
n.metricCollector.ConfigSuccess(hash, true)
|
n.metricCollector.ConfigSuccess(hash, true)
|
||||||
n.metricCollector.IncReloadCount()
|
n.metricCollector.IncReloadCount()
|
||||||
|
n.lastConfigSuccess = true
|
||||||
|
|
||||||
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
|
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
|
||||||
}
|
}
|
||||||
|
|
@ -243,7 +249,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
retriesRemaining := retry.Steps
|
retriesRemaining := retry.Steps
|
||||||
err := wait.ExponentialBackoff(retry, func() (bool, error) {
|
err = wait.ExponentialBackoff(retry, func() (bool, error) {
|
||||||
err := n.configureDynamically(pcfg)
|
err := n.configureDynamically(pcfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
klog.V(2).Infof("Dynamic reconfiguration succeeded.")
|
klog.V(2).Infof("Dynamic reconfiguration succeeded.")
|
||||||
|
|
|
||||||
|
|
@ -264,6 +264,8 @@ type NGINXController struct {
|
||||||
validationWebhookServer *http.Server
|
validationWebhookServer *http.Server
|
||||||
|
|
||||||
command NginxExecTester
|
command NginxExecTester
|
||||||
|
|
||||||
|
lastConfigSuccess bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts a new NGINX master process running in the foreground.
|
// Start starts a new NGINX master process running in the foreground.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue