Skip to content

Commit d218176

Browse files
authored
Merge branch 'master' into oceane.bordeau/sds-attach-sdk-response
2 parents 9d6a38d + 8185dcf commit d218176

29 files changed

Lines changed: 425 additions & 50 deletions

File tree

.gitlab/add_final_status.xsl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
We're using not-that-ideal XSLT here as this change, because it must be done over 17+ repos.
5+
It's a workaround until this gets integrated into a better place, such as datadog-ci or the backend.
6+
* ticket: https://datadoghq.atlassian.net/browse/APMSP-2610
7+
* RFC: https://docs.google.com/document/d/1OaX_h09fCXWmK_1ADrwvilt8Yt5h4WjC7UUAdS3Y3uw/edit?pli=1&tab=t.0#heading=h.tfy5viz7rz2
8+
-->
9+
10+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
11+
12+
<!-- Identity transform: copy everything as-is by default -->
13+
<xsl:template match="@*|node()">
14+
<xsl:copy>
15+
<xsl:apply-templates select="@*|node()"/>
16+
</xsl:copy>
17+
</xsl:template>
18+
19+
<!-- For testcase elements missing dd_tags[test.final_status] inside their properties block -->
20+
<xsl:template match="testcase[not(properties/property[@name='dd_tags[test.final_status]'])]">
21+
<xsl:copy>
22+
<xsl:apply-templates select="@*"/>
23+
<xsl:variable name="status">
24+
<xsl:choose>
25+
<xsl:when test="failure or error">fail</xsl:when>
26+
<xsl:when test="skipped">skip</xsl:when>
27+
<xsl:otherwise>pass</xsl:otherwise>
28+
</xsl:choose>
29+
</xsl:variable>
30+
<xsl:choose>
31+
<xsl:when test="properties">
32+
<!-- Inject into existing properties block, preserving child order -->
33+
<xsl:for-each select="node()">
34+
<xsl:choose>
35+
<xsl:when test="self::properties">
36+
<properties>
37+
<xsl:apply-templates select="@*|node()"/>
38+
<property name="dd_tags[test.final_status]" value="{$status}"/>
39+
</properties>
40+
</xsl:when>
41+
<xsl:otherwise>
42+
<xsl:apply-templates select="."/>
43+
</xsl:otherwise>
44+
</xsl:choose>
45+
</xsl:for-each>
46+
</xsl:when>
47+
<xsl:otherwise>
48+
<!-- No properties block: create one before other children -->
49+
<properties>
50+
<property name="dd_tags[test.final_status]" value="{$status}"/>
51+
</properties>
52+
<xsl:apply-templates select="node()"/>
53+
</xsl:otherwise>
54+
</xsl:choose>
55+
</xsl:copy>
56+
</xsl:template>
57+
58+
</xsl:stylesheet>

.gitlab/collect_results.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ do
7777
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TARGET_DIR/$AGGREGATED_FILE_NAME"
7878
# Replace random port numbers by marker in testcase XML nodes to get stable test names
7979
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TARGET_DIR/$AGGREGATED_FILE_NAME"
80+
81+
# Add dd_tags[test.final_status] property to each testcase
82+
xsl_file="$(dirname "$0")/add_final_status.xsl"
83+
tmp_file="$(mktemp)"
84+
xsltproc --output "$tmp_file" "$xsl_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
85+
mv "$tmp_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
86+
8087
if cmp -s "$RESULT_XML_FILE" "$TARGET_DIR/$AGGREGATED_FILE_NAME"; then
8188
echo ""
8289
else

dd-java-agent/agent-aiguard/src/main/java/com/datadog/aiguard/AIGuardInternal.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ private static String getToolName(final Message current, final List<Message> mes
205205
}
206206

207207
private boolean isBlockingEnabled(final Options options, final Object isBlockingEnabled) {
208+
if (isBlockingEnabled == null) {
209+
return false;
210+
}
208211
return options.block() && "true".equalsIgnoreCase(isBlockingEnabled.toString());
209212
}
210213

dd-java-agent/agent-aiguard/src/test/groovy/com/datadog/aiguard/AIGuardInternalTests.groovy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,51 @@ class AIGuardInternalTests extends DDSpecification {
224224
suite << TestSuite.build()
225225
}
226226

227+
void 'test evaluate block defaults to remote is_blocking_enabled'() {
228+
given:
229+
def request
230+
final call = Mock(Call) {
231+
execute() >> {
232+
return mockResponse(
233+
request,
234+
200,
235+
[data: [attributes: [action: 'DENY', reason: 'Nope', tags: ['deny_everything'], is_blocking_enabled: remoteBlocking]]]
236+
)
237+
}
238+
}
239+
final client = Mock(OkHttpClient) {
240+
newCall(_ as Request) >> {
241+
request = (Request) it[0]
242+
return call
243+
}
244+
}
245+
final aiguard = new AIGuardInternal(URL, HEADERS, client)
246+
247+
when:
248+
Throwable error = null
249+
AIGuard.Evaluation eval = null
250+
try {
251+
eval = aiguard.evaluate(TOOL_CALL, options)
252+
} catch (Throwable e) {
253+
error = e
254+
}
255+
256+
then:
257+
if (shouldBlock) {
258+
error instanceof AIGuard.AIGuardAbortError
259+
error.action == DENY
260+
} else {
261+
error == null
262+
eval.action == DENY
263+
}
264+
265+
where:
266+
options | remoteBlocking | shouldBlock
267+
AIGuard.Options.DEFAULT | true | true
268+
AIGuard.Options.DEFAULT | false | false
269+
new AIGuard.Options().block(false) | true | false
270+
}
271+
227272
void 'test evaluate with API errors'() {
228273
given:
229274
final errors = [[status: 400, title: 'Bad request']]

dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/src/main/java/datadog/trace/instrumentation/armeria/grpc/client/GrpcClientDecorator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import datadog.trace.api.datastreams.DataStreamsTags;
1616
import datadog.trace.api.naming.SpanNaming;
1717
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
18+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
1819
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
1920
import datadog.trace.bootstrap.instrumentation.api.Tags;
2021
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
@@ -116,6 +117,7 @@ public AgentSpan onClose(final AgentSpan span, final Status status) {
116117

117118
span.setTag("status.code", status.getCode().name());
118119
span.setTag("grpc.status.code", status.getCode().name());
120+
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
119121
span.setTag("status.description", status.getDescription());
120122

121123
// TODO why is there a mismatch between client / server for calling the onError method?

dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/src/main/java/datadog/trace/instrumentation/armeria/grpc/server/GrpcServerDecorator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.naming.SpanNaming;
1010
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1111
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
12+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
1213
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
1314
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
1415
import datadog.trace.bootstrap.instrumentation.decorator.ServerDecorator;
@@ -97,6 +98,7 @@ public <RespT, ReqT> AgentSpan onCall(final AgentSpan span, ServerCall<ReqT, Res
9798
public AgentSpan onStatus(final AgentSpan span, final Status status) {
9899
span.setTag("status.code", status.getCode().name());
99100
span.setTag("grpc.status.code", status.getCode().name());
101+
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
100102
span.setTag("status.description", status.getDescription());
101103
return span.setError(
102104
SERVER_ERROR_STATUSES.get(status.getCode().value()), ErrorPriorities.HTTP_SERVER_DECORATOR);

dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/src/test/groovy/ArmeriaGrpcStreamingTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.linecorp.armeria.server.grpc.GrpcService
77
import com.linecorp.armeria.testing.junit4.server.ServerRule
88
import datadog.trace.agent.test.naming.VersionedNamingTestBase
99
import datadog.trace.api.DDSpanTypes
10+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
1011
import datadog.trace.bootstrap.instrumentation.api.Tags
1112
import example.GreeterGrpc
1213
import example.Helloworld
@@ -178,6 +179,7 @@ abstract class ArmeriaGrpcStreamingTest extends VersionedNamingTestBase {
178179
"$Tags.RPC_SERVICE" "example.Greeter"
179180
"status.code" "OK"
180181
"grpc.status.code" "OK"
182+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
181183
"request.type" "example.Helloworld\$Response"
182184
"response.type" "example.Helloworld\$Response"
183185
peerServiceFrom(Tags.RPC_SERVICE)
@@ -215,6 +217,7 @@ abstract class ArmeriaGrpcStreamingTest extends VersionedNamingTestBase {
215217
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
216218
"status.code" "OK"
217219
"grpc.status.code" "OK"
220+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
218221
defaultTags(true)
219222
}
220223
}

dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/src/test/groovy/ArmeriaGrpcTest.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import datadog.trace.api.gateway.RequestContext
1818
import datadog.trace.api.gateway.RequestContextSlot
1919
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation
2020
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
21+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
2122
import datadog.trace.bootstrap.instrumentation.api.Tags
2223
import datadog.trace.core.datastreams.StatsGroup
2324
import datadog.trace.instrumentation.armeria.grpc.server.GrpcExtractAdapter
@@ -182,6 +183,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
182183
"$Tags.RPC_SERVICE" "example.Greeter"
183184
"status.code" "OK"
184185
"grpc.status.code" "OK"
186+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
185187
"request.type" "example.Helloworld\$Request"
186188
"response.type" "example.Helloworld\$Response"
187189
if ({ isDataStreamsEnabled() }) {
@@ -221,6 +223,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
221223
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
222224
"status.code" "OK"
223225
"grpc.status.code" "OK"
226+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
224227
if ({ isDataStreamsEnabled() }) {
225228
"$DDTags.PATHWAY_HASH" { String }
226229
}
@@ -319,6 +322,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
319322
"$Tags.RPC_SERVICE" "example.Greeter"
320323
"status.code" "${status.code.name()}"
321324
"grpc.status.code" "${status.code.name()}"
325+
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
322326
"status.description" description
323327
"request.type" "example.Helloworld\$Request"
324328
"response.type" "example.Helloworld\$Response"
@@ -343,6 +347,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
343347
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
344348
"status.code" "${status.code.name()}"
345349
"grpc.status.code" "${status.code.name()}"
350+
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
346351
"status.description" description
347352
"canceled" { true } // 1.0.0 handles cancellation incorrectly so accesting any value
348353
if (status.cause != null) {
@@ -432,6 +437,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
432437
"$Tags.RPC_SERVICE" "example.Greeter"
433438
"status.code" status.code.name()
434439
"grpc.status.code" status.code.name()
440+
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
435441
if (status.description != null) {
436442
"status.description" status.description
437443
}
@@ -459,6 +465,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
459465
errorTags error.class, error.message
460466
"status.code" "${status.code.name()}"
461467
"grpc.status.code" "${status.code.name()}"
468+
"$InstrumentationTags.GRPC_STATUS_CODE" status.code.value()
462469
"status.description" { it == null || String}
463470
"canceled" { true } // 1.0.0 handles cancellation incorrectly so accesting any value
464471
if ({ isDataStreamsEnabled() }) {
@@ -574,6 +581,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
574581
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
575582
"status.code" "OK"
576583
"grpc.status.code" "OK"
584+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
577585
if ({ isDataStreamsEnabled() }) {
578586
"$DDTags.PATHWAY_HASH" { String }
579587
}
@@ -650,6 +658,7 @@ abstract class ArmeriaGrpcTest extends VersionedNamingTestBase {
650658
"$Tags.RPC_SERVICE" "example.Greeter"
651659
"status.code" "OK"
652660
"grpc.status.code" "OK"
661+
"$InstrumentationTags.GRPC_STATUS_CODE" 0
653662
"request.type" "example.Helloworld\$Request"
654663
"response.type" "example.Helloworld\$Response"
655664
if ({ isDataStreamsEnabled() }) {

dd-java-agent/instrumentation/google-pubsub-1.116/src/test/groovy/PubSubTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import datadog.trace.api.DDSpanTypes
2727
import datadog.trace.api.DDTags
2828
import datadog.trace.api.config.GeneralConfig
2929
import datadog.trace.api.config.TraceInstrumentationConfig
30+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
3031
import datadog.trace.bootstrap.instrumentation.api.Tags
3132
import datadog.trace.core.DDSpan
3233
import datadog.trace.core.datastreams.StatsGroup
@@ -284,6 +285,7 @@ abstract class PubSubTest extends VersionedNamingTestBase {
284285
"$Tags.RPC_SERVICE" { String }
285286
"status.code" { String }
286287
"grpc.status.code" { String }
288+
"$InstrumentationTags.GRPC_STATUS_CODE" { Integer }
287289
if ({ isDataStreamsEnabled() }) {
288290
"$DDTags.PATHWAY_HASH" { String }
289291
}

dd-java-agent/instrumentation/grpc-1.5/src/main/java/datadog/trace/instrumentation/grpc/client/GrpcClientDecorator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import datadog.trace.api.datastreams.DataStreamsContext;
1717
import datadog.trace.api.naming.SpanNaming;
1818
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
19+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
1920
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
2021
import datadog.trace.bootstrap.instrumentation.api.Tags;
2122
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
@@ -116,6 +117,7 @@ public <C> void injectContext(Context context, final C request, CarrierSetter<C>
116117
public AgentSpan onClose(final AgentSpan span, final Status status) {
117118
span.setTag("status.code", status.getCode().name());
118119
span.setTag("grpc.status.code", status.getCode().name());
120+
span.setTag(InstrumentationTags.GRPC_STATUS_CODE, status.getCode().value());
119121
span.setTag("status.description", status.getDescription());
120122

121123
// TODO why is there a mismatch between client / server for calling the onError method?

0 commit comments

Comments
 (0)