Skip to content

Commit 0855f79

Browse files
committed
fix(e2e): relax metric-tester; don't fail on first try
Signed-off-by: Bence Csati <[email protected]>
1 parent 27ac495 commit 0855f79

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

e2e/logging_metrics_monitoring/logging_metrics_monitoring_test.go

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"time"
2727

2828
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
29+
"github.com/stretchr/testify/require"
2930
appsv1 "k8s.io/api/apps/v1"
3031
batchv1 "k8s.io/api/batch/v1"
3132
corev1 "k8s.io/api/core/v1"
@@ -37,10 +38,9 @@ import (
3738
"sigs.k8s.io/controller-runtime/pkg/client"
3839
"sigs.k8s.io/controller-runtime/pkg/cluster"
3940

40-
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
41-
4241
"github.com/kube-logging/logging-operator/e2e/common"
4342
"github.com/kube-logging/logging-operator/e2e/common/setup"
43+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
4444
"sigs.k8s.io/e2e-framework/third_party/helm"
4545
)
4646

@@ -169,13 +169,31 @@ func TestLoggingMetrics_Monitoring(t *testing.T) {
169169
mt, err := setupMetricsTester(ctx, c, ns)
170170
common.RequireNoError(t, err)
171171

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)
179197

180198
common.RequireNoError(t, c.GetClient().Delete(ctx, &logging))
181199

@@ -228,9 +246,18 @@ func TestLoggingMetrics_Monitoring(t *testing.T) {
228246
serviceMonitorsFluentd := &v1.ServiceMonitorList{}
229247
common.RequireNoError(t, c.GetClient().List(ctx, serviceMonitorsFluentd))
230248

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)
234261

235262
serviceMonitors := append(serviceMonitorsFluentd.Items, serviceMonitorsSyslogNG.Items...)
236263
common.RequireNoError(t, checkServiceMonitorAvailability(serviceMonitors))
@@ -382,10 +409,8 @@ func (mt *metricsTester) getMetrics(endpoint metricsEndpoint, c common.Cluster,
382409
}
383410

384411
func (mt *metricsTester) validateMetrics(rawOut []byte, subject loggingResourceName) error {
385-
metrics := getKeyMetricsFor(subject)
386412
var missingMetrics []string
387-
388-
for _, metric := range metrics {
413+
for _, metric := range getKeyMetricsFor(subject) {
389414
if !strings.Contains(string(rawOut), metric) {
390415
missingMetrics = append(missingMetrics, metric)
391416
}

0 commit comments

Comments
 (0)