Skip to content

Commit

Permalink
[CI] Add the integration tests to Gitlab CI (#29489)
Browse files Browse the repository at this point in the history
  • Loading branch information
amenasria authored Oct 3, 2024
1 parent b0d7782 commit b738388
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
25 changes: 25 additions & 0 deletions .gitlab/integration_test/linux.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 9 additions & 10 deletions tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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
Expand All @@ -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/...",
Expand Down
9 changes: 3 additions & 6 deletions tasks/cluster_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tasks/cluster_agent_cloudfoundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
9 changes: 3 additions & 6 deletions tasks/dogstatsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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/...",
Expand Down
10 changes: 5 additions & 5 deletions tasks/gotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions tasks/trace_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"})


Expand Down

0 comments on commit b738388

Please sign in to comment.