@@ -28,6 +28,9 @@ type Metrics struct {
2828 containerImageDuration * prometheus.GaugeVec
2929 containerImageErrors * prometheus.CounterVec
3030
31+ // Kubernetes version metric
32+ kubernetesVersion * prometheus.GaugeVec
33+
3134 cache k8sclient.Reader
3235
3336 // Contains all metrics for the roundtripper
@@ -80,6 +83,16 @@ func New(log *logrus.Entry, reg ctrmetrics.RegistererGatherer, cache k8sclient.R
8083 "namespace" , "pod" , "container" , "image" ,
8184 },
8285 )
86+ kubernetesVersion := promauto .With (reg ).NewGaugeVec (
87+ prometheus.GaugeOpts {
88+ Namespace : "version_checker" ,
89+ Name : "is_latest_kube_version" ,
90+ Help : "Where the current cluster is using the latest release channel version" ,
91+ },
92+ []string {
93+ "current_version" , "latest_version" , "channel" ,
94+ },
95+ )
8396
8497 return & Metrics {
8598 log : log .WithField ("module" , "metrics" ),
@@ -90,6 +103,7 @@ func New(log *logrus.Entry, reg ctrmetrics.RegistererGatherer, cache k8sclient.R
90103 containerImageDuration : containerImageDuration ,
91104 containerImageChecked : containerImageChecked ,
92105 containerImageErrors : containerImageErrors ,
106+ kubernetesVersion : kubernetesVersion ,
93107 roundTripper : NewRoundTripper (reg ),
94108 }
95109}
@@ -113,15 +127,11 @@ func (m *Metrics) AddImage(namespace, pod, container, containerType, imageURL st
113127 ).Set (float64 (time .Now ().Unix ()))
114128}
115129
116- func (m * Metrics ) RemoveImage (namespace , pod , container , containerType string ) {
117- m .mu .Lock ()
118- defer m .mu .Unlock ()
119- total := 0
120-
121- total += m .containerImageVersion .DeletePartialMatch (
130+ func (m * Metrics ) CleanUpMetrics (namespace , pod string ) (total int ) {
131+ total += m .containerImageDuration .DeletePartialMatch (
122132 m .buildPartialLabels (namespace , pod ),
123133 )
124- total += m .containerImageDuration .DeletePartialMatch (
134+ total += m .containerImageChecked .DeletePartialMatch (
125135 m .buildPartialLabels (namespace , pod ),
126136 )
127137
@@ -131,27 +141,23 @@ func (m *Metrics) RemoveImage(namespace, pod, container, containerType string) {
131141 total += m .containerImageErrors .DeletePartialMatch (
132142 m .buildPartialLabels (namespace , pod ),
133143 )
144+ return total
145+ }
146+
147+ func (m * Metrics ) RemoveImage (namespace , pod , container , containerType string ) {
148+ m .mu .Lock ()
149+ defer m .mu .Unlock ()
150+
151+ total := m .CleanUpMetrics (namespace , pod )
152+
134153 m .log .Infof ("Removed %d metrics for image %s/%s/%s" , total , namespace , pod , container )
135154}
136155
137156func (m * Metrics ) RemovePod (namespace , pod string ) {
138157 m .mu .Lock ()
139158 defer m .mu .Unlock ()
140159
141- total := 0
142- total += m .containerImageVersion .DeletePartialMatch (
143- m .buildPartialLabels (namespace , pod ),
144- )
145- total += m .containerImageDuration .DeletePartialMatch (
146- m .buildPartialLabels (namespace , pod ),
147- )
148- total += m .containerImageChecked .DeletePartialMatch (
149- m .buildPartialLabels (namespace , pod ),
150- )
151- total += m .containerImageErrors .DeletePartialMatch (
152- m .buildPartialLabels (namespace , pod ),
153- )
154-
160+ total := m .CleanUpMetrics (namespace , pod )
155161 m .log .Infof ("Removed %d metrics for pod %s/%s" , total , namespace , pod )
156162}
157163
0 commit comments