From b7383882501637956482b60e1e112963664e74a8 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria <47357713+amenasria@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:13:58 +0200 Subject: [PATCH] [CI] Add the integration tests to Gitlab CI (#29489) --- .gitlab/integration_test/linux.yml | 25 +++++++++++++++++++++++++ tasks/agent.py | 19 +++++++++---------- tasks/cluster_agent.py | 9 +++------ tasks/cluster_agent_cloudfoundry.py | 2 +- tasks/dogstatsd.py | 9 +++------ tasks/gotest.py | 10 +++++----- tasks/trace_agent.py | 9 +++------ 7 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 .gitlab/integration_test/linux.yml diff --git a/.gitlab/integration_test/linux.yml b/.gitlab/integration_test/linux.yml new file mode 100644 index 0000000000000..bddbc387e2cd3 --- /dev/null +++ b/.gitlab/integration_test/linux.yml @@ -0,0 +1,25 @@ +.integration_tests_deb: + stage: integration_test + needs: ["go_deps", "go_tools_deps"] + image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/deb_x64$DATADOG_AGENT_BUILDIMAGES_SUFFIX:$DATADOG_AGENT_BUILDIMAGES + tags: ["docker-in-docker:amd64"] + before_script: + - !reference [.retrieve_linux_go_deps] + - !reference [.retrieve_linux_go_tools_deps] + +agent_integration_tests: + extends: .integration_tests_deb + # We have capacity issues on the docker-in-docker:amd64 runners for now. + # Setting allow_failure to true to avoid blocking the pipelines. + # Setting the timeout to 30 min and retry to 2 to avoid the job from pending for too long. + allow_failure: true + timeout: 30m + retry: 2 + script: + - inv -e integration-tests --race --remote-docker + +docker_integration_tests: + extends: .integration_tests_deb + script: + - inv -e docker.test + - inv -e docker.integration-tests diff --git a/tasks/agent.py b/tasks/agent.py index bf9ac70380e54..deda06d0d1945 100644 --- a/tasks/agent.py +++ b/tasks/agent.py @@ -17,7 +17,6 @@ from tasks.build_tags import filter_incompatible_tags, get_build_tags, get_default_build_tags from tasks.devcontainer import run_on_devcontainer from tasks.flavor import AgentFlavor -from tasks.go import deps from tasks.libs.common.utils import ( REPO_PATH, bin_name, @@ -593,29 +592,28 @@ def hacky_dev_image_build( @task -def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, go_mod="mod"): +def integration_tests(ctx, race=False, remote_docker=False, go_mod="mod", timeout=""): """ Run integration tests for the Agent """ - if install_deps: - deps(ctx) if sys.platform == 'win32': - return _windows_integration_tests(ctx, race=race, go_mod=go_mod) + return _windows_integration_tests(ctx, race=race, go_mod=go_mod, timeout=timeout) else: # TODO: See if these will function on Windows - return _linux_integration_tests(ctx, race=race, remote_docker=remote_docker, go_mod=go_mod) + return _linux_integration_tests(ctx, race=race, remote_docker=remote_docker, go_mod=go_mod, timeout=timeout) -def _windows_integration_tests(ctx, race=False, go_mod="mod"): +def _windows_integration_tests(ctx, race=False, go_mod="mod", timeout=""): test_args = { "go_mod": go_mod, "go_build_tags": " ".join(get_default_build_tags(build="test")), "race_opt": "-race" if race else "", "exec_opts": "", + "timeout_opt": f"-timeout {timeout}" if timeout else "", } - go_cmd = 'go test -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}'.format(**test_args) # noqa: FS002 + go_cmd = 'go test {timeout_opt} -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}'.format(**test_args) # noqa: FS002 tests = [ { @@ -644,12 +642,13 @@ def _windows_integration_tests(ctx, race=False, go_mod="mod"): ctx.run(f"{go_cmd} {test['prefix']} {test['extra_args']}") -def _linux_integration_tests(ctx, race=False, remote_docker=False, go_mod="mod"): +def _linux_integration_tests(ctx, race=False, remote_docker=False, go_mod="mod", timeout=""): test_args = { "go_mod": go_mod, "go_build_tags": " ".join(get_default_build_tags(build="test")), "race_opt": "-race" if race else "", "exec_opts": "", + "timeout_opt": f"-timeout {timeout}" if timeout else "", } # since Go 1.13, the -exec flag of go test could add some parameters such as -test.timeout @@ -659,7 +658,7 @@ def _linux_integration_tests(ctx, race=False, remote_docker=False, go_mod="mod") if remote_docker: test_args["exec_opts"] = f"-exec \"{os.getcwd()}/test/integration/dockerize_tests.sh\"" - go_cmd = 'go test -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}'.format(**test_args) # noqa: FS002 + go_cmd = 'go test {timeout_opt} -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}'.format(**test_args) # noqa: FS002 prefixes = [ "./test/integration/config_providers/...", diff --git a/tasks/cluster_agent.py b/tasks/cluster_agent.py index 7b59e0a2746f5..8b270d3209b1d 100644 --- a/tasks/cluster_agent.py +++ b/tasks/cluster_agent.py @@ -15,7 +15,6 @@ from tasks.build_tags import get_build_tags, get_default_build_tags from tasks.cluster_agent_helpers import build_common, clean_common, refresh_assets_common, version_common from tasks.cws_instrumentation import BIN_PATH as CWS_INSTRUMENTATION_BIN_PATH -from tasks.go import deps from tasks.libs.releasing.version import load_release_versions # constants @@ -88,22 +87,20 @@ def clean(ctx): @task -def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, go_mod="mod"): +def integration_tests(ctx, race=False, remote_docker=False, go_mod="mod", timeout=""): """ Run integration tests for cluster-agent """ if sys.platform == 'win32': raise Exit(message='cluster-agent integration tests are not supported on Windows', code=0) - if install_deps: - deps(ctx) - # We need docker for the kubeapiserver integration tests tags = get_default_build_tags(build="cluster-agent") + ["docker", "test"] go_build_tags = " ".join(get_build_tags(tags, [])) race_opt = "-race" if race else "" exec_opts = "" + timeout_opt = f"-timeout {timeout}" if timeout else "" # since Go 1.13, the -exec flag of go test could add some parameters such as -test.timeout # to the call, we don't want them because while calling invoke below, invoke @@ -112,7 +109,7 @@ def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, if remote_docker: exec_opts = f"-exec \"{os.getcwd()}/test/integration/dockerize_tests.sh\"" - go_cmd = f'go test -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}' + go_cmd = f'go test {timeout_opt} -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}' prefixes = [ "./test/integration/util/kube_apiserver", diff --git a/tasks/cluster_agent_cloudfoundry.py b/tasks/cluster_agent_cloudfoundry.py index 317577a86ed4c..e262b91c35880 100644 --- a/tasks/cluster_agent_cloudfoundry.py +++ b/tasks/cluster_agent_cloudfoundry.py @@ -44,7 +44,7 @@ def refresh_assets(ctx, development=True): @task -def integration_tests(ctx, install_deps=False, race=False, remote_docker=False): # noqa: U100 +def integration_tests(ctx, race=False, remote_docker=False): # noqa: U100 """ Run integration tests for cluster-agent-cloudfoundry """ diff --git a/tasks/dogstatsd.py b/tasks/dogstatsd.py index 6373af271bf0b..c40aeebbd315b 100644 --- a/tasks/dogstatsd.py +++ b/tasks/dogstatsd.py @@ -11,7 +11,6 @@ from tasks.build_tags import filter_incompatible_tags, get_build_tags, get_default_build_tags from tasks.flavor import AgentFlavor -from tasks.go import deps from tasks.libs.common.utils import REPO_PATH, bin_name, get_build_flags, get_root from tasks.windows_resources import build_messagetable, build_rc, versioninfo_vars @@ -171,19 +170,17 @@ def size_test(ctx, skip_build=False): @task -def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, go_mod="mod"): +def integration_tests(ctx, race=False, remote_docker=False, go_mod="mod", timeout=""): """ Run integration tests for dogstatsd """ if sys.platform == 'win32': raise Exit(message='dogstatsd integration tests are not supported on Windows', code=0) - if install_deps: - deps(ctx) - go_build_tags = " ".join(get_default_build_tags(build="test")) race_opt = "-race" if race else "" exec_opts = "" + timeout_opt = f"-timeout {timeout}" if timeout else "" # since Go 1.13, the -exec flag of go test could add some parameters such as -test.timeout # to the call, we don't want them because while calling invoke below, invoke @@ -192,7 +189,7 @@ def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, if remote_docker: exec_opts = f"-exec \"{os.getcwd()}/test/integration/dockerize_tests.sh\"" - go_cmd = f'go test -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}' + go_cmd = f'go test {timeout_opt} -mod={go_mod} {race_opt} -tags "{go_build_tags}" {exec_opts}' prefixes = [ "./test/integration/dogstatsd/...", diff --git a/tasks/gotest.py b/tasks/gotest.py index 54015e3f7c35b..cf0a5efd540b7 100644 --- a/tasks/gotest.py +++ b/tasks/gotest.py @@ -395,15 +395,15 @@ def test( @task -def integration_tests(ctx, install_deps=False, race=False, remote_docker=False, debug=False): +def integration_tests(ctx, race=False, remote_docker=False, debug=False, timeout=""): """ Run all the available integration tests """ tests = [ - lambda: agent_integration_tests(ctx, install_deps, race, remote_docker), - lambda: dsd_integration_tests(ctx, install_deps, race, remote_docker), - lambda: dca_integration_tests(ctx, install_deps, race, remote_docker), - lambda: trace_integration_tests(ctx, install_deps, race), + lambda: agent_integration_tests(ctx, race=race, remote_docker=remote_docker, timeout=timeout), + lambda: dsd_integration_tests(ctx, race=race, remote_docker=remote_docker, timeout=timeout), + lambda: dca_integration_tests(ctx, race=race, remote_docker=remote_docker, timeout=timeout), + lambda: trace_integration_tests(ctx, race=race, timeout=timeout), ] for t in tests: try: diff --git a/tasks/trace_agent.py b/tasks/trace_agent.py index 658b2bae3909b..65a1f8b7e3fb6 100644 --- a/tasks/trace_agent.py +++ b/tasks/trace_agent.py @@ -6,7 +6,6 @@ from tasks.agent import build as agent_build from tasks.build_tags import filter_incompatible_tags, get_build_tags, get_default_build_tags from tasks.flavor import AgentFlavor -from tasks.go import deps from tasks.libs.common.utils import REPO_PATH, bin_name, get_build_flags from tasks.windows_resources import build_messagetable, build_rc, versioninfo_vars @@ -92,20 +91,18 @@ def build( @task -def integration_tests(ctx, install_deps=False, race=False, go_mod="mod"): +def integration_tests(ctx, race=False, go_mod="mod", timeout="10m"): """ Run integration tests for trace agent """ if sys.platform == 'win32': raise Exit(message='trace-agent integration tests are not supported on Windows', code=0) - if install_deps: - deps(ctx) - go_build_tags = " ".join(get_default_build_tags(build="test")) race_opt = "-race" if race else "" + timeout_opt = f"-timeout {timeout}" if timeout else "" - go_cmd = f'go test -mod={go_mod} {race_opt} -v -tags "{go_build_tags}"' + go_cmd = f'go test {timeout_opt} -mod={go_mod} {race_opt} -v -tags "{go_build_tags}"' ctx.run(f"{go_cmd} ./cmd/trace-agent/test/testsuite/...", env={"INTEGRATION": "yes"})