Skip to content

Commit ed72d89

Browse files
authored
feat: upgrade the script to installer v12 (#21)
1 parent a4e540e commit ed72d89

File tree

4 files changed

+237
-8
lines changed

4 files changed

+237
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ replay_pid*
2525

2626
# Intellij
2727
.idea
28+
29+
# macOS Finder metadata
30+
.DS_Store

.gitlab-ci.yml

Lines changed: 206 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,213 @@ default:
55
stages:
66
- test
77

8-
test_script:
8+
test_java_script:
99
image: adoptopenjdk/openjdk11:latest
1010
stage: test
1111
cache: []
1212
script:
13-
- LANGUAGES="java" SERVICE="my-service" API_KEY="dummy" JAVA_INSTRUMENTED_BUILD_SYSTEM="all" source <(cat script.sh)
14-
- export LOG_FILE=java-output.log
15-
- export TRACER_INIT_LOG="CI Visibility settings"
16-
- java -version 2>&1 | tee $LOG_FILE
17-
- 'grep -q "$TRACER_INIT_LOG" $LOG_FILE || { echo "Error: Output does not contain tracer initialisation log: $TRACER_INIT_LOG"; exit 1; }'
13+
- |
14+
bash <<'BASH'
15+
set -euo pipefail
16+
LANGUAGES="java" SERVICE="my-service" API_KEY="dummy" JAVA_INSTRUMENTED_BUILD_SYSTEM="all" source <(cat script.sh)
17+
export LOG_FILE="java-output.log"
18+
export TRACER_INIT_LOG="CI Visibility settings"
19+
java -version 2>&1 | tee "$LOG_FILE"
20+
grep -q "$TRACER_INIT_LOG" "$LOG_FILE" || { echo "Error: Output does not contain tracer initialisation log: $TRACER_INIT_LOG"; exit 1; }
21+
BASH
22+
23+
.go_smoke_test:
24+
stage: test
25+
cache: []
26+
before_script:
27+
- |
28+
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
29+
apt-get update
30+
apt-get install -y curl
31+
fi
32+
go version
33+
script:
34+
- |
35+
bash <<'BASH'
36+
set -euo pipefail
37+
38+
fail() {
39+
echo "Error: $1" >&2
40+
exit 1
41+
}
42+
43+
# Create a minimal Go module in the requested directory so the wrapper can
44+
# exercise the live installer against representative repository layouts.
45+
create_go_module() {
46+
local module_dir="$1"
47+
local module_name="$2"
48+
local module_go="$3"
49+
50+
mkdir -p "$module_dir"
51+
printf 'module %s\n\ngo %s\n' "${module_name}" "${module_go}" > "${module_dir}/go.mod"
52+
printf '%s\n' \
53+
'package smoke' \
54+
'' \
55+
'import "testing"' \
56+
'' \
57+
'func TestSmoke(t *testing.T) {}' > "${module_dir}/smoke_test.go"
58+
}
59+
60+
case "${PROJECT_LAYOUT}" in
61+
root)
62+
create_go_module "." "example.com/test-optimization-gitlab-script-smoke" "${PROJECT_GO}"
63+
;;
64+
single_nested)
65+
create_go_module "services/payments" "example.com/test-optimization-gitlab-script-smoke/payments" "${PROJECT_GO}"
66+
;;
67+
multiple_modules)
68+
create_go_module "services/payments" "example.com/test-optimization-gitlab-script-smoke/payments" "${PROJECT_GO}"
69+
create_go_module "services/refunds" "example.com/test-optimization-gitlab-script-smoke/refunds" "${SECOND_PROJECT_GO}"
70+
;;
71+
*)
72+
fail "Unsupported PROJECT_LAYOUT: ${PROJECT_LAYOUT}"
73+
;;
74+
esac
75+
76+
stdout_file="instrumentation.stdout"
77+
stderr_file="instrumentation.stderr"
78+
79+
set +e
80+
if [ -n "${GO_MODULE_DIR:-}" ]; then
81+
LANGUAGES="go" SERVICE="my-service" API_KEY="dummy" GO_MODULE_DIR="${GO_MODULE_DIR}" source <(cat script.sh) >"${stdout_file}" 2>"${stderr_file}"
82+
else
83+
LANGUAGES="go" SERVICE="my-service" API_KEY="dummy" source <(cat script.sh) >"${stdout_file}" 2>"${stderr_file}"
84+
fi
85+
action_exit=$?
86+
set -e
87+
88+
cat "${stdout_file}"
89+
if [ -s "${stderr_file}" ]; then
90+
cat "${stderr_file}" >&2
91+
fi
92+
93+
if [ "${EXPECT_ACTION_FAILURE}" = "true" ]; then
94+
[ "${action_exit}" -ne 0 ] || fail "Expected the wrapper to fail."
95+
grep -Fq "${EXPECTED_FAILURE_MESSAGE}" "${stderr_file}" || fail "Missing expected failure message: ${EXPECTED_FAILURE_MESSAGE}"
96+
exit 0
97+
fi
98+
99+
[ "${action_exit}" -eq 0 ] || fail "Expected the wrapper to succeed."
100+
101+
if [ -n "${EXPECTED_SKIP_MESSAGE:-}" ]; then
102+
[ -z "${GOFLAGS:-}" ] || fail "GOFLAGS should stay unset when Go instrumentation is skipped."
103+
[ -z "${DD_TRACER_VERSION_GO:-}" ] || fail "DD_TRACER_VERSION_GO should stay unset when Go instrumentation is skipped."
104+
grep -Fq "${EXPECTED_SKIP_MESSAGE}" "${stderr_file}" || fail "Missing expected skip message: ${EXPECTED_SKIP_MESSAGE}"
105+
exit 0
106+
fi
107+
108+
[ -n "${GOFLAGS:-}" ] || fail "GOFLAGS was not set."
109+
[ -n "${DD_TRACER_VERSION_GO:-}" ] || fail "DD_TRACER_VERSION_GO was not set."
110+
echo "${GOFLAGS}" | grep -Fq "orchestrion toolexec" || fail "GOFLAGS does not include orchestrion."
111+
[ -f "${TEST_WORKDIR}/orchestrion.tool.go" ] || fail "orchestrion.tool.go was not created in ${TEST_WORKDIR}."
112+
113+
if [ "${RUN_GO_TESTS}" = "true" ]; then
114+
(
115+
cd "${TEST_WORKDIR}"
116+
DD_TRACE_DEBUG="true" go test -v ./...
117+
)
118+
fi
119+
BASH
120+
121+
test_go_root_go124_success:
122+
extends: .go_smoke_test
123+
image: golang:1.26.1
124+
variables:
125+
PROJECT_LAYOUT: root
126+
PROJECT_GO: "1.24.0"
127+
RUN_GO_TESTS: "true"
128+
TEST_WORKDIR: "."
129+
EXPECT_ACTION_FAILURE: "false"
130+
131+
test_go_root_go125_success:
132+
extends: .go_smoke_test
133+
image: golang:1.26.1
134+
variables:
135+
PROJECT_LAYOUT: root
136+
PROJECT_GO: "1.25.0"
137+
RUN_GO_TESTS: "true"
138+
TEST_WORKDIR: "."
139+
EXPECT_ACTION_FAILURE: "false"
140+
141+
test_go_root_go122_skip:
142+
extends: .go_smoke_test
143+
image: golang:1.26.1
144+
variables:
145+
PROJECT_LAYOUT: root
146+
PROJECT_GO: "1.22.0"
147+
RUN_GO_TESTS: "false"
148+
TEST_WORKDIR: "."
149+
EXPECT_ACTION_FAILURE: "false"
150+
EXPECTED_SKIP_MESSAGE: "The project Go version (1.22.0) is lower than the minimum Go version required by dd-trace-go"
151+
152+
test_go_runner_below_minimum_skip:
153+
extends: .go_smoke_test
154+
image: golang:1.23.12
155+
variables:
156+
PROJECT_LAYOUT: root
157+
PROJECT_GO: "1.24.0"
158+
RUN_GO_TESTS: "false"
159+
TEST_WORKDIR: "."
160+
EXPECT_ACTION_FAILURE: "false"
161+
EXPECTED_SKIP_MESSAGE: "The installed Go version (1.23.12) is lower than the minimum Go version required by dd-trace-go"
162+
163+
test_go_single_nested_go124_auto_detect:
164+
extends: .go_smoke_test
165+
image: golang:1.26.1
166+
variables:
167+
PROJECT_LAYOUT: single_nested
168+
PROJECT_GO: "1.24.0"
169+
RUN_GO_TESTS: "true"
170+
TEST_WORKDIR: "services/payments"
171+
EXPECT_ACTION_FAILURE: "false"
172+
173+
test_go_single_nested_go125_auto_detect:
174+
extends: .go_smoke_test
175+
image: golang:1.26.1
176+
variables:
177+
PROJECT_LAYOUT: single_nested
178+
PROJECT_GO: "1.25.0"
179+
RUN_GO_TESTS: "true"
180+
TEST_WORKDIR: "services/payments"
181+
EXPECT_ACTION_FAILURE: "false"
182+
183+
test_go_multiple_modules_without_override_skip:
184+
extends: .go_smoke_test
185+
image: golang:1.26.1
186+
variables:
187+
PROJECT_LAYOUT: multiple_modules
188+
PROJECT_GO: "1.24.0"
189+
SECOND_PROJECT_GO: "1.25.0"
190+
RUN_GO_TESTS: "false"
191+
TEST_WORKDIR: "."
192+
EXPECT_ACTION_FAILURE: "false"
193+
EXPECTED_SKIP_MESSAGE: "Set DD_CIVISIBILITY_GO_MODULE_DIR to the Go module root if this repository contains multiple Go modules."
194+
195+
test_go_multiple_modules_with_override_success:
196+
extends: .go_smoke_test
197+
image: golang:1.26.1
198+
variables:
199+
PROJECT_LAYOUT: multiple_modules
200+
PROJECT_GO: "1.25.0"
201+
SECOND_PROJECT_GO: "1.24.0"
202+
GO_MODULE_DIR: "./services/payments"
203+
RUN_GO_TESTS: "true"
204+
TEST_WORKDIR: "services/payments"
205+
EXPECT_ACTION_FAILURE: "false"
206+
207+
test_go_missing_override_directory_skip:
208+
extends: .go_smoke_test
209+
image: golang:1.26.1
210+
variables:
211+
PROJECT_LAYOUT: root
212+
PROJECT_GO: "1.24.0"
213+
GO_MODULE_DIR: "./services/does-not-exist"
214+
RUN_GO_TESTS: "false"
215+
TEST_WORKDIR: "."
216+
EXPECT_ACTION_FAILURE: "false"
217+
EXPECTED_SKIP_MESSAGE: "Error: DD_CIVISIBILITY_GO_MODULE_DIR points to a directory that does not exist: ./services/does-not-exist"

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The script takes in the following environment variables:
4141
| PYTHON_TRACER_VERSION | The version of Datadog Python tracer to use. Defaults to the latest release. | false | |
4242
| RUBY_TRACER_VERSION | The version of datadog-ci gem to use. Defaults to the latest release. | false | |
4343
| GO_TRACER_VERSION | The version of Orchestrion automatic compile-time instrumentation of Go code (https://github.com/datadog/orchestrion) to use. Defaults to the latest release. | false | |
44+
| GO_MODULE_DIR | Path to the Go module root directory to instrument. Use this when the repository contains multiple Go modules or the Go module is not in the repository root. | false | |
4445
| JAVA_INSTRUMENTED_BUILD_SYSTEM | If provided, only the specified build systems will be instrumented (allowed values are `gradle`,`maven`,`sbt`,`ant`,`all`). `all` is a special value that instruments every Java process. If this property is not provided, all known build systems will be instrumented (Gradle, Maven, SBT, Ant). | false | |
4546

4647
### Additional configuration
@@ -63,6 +64,24 @@ test_node:
6364
- npm run test
6465
```
6566

67+
### Go multi-module repositories
68+
69+
If your repository contains multiple Go modules, or the Go module you want to instrument is not at the repository root, set `GO_MODULE_DIR` to the module root directory that contains the target `go.mod` file:
70+
71+
```yaml
72+
test_go:
73+
image: golang:1.25.0
74+
script:
75+
- |
76+
LANGUAGES="go" SITE="datadoghq.com" API_KEY="YOUR_API_KEY_SECRET" GO_MODULE_DIR="./services/payments" \
77+
SRC=$(curl -fsSL https://github.com/DataDog/test-optimization-gitlab-script/releases/download/v1.2.6/script.sh); \
78+
echo "$SRC" | sha256sum | grep -q '^5df7aea8a13e259c66109ecf7f88fef8ffe22369abc7425bf435b4bbfefb0376' && \
79+
source <(echo "$SRC") || \
80+
echo "ERROR: SHA256 mismatch. Datadog Test Optimization autoinstrumentation not enabled." >&2
81+
- cd services/payments
82+
- go test ./...
83+
```
84+
6685
## Limitations
6786

6887
### Tracing vitest tests

script.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,22 @@ if [ -n "$GO_TRACER_VERSION" ]; then
6363
export DD_SET_TRACER_VERSION_GO=${GO_TRACER_VERSION}
6464
fi
6565

66+
# $GO_MODULE_DIR or $DD_CIVISIBILITY_GO_MODULE_DIR are optional
67+
if [ -n "$GO_MODULE_DIR" ]; then
68+
export DD_CIVISIBILITY_GO_MODULE_DIR=${GO_MODULE_DIR}
69+
fi
70+
6671
# $JAVA_INSTRUMENTED_BUILD_SYSTEM or $DD_INSTRUMENTATION_BUILD_SYSTEM_JAVA are optional
6772
if [ -n "$JAVA_INSTRUMENTED_BUILD_SYSTEM" ]; then
6873
export DD_INSTRUMENTATION_BUILD_SYSTEM_JAVA=${JAVA_INSTRUMENTED_BUILD_SYSTEM}
6974
fi
7075

7176
export DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER="gitlab"
7277

73-
installation_script_url="https://install.datadoghq.com/scripts/install_test_visibility_v11.sh"
74-
installation_script_checksum="fc64c45fd4b45b4b01773c58a3a116bef212dc4095508a6e27e19e50e901bd55"
78+
# Keep the installer URL and checksum pinned together so the wrapper executes a
79+
# deterministic upstream payload.
80+
installation_script_url="https://install.datadoghq.com/scripts/install_test_visibility_v12.sh"
81+
installation_script_checksum="91b6c7bb2c28ef5604c2a2b233da7d931a9b3b5d20b7872254ebb0e689e62f4a"
7582
script_filepath="install_test_visibility.sh"
7683

7784
if command -v curl >/dev/null 2>&1; then

0 commit comments

Comments
 (0)