Skip to content

Commit 4dd4995

Browse files
Metrics: Fix nginx_ingress_controller_config_last_reload_successful. (#13860)
Signed-off-by: Roman Orudzhov <[email protected]> Co-authored-by: Roman Orudzhov <[email protected]>
1 parent a8fae7c commit 4dd4995

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
@@ -192,7 +192,18 @@ func (n *NGINXController) syncIngress(interface{}) error {
192192
n.metricCollector.SetSSLExpireTime(servers)
193193
n.metricCollector.SetSSLInfo(servers)
194194

195+
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
196+
TagName: "json",
197+
})
198+
if err != nil {
199+
klog.Errorf("unexpected error hashing configuration: %v", err)
200+
}
201+
195202
if n.runningConfig.Equal(pcfg) {
203+
if !n.lastConfigSuccess {
204+
n.metricCollector.ConfigSuccess(hash, true)
205+
n.lastConfigSuccess = true
206+
}
196207
klog.V(3).Infof("No configuration change detected, skipping backend reload")
197208
return nil
198209
}
@@ -202,19 +213,13 @@ func (n *NGINXController) syncIngress(interface{}) error {
202213
if !utilingress.IsDynamicConfigurationEnough(pcfg, n.runningConfig) {
203214
klog.InfoS("Configuration changes detected, backend reload required")
204215

205-
hash, err := hashstructure.Hash(pcfg, hashstructure.FormatV1, &hashstructure.HashOptions{
206-
TagName: "json",
207-
})
208-
if err != nil {
209-
klog.Errorf("unexpected error hashing configuration: %v", err)
210-
}
211-
212216
pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash)
213217

214218
err = n.OnUpdate(*pcfg)
215219
if err != nil {
216220
n.metricCollector.IncReloadErrorCount()
217221
n.metricCollector.ConfigSuccess(hash, false)
222+
n.lastConfigSuccess = false
218223
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
219224
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
220225
return err
@@ -223,6 +228,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
223228
klog.InfoS("Backend successfully reloaded")
224229
n.metricCollector.ConfigSuccess(hash, true)
225230
n.metricCollector.IncReloadCount()
231+
n.lastConfigSuccess = true
226232

227233
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
228234
}
@@ -243,7 +249,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
243249
}
244250

245251
retriesRemaining := retry.Steps
246-
err := wait.ExponentialBackoff(retry, func() (bool, error) {
252+
err = wait.ExponentialBackoff(retry, func() (bool, error) {
247253
err := n.configureDynamically(pcfg)
248254
if err == nil {
249255
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)