33# Licensed under a 3-clause BSD style license (see LICENSE)
44import os
55from contextlib import ExitStack
6+ from urllib .request import urlopen
67
78import pytest
89
910from datadog_checks .dev import get_here , run_command
11+ from datadog_checks .dev .conditions import WaitFor
1012from datadog_checks .dev .kind import kind_run
1113from 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+
2435def 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