Skip to content

Commit c2fbcf1

Browse files
authored
Merge branch 'master' into mhlidd/backfilling_v2_format
2 parents a005835 + 2a81ef5 commit c2fbcf1

File tree

38 files changed

+662
-347
lines changed

38 files changed

+662
-347
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
issuer: https://token.actions.githubusercontent.com
22

3-
subject_pattern: ^repo:DataDog/dd-trace-java:ref:refs/heads/.+$
3+
subject_pattern: repo:DataDog/dd-trace-java:ref:refs/heads/(master|test/v.+)
44

55
claim_pattern:
6-
event_name: (push|workflow_dispatch)
7-
ref: refs/heads/.+
8-
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/pin-system-tests\.yaml@refs/heads/.+
6+
event_name: (create|workflow_dispatch)
7+
ref: refs/heads/(master|test/v.+)
8+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/pin-system-tests\.yaml@refs/heads/(master|test/v.+)
99

1010
permissions:
1111
contents: write
1212
pull_requests: write
13+
workflows: write
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Pin system tests
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-branch-name:
7+
description: 'The minor release branch name (e.g. release/v1.54.x)'
8+
required: true
9+
type: string
10+
# run workflow when a release branch is created
11+
create:
12+
13+
jobs:
14+
pin-system-tests:
15+
name: "Pin system tests"
16+
# CHANGE BACK TO release/v*
17+
if: github.event_name != 'create' || startsWith(github.ref, 'refs/heads/test/v')
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write # may not be needed
21+
id-token: write # Required for OIDC token federation
22+
steps:
23+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
24+
id: octo-sts
25+
with:
26+
scope: DataDog/dd-trace-java
27+
policy: self.pin-system-tests.create-pr
28+
29+
- name: Define base branch
30+
id: define-base-branch
31+
run: |
32+
if [[ -n "${{ github.event.inputs.release-branch-name }}" ]]; then
33+
BASE_BRANCH=${{ github.event.inputs.release-branch-name }}
34+
else
35+
BASE_BRANCH=${GITHUB_REF#refs/heads/}
36+
fi
37+
echo "base_branch=${BASE_BRANCH}" >> $GITHUB_OUTPUT
38+
39+
- name: Checkout the repository
40+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
41+
with:
42+
ref: ${{ steps.define-base-branch.outputs.base_branch }}
43+
44+
- name: Get latest commit SHA of base branch
45+
id: get-latest-commit-sha
46+
run: |
47+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
48+
49+
- name: Define branch name
50+
id: define-branch
51+
run: echo "branch=ci/pin-system-tests-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
52+
53+
- name: Check if branch already exists
54+
id: check-branch
55+
run: |
56+
BRANCH=${{ steps.define-branch.outputs.branch }}
57+
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
58+
echo "creating_new_branch=false" >> "$GITHUB_OUTPUT"
59+
echo "Branch $BRANCH already exists - please delete it and re-run the workflow."
60+
else
61+
echo "creating_new_branch=true" >> "$GITHUB_OUTPUT"
62+
echo "Branch $BRANCH does not exist - creating it now"
63+
fi
64+
65+
- name: Update system-tests references to latest commit SHA on main
66+
run: ./tooling/update_system_test_reference.sh
67+
68+
- name: Check if changes should be committed
69+
id: check-changes
70+
run: |
71+
if [[ -z "$(git status -s)" ]]; then
72+
echo "No changes to commit, exiting."
73+
echo "commit_changes=false" >> "$GITHUB_OUTPUT"
74+
else
75+
echo "commit_changes=true" >> "$GITHUB_OUTPUT"
76+
echo "Changes to commit:"
77+
git status -s
78+
fi
79+
80+
- name: Commit changes
81+
if: steps.check-changes.outputs.commit_changes == 'true'
82+
id: create-commit
83+
run: |
84+
git config user.name "github-actions[bot]"
85+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
86+
git commit -m "chore: Pin system-tests for release branch" .github/workflows/run-system-tests.yaml
87+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
88+
89+
- name: Push changes
90+
uses: DataDog/commit-headless@5a0f3876e0fbdd3a86b3e008acf4ec562db59eee # action/v2.0.1
91+
if: steps.check-changes.outputs.commit_changes == 'true' && steps.check-branch.outputs.creating_new_branch == 'true'
92+
with:
93+
token: "${{ steps.octo-sts.outputs.token }}"
94+
branch: "${{ steps.define-branch.outputs.branch }}"
95+
head-sha: "${{ steps.get-latest-commit-sha.outputs.sha }}"
96+
create-branch: true
97+
command: push
98+
commits: "${{ steps.create-commit.outputs.commit }}"
99+
100+
- name: Create pull request
101+
if: steps.check-changes.outputs.commit_changes == 'true' && steps.check-branch.outputs.creating_new_branch == 'true'
102+
env:
103+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
104+
# REMOVE DRAFT
105+
run: |
106+
gh pr create --title "Pin system tests for release branch" \
107+
--base ${{ steps.define-base-branch.outputs.base_branch }} \
108+
--head ${{ steps.define-branch.outputs.branch }} \
109+
--label "tag: dependencies" \
110+
--label "tag: no release notes" \
111+
--body "This PR pins the system-tests reference for the release branch." \
112+
--draft

.gitlab-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ muzzle-dep-report:
542542
needs: [ build_tests ]
543543
stage: tests
544544
variables:
545-
KUBERNETES_MEMORY_REQUEST: 17Gi
546-
KUBERNETES_MEMORY_LIMIT: 17Gi
545+
KUBERNETES_MEMORY_REQUEST: 20Gi
546+
KUBERNETES_MEMORY_LIMIT: 20Gi
547547
KUBERNETES_CPU_REQUEST: 10
548548
GRADLE_WORKERS: 4
549549
GRADLE_MEM: 3G
@@ -728,7 +728,7 @@ test_smoke:
728728
GRADLE_PARAMS: "-PskipFlakyTests"
729729
CACHE_TYPE: "smoke"
730730
parallel:
731-
matrix: *test_matrix_6
731+
matrix: *test_matrix_8
732732

733733
test_ssi_smoke:
734734
extends: .test_job
@@ -739,7 +739,7 @@ test_ssi_smoke:
739739
DD_INJECT_FORCE: "true"
740740
DD_INJECTION_ENABLED: "tracer"
741741
parallel:
742-
matrix: *test_matrix_6
742+
matrix: *test_matrix_8
743743

744744
test_smoke_graalvm:
745745
extends: .test_job

.gitlab/one-pipeline.locked.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# DO NOT EDIT THIS FILE MANUALLY
22
# This file is auto-generated by automation.
33
include:
4-
- remote: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/04f6a88e3db67cb88821632d138a2a5c3105ba59760bd3dfc60b54733501ecc3/one-pipeline.yml
4+
- remote: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/58b2e8d06c714848c8577c8ac9b460b7413823d75ee96d068ebff547d109f5d0/one-pipeline.yml

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/propagation/CodecModuleTest.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ class CodecModuleTest extends IastModuleImplTestBase {
290290
then:
291291
final helloTainted = to.get(hello)
292292
helloTainted.ranges.length == 1
293-
helloTainted.ranges.first().with {
294-
assert it.source.origin == (byte) 0
295-
assert it.source.name == 'name1'
296-
assert it.source.value == 'Hello'
293+
with(helloTainted.ranges.first()) {
294+
it.source.origin == (byte) 0
295+
it.source.name == 'name1'
296+
it.source.value == 'Hello'
297297
}
298298

299299
when:
@@ -303,10 +303,10 @@ class CodecModuleTest extends IastModuleImplTestBase {
303303
then:
304304
final worldTainted = to.get(world)
305305
worldTainted.ranges.length == 1
306-
worldTainted.ranges.first().with {
307-
assert it.source.origin == (byte) 1
308-
assert it.source.name == 'name2'
309-
assert it.source.value == 'World!'
306+
with(worldTainted.ranges.first()) {
307+
it.source.origin == (byte) 1
308+
it.source.name == 'name2'
309+
it.source.value == 'World!'
310310
}
311311
}
312312

dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/iast/IastPostProcessorFactoryTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ class IastPostProcessorFactoryTest extends DDSpecification {
7676
final metrics = collector.drain()
7777
assert metrics.size() == 1
7878
// one method has ben instrumented
79-
metrics.first().with {
80-
assert it.metric == IastMetric.INSTRUMENTED_SINK
81-
assert it.tags == ['vulnerability_type:SQL_INJECTION']
82-
assert it.value == 1L
79+
with(metrics.first()) {
80+
it.metric == IastMetric.INSTRUMENTED_SINK
81+
it.tags == ['vulnerability_type:SQL_INJECTION']
82+
it.value == 1L
8383
}
8484

8585
when: 'the advice is used'

dd-java-agent/appsec/src/main/java/com/datadog/appsec/api/security/ApiSecuritySamplerImpl.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import datadog.trace.api.Config;
55
import datadog.trace.api.time.SystemTimeSource;
66
import datadog.trace.api.time.TimeSource;
7+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
8+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
79
import java.util.Deque;
810
import java.util.concurrent.ConcurrentHashMap;
911
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -73,8 +75,15 @@ public boolean preSampleRequest(final @Nonnull AppSecRequestContext ctx) {
7375
return false;
7476
}
7577
if (counter.tryAcquire()) {
76-
log.debug("API security sampling is required for this request (presampled)");
7778
ctx.setKeepOpenForApiSecurityPostProcessing(true);
79+
if (!Config.get().isApmTracingEnabled()) {
80+
boolean sampled = updateApiAccessIfExpired(hash);
81+
if (sampled) {
82+
logSamplingDecision("preSampleRequest", hash);
83+
}
84+
return sampled;
85+
}
86+
logSamplingDecision("preSampleRequest", hash);
7887
return true;
7988
}
8089
return false;
@@ -91,7 +100,11 @@ public boolean sampleRequest(AppSecRequestContext ctx) {
91100
// This should never happen, it should have been short-circuited before.
92101
return false;
93102
}
94-
return updateApiAccessIfExpired(hash);
103+
boolean sampled = Config.get().isApmTracingEnabled() ? updateApiAccessIfExpired(hash) : true;
104+
if (sampled) {
105+
logSamplingDecision("sampleRequest", hash);
106+
}
107+
return sampled;
95108
}
96109

97110
@Override
@@ -168,4 +181,23 @@ private long computeApiHash(final String route, final String method, final int s
168181
result = 31 * result + statusCode;
169182
return result;
170183
}
184+
185+
private void logSamplingDecision(final String method, final long hash) {
186+
if (!log.isDebugEnabled()) {
187+
return;
188+
}
189+
AgentSpan activeSpan = AgentTracer.get().activeSpan();
190+
191+
if (activeSpan != null) {
192+
log.debug(
193+
"API security sampling decision in {}: hash={}, traceId={}, spanId={}",
194+
method,
195+
hash,
196+
activeSpan.getTraceId(),
197+
activeSpan.getSpanId());
198+
} else {
199+
log.debug(
200+
"API security sampling decision in {}: hash={}, traceId=null, spanId=null", method, hash);
201+
}
202+
}
171203
}

0 commit comments

Comments
 (0)