Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tekton/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
from contextlib import ExitStack
from urllib.request import urlopen

import pytest

from datadog_checks.dev import get_here, run_command
from datadog_checks.dev.conditions import WaitFor
from datadog_checks.dev.kind import kind_run
from datadog_checks.dev.kube_port_forward import port_forward

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


def wait_for_metric_families(endpoint: str, families: list[str]) -> None:
with urlopen(endpoint, timeout=5) as response:
metrics = response.read().decode("utf-8")

missing = [family for family in families if family not in metrics]
if missing:
raise AssertionError("Tekton metric families are not available yet: {}".format(", ".join(missing)))


def setup_tekton():
run_command(["kubectl", "create", "namespace", "tekton-operator"])
run_command(["kubectl", "apply", "-f", os.path.join(HERE, "kind", "tekton-operator.yaml"), "-n", "tekton-operator"])
Expand Down Expand Up @@ -77,6 +88,22 @@ def dd_environment():
)
instances['triggers_controller_endpoint'] = f'http://{trigger_host}:{trigger_port}/metrics'

WaitFor(
wait_for_metric_families,
attempts=60,
wait=2,
args=(
instances['triggers_controller_endpoint'],
[
'controller_clusterinterceptor_count',
'controller_clustertriggerbinding_count',
'controller_eventlistener_count',
'controller_triggerbinding_count',
'controller_triggertemplate_count',
],
),
)()

yield {'instances': [instances]}


Expand Down
Loading