Skip to content

Commit

Permalink
test: Fix flakiness in metrics e2e tests (#1543)
Browse files Browse the repository at this point in the history
Co-authored-by: Korbinian Stoemmer <[email protected]>
  • Loading branch information
shorim and k15r authored Oct 23, 2024
1 parent 2895ffd commit c0c174d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
9 changes: 7 additions & 2 deletions test/e2e/metrics_runtime_input_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelMetrics), Label(suite.LabelSetA),
g.Expect(resp).To(HaveHTTPBody(
HaveFlatMetrics(ContainElement(HaveResourceAttributes(HaveKeys(ConsistOf(runtime.PodMetricsResourceAttributes))))),
))
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
}, 3*periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
})

It("Should have expected metric attributes in runtime pod metrics", func() {
Expand Down Expand Up @@ -404,6 +404,11 @@ var _ = Describe(suite.ID(), Label(suite.LabelMetrics), Label(suite.LabelSetA),
assert.ServiceReady(ctx, k8sClient, types.NamespacedName{Name: backendOnlyVolumeMetricsEnabledName, Namespace: mockNs})
})

It("Should have pods mounting volumes running", func() {
assert.PodReady(ctx, k8sClient, types.NamespacedName{Name: podMountingPVCName, Namespace: mockNs})
assert.PodReady(ctx, k8sClient, types.NamespacedName{Name: podMountingEmptyDirName, Namespace: mockNs})
})

Context("Runtime volume metrics", func() {
It("Should deliver ONLY runtime volume metrics to volume-metrics backend", func() {
Eventually(func(g Gomega) {
Expand All @@ -414,7 +419,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelMetrics), Label(suite.LabelSetA),
g.Expect(resp).To(HaveHTTPBody(
HaveFlatMetrics(HaveUniqueNamesForRuntimeScope(ConsistOf(runtime.VolumeMetricsNames))),
))
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
}, 2*periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
})

It("Should have expected resource attributes in runtime volume metrics", func() {
Expand Down
15 changes: 6 additions & 9 deletions test/integration/istio/access_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@ var _ = Describe(suite.ID(), Label(suite.LabelIntegration), Ordered, func() {
})

It("Should have sample app running", func() {
Eventually(func(g Gomega) {
listOptions := client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{"app": "sample-metrics"}),
Namespace: sampleAppNs,
}
ready, err := assert.PodsReady(ctx, k8sClient, listOptions)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ready).To(BeTrueBecause("sample app is not ready"))
}, periodic.EventuallyTimeout*2, periodic.DefaultInterval).Should(Succeed())
listOptions := client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{"app": "sample-metrics"}),
Namespace: sampleAppNs,
}

assert.PodsReady(ctx, k8sClient, listOptions)
})

It("Should have the log pipeline running", func() {
Expand Down
15 changes: 5 additions & 10 deletions test/integration/istio/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,12 @@ func verifySidecarPresent(namespace string, labelSelector map[string]string) {
}

func verifyAppIsRunning(namespace string, labelSelector map[string]string) {
Eventually(func(g Gomega) {
listOptions := client.ListOptions{
LabelSelector: labels.SelectorFromSet(labelSelector),
Namespace: namespace,
}

ready, err := assert.PodsReady(ctx, k8sClient, listOptions)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ready).To(BeTrueBecause("Pods not ready"))
listOptions := client.ListOptions{
LabelSelector: labels.SelectorFromSet(labelSelector),
Namespace: namespace,
}

}, periodic.EventuallyTimeout*2, periodic.DefaultInterval).Should(Succeed())
assert.PodsReady(ctx, k8sClient, listOptions)
}

func verifyIstioSpans(backendURL, namespace string) {
Expand Down
2 changes: 1 addition & 1 deletion test/testkit/assert/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func isDaemonSetReady(ctx context.Context, k8sClient client.Client, name types.N
Namespace: name.Namespace,
}

return PodsReady(ctx, k8sClient, listOptions)
return arePodsReady(ctx, k8sClient, listOptions)
}
2 changes: 1 addition & 1 deletion test/testkit/assert/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func isDeploymentReady(ctx context.Context, k8sClient client.Client, name types.
Namespace: name.Namespace,
}

return PodsReady(ctx, k8sClient, listOptions)
return arePodsReady(ctx, k8sClient, listOptions)
}

func DeploymentHasPriorityClass(ctx context.Context, k8sClient client.Client, name types.NamespacedName, expectedPriorityClassName string) {
Expand Down
23 changes: 21 additions & 2 deletions test/testkit/assert/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@ import (
"context"
"fmt"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kyma-project/telemetry-manager/test/testkit/periodic"
)

func PodReady(ctx context.Context, k8sClient client.Client, name types.NamespacedName) (bool, error) {
func PodReady(ctx context.Context, k8sClient client.Client, name types.NamespacedName) {
Eventually(func(g Gomega) {
ready, err := isPodReady(ctx, k8sClient, name)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ready).To(BeTrueBecause("Pod not ready"))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
}

func PodsReady(ctx context.Context, k8sClient client.Client, listOptions client.ListOptions) {
Eventually(func(g Gomega) {
ready, err := arePodsReady(ctx, k8sClient, listOptions)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ready).To(BeTrueBecause("Pods are not ready"))
}, 2*periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
}

func isPodReady(ctx context.Context, k8sClient client.Client, name types.NamespacedName) (bool, error) {
var pod corev1.Pod

err := k8sClient.Get(ctx, name, &pod)
Expand All @@ -26,7 +45,7 @@ func PodReady(ctx context.Context, k8sClient client.Client, name types.Namespace
return true, nil
}

func PodsReady(ctx context.Context, k8sClient client.Client, listOptions client.ListOptions) (bool, error) {
func arePodsReady(ctx context.Context, k8sClient client.Client, listOptions client.ListOptions) (bool, error) {
var pods corev1.PodList

err := k8sClient.List(ctx, &pods, &listOptions)
Expand Down

0 comments on commit c0c174d

Please sign in to comment.