@@ -5,20 +5,23 @@ package e2e
5
5
import (
6
6
"context"
7
7
"fmt"
8
+ "regexp"
9
+ "time"
10
+
8
11
. "github.com/onsi/ginkgo"
9
12
. "github.com/onsi/gomega"
10
13
corev1 "k8s.io/api/core/v1"
11
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
15
"k8s.io/apimachinery/pkg/util/net"
13
- "regexp"
14
16
15
17
"github.com/operator-framework/api/pkg/operators/v1alpha1"
16
18
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
17
19
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
20
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
18
21
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
19
22
)
20
23
21
- var _ = Describe ("Metrics are generated for OLM pod " , func () {
24
+ var _ = Describe ("Metrics are generated for OLM managed resources " , func () {
22
25
23
26
var (
24
27
c operatorclient.ClientInterface
@@ -69,7 +72,7 @@ var _ = Describe("Metrics are generated for OLM pod", func() {
69
72
It ("generates csv_abnormal metric for OLM pod" , func () {
70
73
71
74
// Verify metrics have been emitted for packageserver csv
72
- Expect (getMetricsFromPod (c , getOLMPod ( c ), "8081" )).To (And (
75
+ Expect (getMetricsFromPod (c , getPodWithLabel ( c , "app=olm-operator" ), "8081" )).To (And (
73
76
ContainSubstring ("csv_abnormal" ),
74
77
ContainSubstring (fmt .Sprintf ("name=\" %s\" " , failingCSV .Name )),
75
78
ContainSubstring ("phase=\" Failed\" " ),
@@ -91,18 +94,89 @@ var _ = Describe("Metrics are generated for OLM pod", func() {
91
94
92
95
It ("deletes its associated CSV metrics" , func () {
93
96
// Verify that when the csv has been deleted, it deletes the corresponding CSV metrics
94
- Expect (getMetricsFromPod (c , getOLMPod ( c ), "8081" )).ToNot (And (
97
+ Expect (getMetricsFromPod (c , getPodWithLabel ( c , "app=olm-operator" ), "8081" )).ToNot (And (
95
98
ContainSubstring ("csv_abnormal{name=\" %s\" " , failingCSV .Name ),
96
99
ContainSubstring ("csv_succeeded{name=\" %s\" " , failingCSV .Name ),
97
100
))
98
101
})
99
102
})
100
103
})
101
104
})
105
+
106
+ Context ("Subscription Metric" , func () {
107
+ var (
108
+ subscriptionCleanup cleanupFunc
109
+ subscription * v1alpha1.Subscription
110
+ )
111
+ When ("A subscription object is created" , func () {
112
+
113
+ BeforeEach (func () {
114
+ subscriptionCleanup , _ = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-create" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
115
+ })
116
+
117
+ It ("generates subscription_sync_total metric" , func () {
118
+
119
+ // Verify metrics have been emitted for subscription
120
+ Eventually (func () string {
121
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
122
+ }, time .Minute , 5 * time .Second ).Should (And (
123
+ ContainSubstring ("subscription_sync_total" ),
124
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .NAME_LABEL , "metric-subscription-for-create" )),
125
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .CHANNEL_LABEL , stableChannel )),
126
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .PACKAGE_LABEL , testPackageName ))))
127
+ })
128
+ if subscriptionCleanup != nil {
129
+ subscriptionCleanup ()
130
+ }
131
+ })
132
+ When ("A subscription object is updated" , func () {
133
+
134
+ BeforeEach (func () {
135
+ subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-update" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
136
+ subscription .Spec .Channel = "beta"
137
+ updateSubscription (GinkgoT (), crc , subscription )
138
+ })
139
+
140
+ It ("deletes the old Subscription metric and emits the new metric" , func () {
141
+ Eventually (func () string {
142
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
143
+ }, time .Minute , 5 * time .Second ).ShouldNot (And (
144
+ ContainSubstring ("subscription_sync_total{name=\" metric-subscription-for-update\" " ),
145
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .CHANNEL_LABEL , stableChannel ))))
146
+
147
+ Eventually (func () string {
148
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
149
+ }, time .Minute , 5 * time .Second ).Should (And (
150
+ ContainSubstring ("subscription_sync_total" ),
151
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .NAME_LABEL , "metric-subscription-for-update" )),
152
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .CHANNEL_LABEL , "beta" )),
153
+ ContainSubstring (fmt .Sprintf ("%s=\" %s\" " , metrics .PACKAGE_LABEL , testPackageName ))))
154
+ })
155
+ if subscriptionCleanup != nil {
156
+ subscriptionCleanup ()
157
+ }
158
+ })
159
+
160
+ When ("A subscription object is deleted" , func () {
161
+
162
+ BeforeEach (func () {
163
+ subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-delete" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
164
+ if subscriptionCleanup != nil {
165
+ subscriptionCleanup ()
166
+ }
167
+ })
168
+
169
+ It ("deletes the Subscription metric" , func () {
170
+ Eventually (func () string {
171
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
172
+ }, time .Minute , 5 * time .Second ).ShouldNot (ContainSubstring ("subscription_sync_total{name=\" metric-subscription-for-update\" " ))
173
+ })
174
+ })
175
+ })
102
176
})
103
177
104
- func getOLMPod (client operatorclient.ClientInterface ) * corev1.Pod {
105
- listOptions := metav1.ListOptions {LabelSelector : "app=olm-operator" }
178
+ func getPodWithLabel (client operatorclient.ClientInterface , label string ) * corev1.Pod {
179
+ listOptions := metav1.ListOptions {LabelSelector : label }
106
180
var podList * corev1.PodList
107
181
Eventually (func () (err error ) {
108
182
podList , err = client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (context .TODO (), listOptions )
0 commit comments