@@ -5,17 +5,17 @@ import (
5
5
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6
6
"k8s.io/apimachinery/pkg/labels"
7
7
8
+ olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
8
9
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
9
10
v1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
10
- olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
11
-
12
11
)
13
12
14
13
const (
15
14
NAME_LABEL = "name"
16
15
INSTALLED_LABEL = "installed"
16
+ NAMESPACE_LABEL = "namespace"
17
17
VERSION_LABEL = "version"
18
- PHASE_LABEL = "phase"
18
+ PHASE_LABEL = "phase"
19
19
REASON_LABEL = "reason"
20
20
)
21
21
@@ -151,18 +151,27 @@ var (
151
151
[]string {NAME_LABEL , INSTALLED_LABEL },
152
152
)
153
153
154
- csvSyncCounter = prometheus .NewCounterVec (
155
- prometheus.CounterOpts {
156
- Name : "csv_sync_total" ,
157
- Help : "Monotonic count of CSV syncs" ,
154
+ csvSucceeded = prometheus .NewGaugeVec (
155
+ prometheus.GaugeOpts {
156
+ Name : "csv_succeeded" ,
157
+ Help : "Successful CSV install" ,
158
+ },
159
+ []string {NAMESPACE_LABEL , NAME_LABEL , VERSION_LABEL },
160
+ )
161
+
162
+ csvAbnormal = prometheus .NewGaugeVec (
163
+ prometheus.GaugeOpts {
164
+ Name : "csv_abnormal" ,
165
+ Help : "CSV is not installed" ,
158
166
},
159
- []string {NAME_LABEL , VERSION_LABEL , PHASE_LABEL , REASON_LABEL },
167
+ []string {NAMESPACE_LABEL , NAME_LABEL , VERSION_LABEL , PHASE_LABEL , REASON_LABEL },
160
168
)
161
169
)
162
170
163
171
func RegisterOLM () {
164
172
prometheus .MustRegister (csvCount )
165
- prometheus .MustRegister (csvSyncCounter )
173
+ prometheus .MustRegister (csvSucceeded )
174
+ prometheus .MustRegister (csvAbnormal )
166
175
prometheus .MustRegister (CSVUpgradeCount )
167
176
}
168
177
@@ -177,6 +186,26 @@ func CounterForSubscription(name, installedCSV string) prometheus.Counter {
177
186
return SubscriptionSyncCount .WithLabelValues (name , installedCSV )
178
187
}
179
188
180
- func EmitCSVMetric (csv * olmv1alpha1.ClusterServiceVersion ){
181
- csvSyncCounter .WithLabelValues (csv .Name , csv .Spec .Version .String (), string (csv .Status .Phase ), string (csv .Status .Reason )).Inc ()
189
+ func EmitCSVMetric (oldCSV * olmv1alpha1.ClusterServiceVersion , newCSV * olmv1alpha1.ClusterServiceVersion ) {
190
+ if oldCSV == nil || newCSV == nil {
191
+ return
192
+ }
193
+
194
+ // Don't update the metric for copies
195
+ if newCSV .Status .Reason == olmv1alpha1 .CSVReasonCopied {
196
+ return
197
+ }
198
+
199
+ // Delete the old CSV metrics
200
+ csvAbnormal .DeleteLabelValues (oldCSV .Namespace , oldCSV .Name , oldCSV .Spec .Version .String (), string (oldCSV .Status .Phase ), string (oldCSV .Status .Reason ))
201
+
202
+ // Get the phase of the new CSV
203
+ newCSVPhase := string (newCSV .Status .Phase )
204
+ csvSucceededGauge := csvSucceeded .WithLabelValues (newCSV .Namespace , newCSV .Name , newCSV .Spec .Version .String ())
205
+ if newCSVPhase == string (olmv1alpha1 .CSVPhaseSucceeded ) {
206
+ csvSucceededGauge .Set (1 )
207
+ } else {
208
+ csvSucceededGauge .Set (0 )
209
+ csvAbnormal .WithLabelValues (newCSV .Namespace , newCSV .Name , newCSV .Spec .Version .String (), string (newCSV .Status .Phase ), string (newCSV .Status .Reason )).Set (1 )
210
+ }
182
211
}
0 commit comments