@@ -26,6 +26,7 @@ import (
26
26
"time"
27
27
28
28
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
29
+ "github.com/stretchr/testify/require"
29
30
appsv1 "k8s.io/api/apps/v1"
30
31
batchv1 "k8s.io/api/batch/v1"
31
32
corev1 "k8s.io/api/core/v1"
@@ -37,10 +38,9 @@ import (
37
38
"sigs.k8s.io/controller-runtime/pkg/client"
38
39
"sigs.k8s.io/controller-runtime/pkg/cluster"
39
40
40
- "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
41
-
42
41
"github.com/kube-logging/logging-operator/e2e/common"
43
42
"github.com/kube-logging/logging-operator/e2e/common/setup"
43
+ "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
44
44
"sigs.k8s.io/e2e-framework/third_party/helm"
45
45
)
46
46
@@ -169,13 +169,31 @@ func TestLoggingMetrics_Monitoring(t *testing.T) {
169
169
mt , err := setupMetricsTester (ctx , c , ns )
170
170
common .RequireNoError (t , err )
171
171
172
- rawOut , err := mt .getMetrics (metricServices [fluentbit ], c , ns )
173
- common .RequireNoError (t , err )
174
- common .RequireNoError (t , mt .validateMetrics (rawOut , fluentbit ))
175
-
176
- rawOut , err = mt .getMetrics (metricServices [syslogNG ], c , ns )
177
- common .RequireNoError (t , err )
178
- common .RequireNoError (t , mt .validateMetrics (rawOut , syslogNG ))
172
+ require .Eventually (t , func () bool {
173
+ rawOut , err := mt .getMetrics (metricServices [fluentbit ], c , ns )
174
+ if err != nil {
175
+ t .Log (err )
176
+ return false
177
+ }
178
+ if err := mt .validateMetrics (rawOut , fluentbit ); err != nil {
179
+ t .Log (err )
180
+ return false
181
+ }
182
+ return true
183
+ }, pollTimeout , pollInterval )
184
+
185
+ require .Eventually (t , func () bool {
186
+ rawOut , err := mt .getMetrics (metricServices [syslogNG ], c , ns )
187
+ if err != nil {
188
+ t .Log (err )
189
+ return false
190
+ }
191
+ if err := mt .validateMetrics (rawOut , syslogNG ); err != nil {
192
+ t .Log (err )
193
+ return false
194
+ }
195
+ return true
196
+ }, pollTimeout , pollInterval )
179
197
180
198
common .RequireNoError (t , c .GetClient ().Delete (ctx , & logging ))
181
199
@@ -228,9 +246,18 @@ func TestLoggingMetrics_Monitoring(t *testing.T) {
228
246
serviceMonitorsFluentd := & v1.ServiceMonitorList {}
229
247
common .RequireNoError (t , c .GetClient ().List (ctx , serviceMonitorsFluentd ))
230
248
231
- rawOut , err = mt .getMetrics (metricServices [fluentd ], c , ns )
232
- common .RequireNoError (t , err )
233
- common .RequireNoError (t , mt .validateMetrics (rawOut , fluentd ))
249
+ require .Eventually (t , func () bool {
250
+ rawOut , err := mt .getMetrics (metricServices [fluentd ], c , ns )
251
+ if err != nil {
252
+ t .Log (err )
253
+ return false
254
+ }
255
+ if err := mt .validateMetrics (rawOut , fluentd ); err != nil {
256
+ t .Log (err )
257
+ return false
258
+ }
259
+ return true
260
+ }, pollTimeout , pollInterval )
234
261
235
262
serviceMonitors := append (serviceMonitorsFluentd .Items , serviceMonitorsSyslogNG .Items ... )
236
263
common .RequireNoError (t , checkServiceMonitorAvailability (serviceMonitors ))
@@ -382,10 +409,8 @@ func (mt *metricsTester) getMetrics(endpoint metricsEndpoint, c common.Cluster,
382
409
}
383
410
384
411
func (mt * metricsTester ) validateMetrics (rawOut []byte , subject loggingResourceName ) error {
385
- metrics := getKeyMetricsFor (subject )
386
412
var missingMetrics []string
387
-
388
- for _ , metric := range metrics {
413
+ for _ , metric := range getKeyMetricsFor (subject ) {
389
414
if ! strings .Contains (string (rawOut ), metric ) {
390
415
missingMetrics = append (missingMetrics , metric )
391
416
}
0 commit comments