Skip to content

Commit 4a91aa7

Browse files
authored
Refactor (#10125)
What Does This Do Added default method to BlockResponseFunction Updated all call sites to use the new signature: Motivation This PR prepares the codebase for adding securityResponseId to RequestBlockingAction in a follow-up PR. Currently, tons of classes manually extract individual fields (statusCode, blockingContentType, extraHeaders) from RequestBlockingAction before calling tryCommitBlockingResponse. This pattern makes it difficult to extend RequestBlockingAction with new fields, as every call site would need to be updated.
1 parent c7e1489 commit 4a91aa7

File tree

72 files changed

+94
-372
lines changed

Some content is hidden

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

72 files changed

+94
-372
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/DatabaseClientDecorator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ public void onRawStatement(AgentSpan span, String sql) {
137137
BlockResponseFunction brf = ctx.getBlockResponseFunction();
138138
if (brf != null) {
139139
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
140-
brf.tryCommitBlockingResponse(
141-
ctx.getTraceSegment(),
142-
rba.getStatusCode(),
143-
rba.getBlockingContentType(),
144-
rba.getExtraHeaders());
140+
brf.tryCommitBlockingResponse(ctx.getTraceSegment(), rba);
145141
}
146142
throw new BlockingException("Blocked request (for SQL query)");
147143
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpClientDecorator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ protected void onHttpClientRequest(final AgentSpan span, final String url) {
210210
BlockResponseFunction brf = ctx.getBlockResponseFunction();
211211
if (brf != null) {
212212
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
213-
brf.tryCommitBlockingResponse(
214-
ctx.getTraceSegment(),
215-
rba.getStatusCode(),
216-
rba.getBlockingContentType(),
217-
rba.getExtraHeaders());
213+
brf.tryCommitBlockingResponse(ctx.getTraceSegment(), rba);
218214
}
219215
throw new BlockingException("Blocked request (for SSRF attempt)");
220216
}

dd-java-agent/instrumentation/akka/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/appsec/BlockingResponseHelper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ public static HttpResponse handleFinishForWaf(final AgentSpan span, final HttpRe
4242
if (action instanceof Flow.Action.RequestBlockingAction) {
4343
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
4444
if (brf instanceof AkkaBlockResponseFunction) {
45-
brf.tryCommitBlockingResponse(
46-
requestContext.getTraceSegment(),
47-
rba.getStatusCode(),
48-
rba.getBlockingContentType(),
49-
rba.getExtraHeaders());
45+
brf.tryCommitBlockingResponse(requestContext.getTraceSegment(), rba);
5046
HttpResponse altResponse =
5147
((AkkaBlockResponseFunction) brf).maybeCreateAlternativeResponse();
5248
if (altResponse != null) {

dd-java-agent/instrumentation/akka/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/appsec/UnmarshallerHelpers.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ private static void executeCallback(
128128
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
129129
if (blockResponseFunction != null) {
130130
boolean success =
131-
blockResponseFunction.tryCommitBlockingResponse(
132-
reqCtx.getTraceSegment(),
133-
rba.getStatusCode(),
134-
rba.getBlockingContentType(),
135-
rba.getExtraHeaders());
131+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
136132
if (success) {
137133
if (blockResponseFunction instanceof AkkaBlockResponseFunction) {
138134
AkkaBlockResponseFunction abrf = (AkkaBlockResponseFunction) blockResponseFunction;

dd-java-agent/instrumentation/grizzly/grizzly-http-2.3.20/src/main/java/datadog/trace/instrumentation/grizzlyhttp232/ParsedBodyParametersInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ static void after(
111111
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
112112
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
113113
if (blockResponseFunction != null) {
114-
blockResponseFunction.tryCommitBlockingResponse(
115-
reqCtx.getTraceSegment(),
116-
rba.getStatusCode(),
117-
rba.getBlockingContentType(),
118-
rba.getExtraHeaders());
114+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
119115
if (t == null) {
120116
t = new BlockingException("Blocked request (for Parameters/processParameters)");
121117
}

dd-java-agent/instrumentation/java/java-io-1.8/src/main/java/datadog/trace/instrumentation/java/lang/FileLoadedRaspHelper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ public void beforeFileLoaded(@Nonnull final String path) {
122122
BlockResponseFunction brf = ctx.getBlockResponseFunction();
123123
if (brf != null) {
124124
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
125-
brf.tryCommitBlockingResponse(
126-
ctx.getTraceSegment(),
127-
rba.getStatusCode(),
128-
rba.getBlockingContentType(),
129-
rba.getExtraHeaders());
125+
brf.tryCommitBlockingResponse(ctx.getTraceSegment(), rba);
130126
}
131127
throw new BlockingException("Blocked request (for LFI attempt)");
132128
}

dd-java-agent/instrumentation/java/java-net/java-net-1.8/src/main/java/datadog/trace/instrumentation/java/net/URLSinkCallSite.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ private static void raspCallback(@Nonnull final URL url) {
8585
BlockResponseFunction brf = ctx.getBlockResponseFunction();
8686
if (brf != null) {
8787
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
88-
brf.tryCommitBlockingResponse(
89-
ctx.getTraceSegment(),
90-
rba.getStatusCode(),
91-
rba.getBlockingContentType(),
92-
rba.getExtraHeaders());
88+
brf.tryCommitBlockingResponse(ctx.getTraceSegment(), rba);
9389
}
9490
throw new BlockingException("Blocked request (for SSRF attempt)");
9591
}

dd-java-agent/instrumentation/jersey/jersey-appsec/jersey-appsec-2.0/src/main/java/datadog/trace/instrumentation/jersey2/MessageBodyReaderInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ static void after(
8686
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
8787
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
8888
if (blockResponseFunction != null) {
89-
blockResponseFunction.tryCommitBlockingResponse(
90-
reqCtx.getTraceSegment(),
91-
rba.getStatusCode(),
92-
rba.getBlockingContentType(),
93-
rba.getExtraHeaders());
89+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
9490
t = new BlockingException("Blocked request (for ReaderInterceptorExecutor/proceed)");
9591
reqCtx.getTraceSegment().effectivelyBlocked();
9692
}

dd-java-agent/instrumentation/jersey/jersey-appsec/jersey-appsec-2.0/src/main/java/datadog/trace/instrumentation/jersey2/MultiPartReaderServerSideInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ static void after(
105105
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
106106
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
107107
if (blockResponseFunction != null) {
108-
blockResponseFunction.tryCommitBlockingResponse(
109-
reqCtx.getTraceSegment(),
110-
rba.getStatusCode(),
111-
rba.getBlockingContentType(),
112-
rba.getExtraHeaders());
108+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
113109
t = new BlockingException("Blocked request (for MultiPartReaderClientSide/readFrom)");
114110
reqCtx.getTraceSegment().effectivelyBlocked();
115111
}

dd-java-agent/instrumentation/jersey/jersey-appsec/jersey-appsec-2.0/src/main/java/datadog/trace/instrumentation/jersey2/UriRoutingContextInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ static void after(
7070
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action;
7171
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction();
7272
if (blockResponseFunction != null) {
73-
blockResponseFunction.tryCommitBlockingResponse(
74-
reqCtx.getTraceSegment(),
75-
rba.getStatusCode(),
76-
rba.getBlockingContentType(),
77-
rba.getExtraHeaders());
73+
blockResponseFunction.tryCommitBlockingResponse(reqCtx.getTraceSegment(), rba);
7874
t =
7975
new BlockingException(
8076
"Blocked request (for UriRoutingContextInstrumentation/getPathParameters)");

0 commit comments

Comments
 (0)