Skip to content

Commit 3361af5

Browse files
authored
Wait for Tekton metrics in E2E Test (#24163)
* Wait for Tekton trigger metrics in E2E * Add type hints to Tekton metric wait helper
1 parent fe620f8 commit 3361af5

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tekton/tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import os
55
from contextlib import ExitStack
6+
from urllib.request import urlopen
67

78
import pytest
89

910
from datadog_checks.dev import get_here, run_command
11+
from datadog_checks.dev.conditions import WaitFor
1012
from datadog_checks.dev.kind import kind_run
1113
from datadog_checks.dev.kube_port_forward import port_forward
1214

@@ -21,6 +23,15 @@ def _wait_for_resource(*, kind, name, condition, namespace=None, timeout="300s")
2123
run_command(command)
2224

2325

26+
def wait_for_metric_families(endpoint: str, families: list[str]) -> None:
27+
with urlopen(endpoint, timeout=5) as response:
28+
metrics = response.read().decode("utf-8")
29+
30+
missing = [family for family in families if family not in metrics]
31+
if missing:
32+
raise AssertionError("Tekton metric families are not available yet: {}".format(", ".join(missing)))
33+
34+
2435
def setup_tekton():
2536
run_command(["kubectl", "create", "namespace", "tekton-operator"])
2637
run_command(["kubectl", "apply", "-f", os.path.join(HERE, "kind", "tekton-operator.yaml"), "-n", "tekton-operator"])
@@ -77,6 +88,22 @@ def dd_environment():
7788
)
7889
instances['triggers_controller_endpoint'] = f'http://{trigger_host}:{trigger_port}/metrics'
7990

91+
WaitFor(
92+
wait_for_metric_families,
93+
attempts=60,
94+
wait=2,
95+
args=(
96+
instances['triggers_controller_endpoint'],
97+
[
98+
'controller_clusterinterceptor_count',
99+
'controller_clustertriggerbinding_count',
100+
'controller_eventlistener_count',
101+
'controller_triggerbinding_count',
102+
'controller_triggertemplate_count',
103+
],
104+
),
105+
)()
106+
80107
yield {'instances': [instances]}
81108

82109

0 commit comments

Comments
 (0)