Skip to content

Commit a86cca4

Browse files
committed
Improve error reporting of KCM metrics
Show what is a test waiting for and make sure the metric name + label appears in the timeout error.
1 parent eeabc3a commit a86cca4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

test/e2e/storage/csimock/csi_selinux_mount.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ import (
7272
//
7373
// All other feature gate combinations should be invalid.
7474

75+
const (
76+
controllerSELinuxMetricName = "selinux_warning_controller_selinux_volume_conflict"
77+
)
78+
7579
var (
7680
defaultSELinuxLabels = map[string]struct{ defaultProcessLabel, defaultFileLabel string }{
7781
"debian": {"svirt_lxc_net_t", "svirt_lxc_file_t"},
@@ -713,13 +717,13 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics and SELinuxWarningC
713717
// We don't need to compare the initial and final KCM metrics,
714718
// KCM metrics report exact pod namespaces+names as labels and the metric value is always "1".
715719
err = waitForControllerMetric(ctx, grabber, f.Namespace.Name, pod.Name, pod2.Name, t.expectControllerConflictProperty, framework.PodStartShortTimeout)
716-
framework.ExpectNoError(err, "failed to get metrics from KCM")
720+
framework.ExpectNoError(err, "while waiting for metrics from KCM")
717721
// Check the controler generated a conflict event on the first pod
718722
err = waitForConflictEvent(ctx, m.cs, pod, pod2, t.expectControllerConflictProperty, f.Timeouts.PodStart)
719-
framework.ExpectNoError(err, "failed to receive event on the first pod")
723+
framework.ExpectNoError(err, "while waiting for an event on the first pod")
720724
// Check the controler generated event on the second pod
721725
err = waitForConflictEvent(ctx, m.cs, pod2, pod, t.expectControllerConflictProperty, f.Timeouts.PodStart)
722-
framework.ExpectNoError(err, "failed to receive event on the second pod")
726+
framework.ExpectNoError(err, "while waiting for an event on the second pod")
723727
}
724728
}
725729
// t.testTags is array and it's not possible to use It("name", func(){xxx}, t.testTags...)
@@ -778,7 +782,7 @@ func grabKCMSELinuxMetrics(ctx context.Context, grabber *e2emetrics.Grabber, nam
778782
for i := range samples {
779783
// E.g. "selinux_warning_controller_selinux_volume_conflict"
780784
metricName := samples[i].Metric[testutil.MetricNameLabel]
781-
if metricName != "selinux_warning_controller_selinux_volume_conflict" {
785+
if metricName != controllerSELinuxMetricName {
782786
continue
783787
}
784788

@@ -836,7 +840,6 @@ func waitForNodeMetricIncrease(ctx context.Context, grabber *e2emetrics.Grabber,
836840
}
837841

838842
func waitForControllerMetric(ctx context.Context, grabber *e2emetrics.Grabber, namespace, pod1Name, pod2Name, propertyName string, timeout time.Duration) error {
839-
var noIncreaseMetrics sets.Set[string]
840843
var metrics map[string]float64
841844

842845
expectLabels := []string{
@@ -846,6 +849,8 @@ func waitForControllerMetric(ctx context.Context, grabber *e2emetrics.Grabber, n
846849
fmt.Sprintf("pod2_namespace=%q", namespace),
847850
fmt.Sprintf("property=%q", propertyName),
848851
}
852+
framework.Logf("Waiting for KCM metric %s{%+v}", controllerSELinuxMetricName, expectLabels)
853+
849854
err := wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, func(ctx context.Context) (bool, error) {
850855
var err error
851856
metrics, err = grabKCMSELinuxMetrics(ctx, grabber, namespace)
@@ -876,8 +881,8 @@ func waitForControllerMetric(ctx context.Context, grabber *e2emetrics.Grabber, n
876881
ginkgo.By("Dumping final KCM metrics")
877882
dumpMetrics(metrics)
878883

879-
if err == context.DeadlineExceeded {
880-
return fmt.Errorf("timed out waiting for KCM metrics %v", noIncreaseMetrics.UnsortedList())
884+
if err != nil {
885+
return fmt.Errorf("error waiting for KCM metrics %s{%+v}: %w", controllerSELinuxMetricName, expectLabels, err)
881886
}
882887
return err
883888
}

0 commit comments

Comments
 (0)