fix: Add failure threshold to graceful shutdown

This commit is contained in:
motoki317 2024-11-22 00:48:36 +09:00
parent 872d64b05c
commit 4f43d4a78c
No known key found for this signature in database

View file

@ -400,12 +400,18 @@ func (n *NGINXController) stopWait() {
var scraper collectors.NginxStatusScraper var scraper collectors.NginxStatusScraper
lastRequests := 0 lastRequests := 0
noChangeTimes := 0 noChangeTimes := 0
failures := 0
const failureThreshold = 5
for ; ; time.Sleep(checkFrequency) { for ; ; time.Sleep(checkFrequency) {
st, err := scraper.Scrape() st, err := scraper.Scrape()
if err != nil { if err != nil {
klog.Warningf("failed to scrape nginx status: %v", err) klog.Warningf("failed to scrape nginx status: %v", err)
noChangeTimes = 0 failures++
if failures >= failureThreshold {
klog.Warningf("giving up graceful shutdown: too many nginx status scrape failures")
break
}
continue continue
} }