Only the leader updates metrics for SSL certificate expiration
This commit is contained in:
parent
870b89c72b
commit
f4e4335d8c
4 changed files with 44 additions and 16 deletions
|
|
@ -190,7 +190,11 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
|||
klog.Infof("Backend successfully reloaded.")
|
||||
n.metricCollector.ConfigSuccess(hash, true)
|
||||
n.metricCollector.IncReloadCount()
|
||||
n.metricCollector.SetSSLExpireTime(servers)
|
||||
|
||||
if n.isLeader() {
|
||||
klog.V(2).Infof("Updating ssl expiration metrics.")
|
||||
n.metricCollector.SetSSLExpireTime(servers)
|
||||
}
|
||||
}
|
||||
|
||||
isFirstSync := n.runningConfig.Equal(&ingress.Configuration{})
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
|
@ -255,6 +256,8 @@ type NGINXController struct {
|
|||
fileSystem filesystem.Filesystem
|
||||
|
||||
metricCollector metric.Collector
|
||||
|
||||
currentLeader uint32
|
||||
}
|
||||
|
||||
// Start starts a new NGINX master process running in the foreground.
|
||||
|
|
@ -278,19 +281,15 @@ func (n *NGINXController) Start() {
|
|||
go n.syncStatus.Run(stopCh)
|
||||
}
|
||||
|
||||
n.setLeader(true)
|
||||
n.metricCollector.OnStartedLeading(electionID)
|
||||
// manually update SSL expiration metrics
|
||||
// (to not wait for a reload)
|
||||
n.metricCollector.SetSSLExpireTime(n.runningConfig.Servers)
|
||||
},
|
||||
OnStoppedLeading: func() {
|
||||
n.setLeader(false)
|
||||
n.metricCollector.OnStoppedLeading(electionID)
|
||||
|
||||
// Remove prometheus metrics related to SSL certificates
|
||||
srvs := sets.NewString()
|
||||
for _, s := range n.runningConfig.Servers {
|
||||
if !srvs.Has(s.Hostname) {
|
||||
srvs.Insert(s.Hostname)
|
||||
}
|
||||
}
|
||||
n.metricCollector.RemoveMetrics(nil, srvs.List())
|
||||
},
|
||||
PodName: n.podInfo.Name,
|
||||
PodNamespace: n.podInfo.Namespace,
|
||||
|
|
@ -1129,3 +1128,15 @@ func buildRedirects(servers []*ingress.Server) []*redirect {
|
|||
|
||||
return redirectServers
|
||||
}
|
||||
|
||||
func (n *NGINXController) setLeader(leader bool) {
|
||||
var i uint32
|
||||
if leader {
|
||||
i = 1
|
||||
}
|
||||
atomic.StoreUint32(&n.currentLeader, i)
|
||||
}
|
||||
|
||||
func (n *NGINXController) isLeader() bool {
|
||||
return atomic.LoadUint32(&n.currentLeader) != 0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue