Skip to content

Commit 2991694

Browse files
Metrics: Fix nginx_ingress_controller_config_last_reload_successful. (#13859)
Signed-off-by: Roman Orudzhov <[email protected]> Co-authored-by: Roman Orudzhov <[email protected]>
1 parent aafd201 commit 2991694

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

internal/ingress/controller/controller.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,18 @@ func (n *NGINXController) syncIngress(interface{}) error {
185185
n.metricCollector.SetSSLExpireTime(servers)
186186
n.metricCollector.SetSSLInfo(servers)
187187

188+
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
189+
TagName: "json",
190+
})
191+
if err != nil {
192+
klog.Errorf("unexpected error hashing configuration: %v", err)
193+
}
194+
188195
if n.runningConfig.Equal(pcfg) {
196+
if !n.lastConfigSuccess {
197+
n.metricCollector.ConfigSuccess(hash, true)
198+
n.lastConfigSuccess = true
199+
}
189200
klog.V(3).Infof("No configuration change detected, skipping backend reload")
190201
return nil
191202
}
@@ -195,19 +206,13 @@ func (n *NGINXController) syncIngress(interface{}) error {
195206
if !utilingress.IsDynamicConfigurationEnough(pcfg, n.runningConfig) {
196207
klog.InfoS("Configuration changes detected, backend reload required")
197208

198-
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
199-
TagName: "json",
200-
})
201-
if err != nil {
202-
klog.Errorf("unexpected error hashing configuration: %v", err)
203-
}
204-
205209
pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash)
206210

207211
err = n.OnUpdate(*pcfg)
208212
if err != nil {
209213
n.metricCollector.IncReloadErrorCount()
210214
n.metricCollector.ConfigSuccess(hash, false)
215+
n.lastConfigSuccess = false
211216
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
212217
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
213218
return err
@@ -216,6 +221,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
216221
klog.InfoS("Backend successfully reloaded")
217222
n.metricCollector.ConfigSuccess(hash, true)
218223
n.metricCollector.IncReloadCount()
224+
n.lastConfigSuccess = true
219225

220226
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
221227
}
@@ -236,7 +242,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
236242
}
237243

238244
retriesRemaining := retry.Steps
239-
err := wait.ExponentialBackoff(retry, func() (bool, error) {
245+
err = wait.ExponentialBackoff(retry, func() (bool, error) {
240246
err := n.configureDynamically(pcfg)
241247
if err == nil {
242248
klog.V(2).Infof("Dynamic reconfiguration succeeded.")

internal/ingress/controller/nginx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ type NGINXController struct {
264264
validationWebhookServer *http.Server
265265

266266
command NginxExecTester
267+
268+
lastConfigSuccess bool
267269
}
268270

269271
// Start starts a new NGINX master process running in the foreground.

0 commit comments

Comments
 (0)