Skip to content

Commit 430ec7b

Browse files
authored
Merge branch 'master' into jb/crash_track_unredacted
2 parents ae4d6b6 + 8233fc5 commit 430ec7b

File tree

129 files changed

+4792
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+4792
-593
lines changed

.github/workflows/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ _Action:_ Append the new release to the Cloud Foundry repository.
2020

2121
_Recovery:_ Manually edit and push the `index.yml` file from [the cloudfoundry branch](https://github.com/DataDog/dd-trace-java/tree/cloudfoundry).
2222

23+
### check-pull-requests [🔗](check-pull-requests.yaml)
24+
25+
_Trigger:_ When creating or updating a pull request.
26+
27+
_Action:_ Check the pull request complies with [the contribution guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md).
28+
29+
_Recovery:_ Manually verify the guideline compliance.
30+
2331
### create-next-milestone [🔗](create-next-milestone.yaml)
2432

2533
_Trigger:_ When closing a milestone.

.github/workflows/analyze-changes.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ jobs:
140140
output: 'trivy-results.sarif'
141141
severity: 'CRITICAL,HIGH'
142142
limit-severities-for-sarif: true
143+
env:
144+
TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db
145+
TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
143146

144147
- name: Upload Trivy scan results to GitHub Security tab
145148
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Check pull requests
2+
on:
3+
pull_request:
4+
types: [opened, reopened, edited, labeled, unlabeled]
5+
branches:
6+
- master
7+
- release/v*
8+
jobs:
9+
check_pull_requests:
10+
name: Check pull requests
11+
permissions:
12+
issues: write # Required to create a comment on the pull request
13+
pull-requests: write # Required to create a comment on the pull request
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check pull requests
17+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
18+
with:
19+
github-token: ${{secrets.GITHUB_TOKEN}}
20+
script: |
21+
// Skip draft pull requests
22+
if (context.payload.pull_request.draft) {
23+
return
24+
}
25+
// Check at least one type and (component or instrumentation) label is set
26+
const labels = context.payload.pull_request.labels.map(label => label.name)
27+
const ignoreReleaseNotes = labels.filter(label => label == 'tag: no release notes').length > 0
28+
const hasTypeLabel = labels.filter(label => label.startsWith('type:')).length > 0
29+
const hasComponentLabel = labels.filter(label => label.startsWith('comp:')).length > 0
30+
const hasInstrumentationLabel = labels.filter(label => label.startsWith('instr:')).length > 0
31+
const labelsCheckFailed = !ignoreReleaseNotes && (!hasTypeLabel || (!hasComponentLabel && !hasInstrumentationLabel));
32+
if (labelsCheckFailed) {
33+
core.setFailed('Please add at least one type, and one component or instrumentation label to the pull request.')
34+
}
35+
// Check title does not contain tag
36+
const title = context.payload.pull_request.title
37+
const titleCheckFailed = title.match(/\[.*\]/)
38+
if (titleCheckFailed) {
39+
core.setFailed('Please remove the tag from the pull request title.')
40+
}
41+
// Add comment to the pull request
42+
if (labelsCheckFailed || titleCheckFailed) {
43+
await github.rest.issues.createComment({
44+
issue_number: context.payload.pull_request.number,
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
body: 'Hi! 👋 Thanks for your pull request! 🎉\n\n' +
48+
'To help us review it, please make sure to:\n\n' +
49+
(labelsCheckFailed ? '* Add at least one type, and one component or instrumentation label to the pull request\n' : '') +
50+
(titleCheckFailed ? '* Remove the tag from the pull request title\n' : '') +
51+
'\nIf you need help, please check our [contributing guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md).'
52+
})
53+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"pull_request": {
3+
"number": 7884,
4+
"draft": true,
5+
"labels": [],
6+
"title": "Adding some new features"
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"pull_request": {
3+
"number": 7884,
4+
"draft": false,
5+
"labels": [
6+
{
7+
"name": "comp: api"
8+
}
9+
],
10+
"title": "Adding some new features"
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"pull_request": {
3+
"number": 7884,
4+
"draft": false,
5+
"labels": [
6+
{
7+
"name": "tag: no release notes"
8+
}
9+
],
10+
"title": "Adding some new features"
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"pull_request": {
3+
"number": 7884,
4+
"draft": false,
5+
"labels": [
6+
{
7+
"name": "comp: api"
8+
},
9+
{
10+
"name": "type: enhancement"
11+
}
12+
],
13+
"title": "[API] Adding some new features"
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"pull_request": {
3+
"number": 7884,
4+
"draft": false,
5+
"labels": [
6+
{
7+
"name": "comp: api"
8+
},
9+
{
10+
"name": "type: enhancement"
11+
}
12+
],
13+
"title": "Adding some new features"
14+
}
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
source "$(dirname "$0")/../env.sh"
3+
testworkflow pull_request && \
4+
testworkflow pull_request draft && \
5+
testworkflow pull_request no-release-notes && \
6+
! testworkflow pull_request missing-label && \
7+
! testworkflow pull_request title-tag

.github/workflows/tests/env.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
function testworkflow() {
44
local EVENT_TYPE=$1
5+
local SCENARIO=$2
56
# Get workflow name
67
local TEST_PATH
78
TEST_PATH=$(dirname "$(readlink -f "${BASH_SOURCE[1]}")")
89
local WORKFLOW_NAME
910
WORKFLOW_NAME=$(basename "$TEST_PATH")
1011
local WORKFLOW_FILE=.github/workflows/${WORKFLOW_NAME}.yaml
11-
local PAYLOAD_FILE=${TEST_PATH}/payload-${EVENT_TYPE//_/-}.json
12+
local PAYLOAD_FILE
13+
PAYLOAD_FILE=${TEST_PATH}/payload-${EVENT_TYPE//_/-}
14+
if [ "$SCENARIO" != "" ]; then
15+
PAYLOAD_FILE=${PAYLOAD_FILE}-${SCENARIO}
16+
fi
17+
PAYLOAD_FILE=${PAYLOAD_FILE}.json
1218
# Move to project root directory
1319
local FILE_PATH
1420
FILE_PATH=$(dirname "$0")
15-
cd "$FILE_PATH/../../../../" || exit 1
21+
pushd "$FILE_PATH/../../../../" || exit 1
1622
# Check if workflow file and payload file exist
1723
if [ ! -f "$WORKFLOW_FILE" ]; then
1824
echo "Workflow file not found: $WORKFLOW_FILE"
@@ -29,4 +35,10 @@ function testworkflow() {
2935
--container-architecture linux/amd64 \
3036
--secret GITHUB_TOKEN="$(gh auth token)" \
3137
--verbose
38+
# Capture the exit code
39+
local EXIT_CODE=$?
40+
# Move back to initial directory
41+
popd || exit 1
42+
# Return the test exit code
43+
return $EXIT_CODE
3244
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/QueueTimerHelper.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datadog.trace.api.config.ProfilingConfig;
55
import datadog.trace.api.profiling.QueueTiming;
66
import datadog.trace.api.profiling.Timer;
7+
import datadog.trace.api.profiling.Timing;
78
import datadog.trace.api.sampling.PerRecordingRateLimiter;
89
import datadog.trace.bootstrap.ContextStore;
910
import datadog.trace.bootstrap.config.provider.ConfigProvider;
@@ -35,21 +36,28 @@ public static <T> void startQueuingTimer(
3536
}
3637

3738
public static void startQueuingTimer(State state, Class<?> schedulerClass, Object task) {
38-
if (Platform.isNativeImageBuilder()) {
39+
if (Platform.isNativeImage()) {
3940
// explicitly not supported for Graal native image
4041
return;
4142
}
4243
// avoid calling this before JFR is initialised because it will lead to reading the wrong
4344
// TSC frequency before JFR has set it up properly
44-
if (task != null
45-
&& state != null
46-
&& InstrumentationBasedProfiling.isJFRReady()
47-
&& RateLimiterHolder.RATE_LIMITER.permit()) {
45+
if (task != null && state != null && InstrumentationBasedProfiling.isJFRReady()) {
4846
QueueTiming timing =
4947
(QueueTiming) AgentTracer.get().getProfilingContext().start(Timer.TimerType.QUEUEING);
5048
timing.setTask(task);
5149
timing.setScheduler(schedulerClass);
5250
state.setTiming(timing);
5351
}
5452
}
53+
54+
public static void stopQueuingTimer(Timing timing) {
55+
if (Platform.isNativeImage()) {
56+
// explicitly not supported for Graal native image
57+
return;
58+
}
59+
if (timing != null && timing.sample() && RateLimiterHolder.RATE_LIMITER.permit()) {
60+
timing.report();
61+
}
62+
}
5563
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/State.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public boolean isTimed() {
8585
public void stopTiming() {
8686
Timing timing = TIMING.getAndSet(this, null);
8787
if (timing != null) {
88-
timing.close();
88+
QueueTimerHelper.stopQueuingTimer(timing);
8989
}
9090
}
9191
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/JacocoCoverageCalculator.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.BufferedInputStream;
1717
import java.io.ByteArrayInputStream;
1818
import java.io.File;
19+
import java.io.FileOutputStream;
1920
import java.io.IOException;
2021
import java.io.InputStream;
2122
import java.nio.file.Files;
@@ -43,6 +44,7 @@
4344
import org.jacoco.report.IReportVisitor;
4445
import org.jacoco.report.InputStreamSourceFileLocator;
4546
import org.jacoco.report.html.HTMLFormatter;
47+
import org.jacoco.report.xml.XMLFormatter;
4648
import org.slf4j.Logger;
4749
import org.slf4j.LoggerFactory;
4850

@@ -290,12 +292,23 @@ private void dumpCoverageReport(IBundleCoverage coverageBundle, File reportFolde
290292
}
291293
try {
292294
final HTMLFormatter htmlFormatter = new HTMLFormatter();
293-
final IReportVisitor visitor =
295+
296+
final IReportVisitor htmlVisitor =
294297
htmlFormatter.createVisitor(new FileMultiReportOutput(reportFolder));
295-
visitor.visitInfo(Collections.emptyList(), Collections.emptyList());
296-
visitor.visitBundle(
298+
htmlVisitor.visitInfo(Collections.emptyList(), Collections.emptyList());
299+
htmlVisitor.visitBundle(
297300
coverageBundle, new RepoIndexFileLocator(repoIndexProvider.getIndex(), repoRoot));
298-
visitor.visitEnd();
301+
htmlVisitor.visitEnd();
302+
303+
File xmlReport = new File(reportFolder, "jacoco.xml");
304+
try (FileOutputStream xmlReportStream = new FileOutputStream(xmlReport)) {
305+
XMLFormatter xmlFormatter = new XMLFormatter();
306+
IReportVisitor xmlVisitor = xmlFormatter.createVisitor(xmlReportStream);
307+
xmlVisitor.visitInfo(Collections.emptyList(), Collections.emptyList());
308+
xmlVisitor.visitBundle(
309+
coverageBundle, new RepoIndexFileLocator(repoIndexProvider.getIndex(), repoRoot));
310+
xmlVisitor.visitEnd();
311+
}
299312
} catch (Exception e) {
300313
LOGGER.error("Error while creating report in {}", reportFolder, e);
301314
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestSuiteImpl.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static datadog.trace.api.civisibility.CIConstants.CI_VISIBILITY_INSTRUMENTATION_NAME;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
5+
import static datadog.trace.util.Strings.toJson;
56

67
import datadog.trace.api.Config;
78
import datadog.trace.api.civisibility.DDTestSuite;
@@ -22,6 +23,7 @@
2223
import datadog.trace.civisibility.source.SourceResolutionException;
2324
import datadog.trace.civisibility.utils.SpanUtils;
2425
import java.lang.reflect.Method;
26+
import java.util.Collection;
2527
import java.util.function.Consumer;
2628
import javax.annotation.Nullable;
2729
import org.slf4j.Logger;
@@ -113,7 +115,7 @@ public TestSuiteImpl(
113115
this.testClass = testClass;
114116

115117
if (config.isCiVisibilitySourceDataEnabled()) {
116-
populateSourceDataTags(testClass, sourcePathResolver);
118+
populateSourceDataTags(span, testClass, sourcePathResolver, codeowners);
117119
}
118120

119121
testDecorator.afterStart(span);
@@ -130,17 +132,31 @@ public TestSuiteImpl(
130132
}
131133
}
132134

133-
private void populateSourceDataTags(Class<?> testClass, SourcePathResolver sourcePathResolver) {
134-
if (this.testClass == null) {
135+
private void populateSourceDataTags(
136+
AgentSpan span,
137+
Class<?> testClass,
138+
SourcePathResolver sourcePathResolver,
139+
Codeowners codeowners) {
140+
if (testClass == null) {
135141
return;
136142
}
143+
144+
String sourcePath;
137145
try {
138-
String sourcePath = sourcePathResolver.getSourcePath(testClass);
139-
if (sourcePath != null && !sourcePath.isEmpty()) {
140-
span.setTag(Tags.TEST_SOURCE_FILE, sourcePath);
146+
sourcePath = sourcePathResolver.getSourcePath(testClass);
147+
if (sourcePath == null || sourcePath.isEmpty()) {
148+
return;
141149
}
142150
} catch (SourceResolutionException e) {
143151
log.debug("Could not populate source path for {}", testClass, e);
152+
return;
153+
}
154+
155+
span.setTag(Tags.TEST_SOURCE_FILE, sourcePath);
156+
157+
Collection<String> testCodeOwners = codeowners.getOwners(sourcePath);
158+
if (testCodeOwners != null) {
159+
span.setTag(Tags.TEST_CODEOWNERS, toJson(testCodeOwners));
144160
}
145161
}
146162

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package datadog.trace.civisibility.domain
2+
3+
import datadog.trace.agent.tooling.TracerInstaller
4+
import datadog.trace.api.IdGenerationStrategy
5+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
6+
import datadog.trace.common.writer.ListWriter
7+
import datadog.trace.core.CoreTracer
8+
import datadog.trace.test.util.DDSpecification
9+
import spock.lang.Shared
10+
11+
abstract class SpanWriterTest extends DDSpecification {
12+
@SuppressWarnings('PropertyName')
13+
@Shared
14+
ListWriter TEST_WRITER
15+
16+
@SuppressWarnings('PropertyName')
17+
@Shared
18+
AgentTracer.TracerAPI TEST_TRACER
19+
20+
void setupSpec() {
21+
TEST_WRITER = new ListWriter()
22+
TEST_TRACER =
23+
Spy(
24+
CoreTracer.builder()
25+
.writer(TEST_WRITER)
26+
.idGenerationStrategy(IdGenerationStrategy.fromName("SEQUENTIAL"))
27+
.build())
28+
TracerInstaller.forceInstallGlobalTracer(TEST_TRACER)
29+
30+
TEST_TRACER.startSpan(*_) >> {
31+
def agentSpan = callRealMethod()
32+
agentSpan
33+
}
34+
}
35+
36+
void cleanupSpec() {
37+
TEST_TRACER?.close()
38+
}
39+
40+
void setup() {
41+
assert TEST_TRACER.activeSpan() == null: "Span is active before test has started: " + TEST_TRACER.activeSpan()
42+
TEST_TRACER.flush()
43+
TEST_WRITER.start()
44+
}
45+
46+
void cleanup() {
47+
TEST_TRACER.flush()
48+
}
49+
}

0 commit comments

Comments
 (0)