Skip to content

Commit

Permalink
Move to _dd.p.ts and refactor all the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jandro996 committed Jan 24, 2025
1 parent 802233f commit bfd572e
Show file tree
Hide file tree
Showing 34 changed files with 204 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.datadog.iast.model.VulnerabilityBatch;
import com.datadog.iast.taint.TaintedObjects;
import datadog.trace.api.Config;
import datadog.trace.api.ProductTs;
import datadog.trace.api.gateway.RequestContext;
import datadog.trace.api.gateway.RequestContextSlot;
import datadog.trace.api.internal.TraceSegment;
Expand Down Expand Up @@ -125,7 +126,7 @@ private VulnerabilityBatch getOrCreateVulnerabilityBatch(final AgentSpan span) {
// TODO: We need to check if we can have an API with more fine-grained semantics on why traces
// are kept.
segment.setTagTop(Tags.ASM_KEEP, true);
segment.setTagTop(Tags.PROPAGATED_APPSEC, true);
segment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTs.ASM);
return batch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.datadog.iast.model.Vulnerability
import com.datadog.iast.model.VulnerabilityBatch
import com.datadog.iast.model.VulnerabilityType
import datadog.trace.api.Config
import datadog.trace.api.ProductTs
import datadog.trace.api.gateway.RequestContext
import datadog.trace.api.gateway.RequestContextSlot
import datadog.trace.api.internal.TraceSegment
Expand Down Expand Up @@ -85,7 +86,7 @@ class ReporterTest extends DDSpecification {
]
}''', batch.toString(), true)
1 * traceSegment.setTagTop('asm.keep', true)
1 * traceSegment.setTagTop('_dd.p.appsec', true)
1 * traceSegment.setTagTop('_dd.p.ts', ProductTs.ASM)
1 * reqCtx.getOrCreateMetaStructTop('_dd.stack', _) >> { stackTraceBatch }
assertStackTrace(stackTraceBatch, v)
0 * _
Expand Down Expand Up @@ -135,7 +136,7 @@ class ReporterTest extends DDSpecification {
]
}''', batch.toString(), true)
1 * traceSegment.setTagTop('asm.keep', true)
1 * traceSegment.setTagTop('_dd.p.appsec', true)
1 * traceSegment.setTagTop('_dd.p.ts', ProductTs.ASM)
0 * _
}

Expand Down Expand Up @@ -206,7 +207,7 @@ class ReporterTest extends DDSpecification {
]
}''', batch.toString(), true)
1 * traceSegment.setTagTop('asm.keep', true)
1 * traceSegment.setTagTop('_dd.p.appsec', true)
1 * traceSegment.setTagTop('_dd.p.ts', ProductTs.ASM)
assertStackTrace(stackTraceBatch, [v1, v2] as Vulnerability[])
0 * _
}
Expand Down Expand Up @@ -331,7 +332,7 @@ class ReporterTest extends DDSpecification {
1 * traceSegment.getDataTop('iast') >> null
1 * traceSegment.setDataTop('iast', _ as VulnerabilityBatch)
1 * traceSegment.setTagTop('asm.keep', true)
1 * traceSegment.setTagTop('_dd.p.appsec', true)
1 * traceSegment.setTagTop('_dd.p.ts', ProductTs.ASM)
1 * traceSegment.setTagTop('_dd.iast.enabled', 1)
1 * reqCtx.getOrCreateMetaStructTop('_dd.stack', _) >> new ConcurrentHashMap<>()
0 * _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.datadog.appsec.report.AppSecEvent;
import com.datadog.appsec.report.AppSecEventWrapper;
import datadog.trace.api.Config;
import datadog.trace.api.ProductTs;
import datadog.trace.api.UserIdCollectionMode;
import datadog.trace.api.gateway.Events;
import datadog.trace.api.gateway.Flow;
Expand Down Expand Up @@ -190,7 +191,7 @@ private Flow<Void> onUser(

// span with ASM data
segment.setTagTop(Tags.ASM_KEEP, true);
segment.setTagTop(Tags.PROPAGATED_APPSEC, true);
segment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTs.ASM);

// skip event if we have an SDK one
if (mode != SDK) {
Expand Down Expand Up @@ -251,7 +252,7 @@ private Flow<Void> onLoginEvent(

// span with ASM data
segment.setTagTop(Tags.ASM_KEEP, true);
segment.setTagTop(Tags.PROPAGATED_APPSEC, true);
segment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTs.ASM);

// update span tags
segment.setTagTop("appsec.events." + eventName + ".track", true, true);
Expand Down Expand Up @@ -762,7 +763,7 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
if (!collectedEvents.isEmpty()) {
// Set asm keep in case that root span was not available when events are detected
traceSeg.setTagTop(Tags.ASM_KEEP, true);
traceSeg.setTagTop(Tags.PROPAGATED_APPSEC, true);
traceSeg.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTs.ASM);
traceSeg.setTagTop("appsec.event", true);
traceSeg.setTagTop("network.client.ip", ctx.getPeerAddress());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import datadog.communication.monitor.Monitoring;
import datadog.trace.api.Config;
import datadog.trace.api.ProductActivation;
import datadog.trace.api.ProductTs;
import datadog.trace.api.gateway.Flow;
import datadog.trace.api.telemetry.LogCollector;
import datadog.trace.api.telemetry.WafMetricCollector;
Expand Down Expand Up @@ -494,7 +495,7 @@ public void onDataAvailable(
// If APM is disabled, inform downstream services that the current
// distributed trace contains at least one ASM event and must inherit
// the given force-keep priority
activeSpan.getLocalRootSpan().setTag(Tags.PROPAGATED_APPSEC, true);
activeSpan.getLocalRootSpan().setTag(Tags.PROPAGATED_TRACE_SOURCE, ProductTs.ASM);
} else {
// If active span is not available the ASK_KEEP tag will be set in the GatewayBridge
// when the request ends
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.smoketest.asmstandalonebilling;
package datadog.smoketest.apmtracingdisabled;

import java.util.EnumSet;
import javax.servlet.ServletContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.smoketest.asmstandalonebilling;
package datadog.smoketest.apmtracingdisabled;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.opentracing.Span;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.smoketest.asmstandalonebilling;
package datadog.smoketest.apmtracingdisabled;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package datadog.smoketest.asmstandalonebilling
package datadog.smoketest.apmtracingdisabled

import datadog.smoketest.AbstractServerSmokeTest
import datadog.trace.api.sampling.PrioritySampling
import datadog.trace.test.agent.decoder.DecodedTrace

abstract class AbstractAsmStandaloneBillingSmokeTest extends AbstractServerSmokeTest {
abstract class AbstractApmTracingDisabledSmokeTest extends AbstractServerSmokeTest {

@Override
File createTemporaryFile(int processIndex) {
Expand Down Expand Up @@ -67,7 +67,7 @@ abstract class AbstractAsmStandaloneBillingSmokeTest extends AbstractServerSmoke
}

protected hasAppsecPropagationTag(DecodedTrace trace) {
return trace.spans[0].meta['_dd.p.appsec'] == "1"
return trace.spans[0].meta['_dd.p.ts'] == "02"
}

protected hasApmDisabledTag(DecodedTrace trace) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package datadog.smoketest.asmstandalonebilling
package datadog.smoketest.apmtracingdisabled

import datadog.trace.api.sampling.PrioritySampling
import okhttp3.Request

class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSmokeTest {
class ApmTracingDisabledMatrixSmokeTest extends AbstractApmTracingDisabledSmokeTest {

static final String STANDALONE_BILLING_SERVICE_NAME = "asm-standalone-billing-matrix-smoketest-app"
static final String STANDALONE_BILLING_SERVICE_NAME_2 = "asm-standalone-billing-matrix-smoketest-app2"
static final String APM_TRACING_DISABLED_SERVICE_NAME = "apm-tracing-disabled-matrix-smoketest-app"
static final String APM_TRACING_DISABLED_SERVICE_NAME_2 = "apm-tracing-disabled-matrix-smoketest-app2"
static final String APM_ENABLED_SERVICE_NAME = "apm-enabled-matrix-smoketest-app"
static final String ASM_ENABLED_SERVICE_NAME = "asm-enabled-matrix-smoketest-app"

static final String[] STANDALONE_BILLING_PROPERTIES = [
"-Ddd.experimental.appsec.standalone.enabled=true",
static final String[] APM_TRACING_DISABLED_PROPERTIES = [
"-Ddd.apm.tracing.enabled=false",
"-Ddd.iast.enabled=true",
"-Ddd.iast.detection.mode=FULL",
"-Ddd.iast.debug.enabled=true",
"-Ddd.trace.tracer.metrics.enabled=true",
"-Ddd.service.name=${STANDALONE_BILLING_SERVICE_NAME}",
"-Ddd.service.name=${APM_TRACING_DISABLED_SERVICE_NAME}",
]

static final String[] STANDALONE_BILLING_PROPERTIES_2 = [
"-Ddd.experimental.appsec.standalone.enabled=true",
static final String[] APM_TRACING_DISABLED_PROPERTIES_2 = [
"-Ddd.apm.tracing.enabled=false",
"-Ddd.iast.enabled=true",
"-Ddd.iast.detection.mode=FULL",
"-Ddd.iast.debug.enabled=true",
"-Ddd.trace.tracer.metrics.enabled=true",
"-Ddd.service.name=${STANDALONE_BILLING_SERVICE_NAME_2}",
"-Ddd.service.name=${APM_TRACING_DISABLED_SERVICE_NAME_2}",
]

static final String[] APM_ENABLED_PROPERTIES = ["-Ddd.service.name=${APM_ENABLED_SERVICE_NAME}", "-Ddd.trace.tracer.metrics.enabled=true",]
Expand All @@ -46,13 +46,13 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
ProcessBuilder createProcessBuilder(int processIndex) {
switch (processIndex) {
case 0:
return createProcess(processIndex, STANDALONE_BILLING_PROPERTIES)
return createProcess(processIndex, APM_TRACING_DISABLED_PROPERTIES)
case 1:
return createProcess(processIndex, APM_ENABLED_PROPERTIES)
case 2:
return createProcess(processIndex, ASM_ENABLED_PROPERTIES)
case 3:
return createProcess(processIndex, STANDALONE_BILLING_PROPERTIES_2)
return createProcess(processIndex, APM_TRACING_DISABLED_PROPERTIES_2)
default:
throw new IllegalArgumentException("Invalid process index: ${processIndex}")
}
Expand Down Expand Up @@ -82,7 +82,7 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
!hasApmDisabledTag (upstreamTrace)

and:"No ASM events, resulting in the local sampling decision"
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
isSampledBySampler(standAloneBillingTrace)
!hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
Expand Down Expand Up @@ -118,7 +118,7 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
!hasApmDisabledTag (upstreamTrace)

and:"ASM events"
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
checkRootSpanPrioritySampling(standAloneBillingTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
Expand Down Expand Up @@ -154,7 +154,7 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
!hasApmDisabledTag (upstreamTrace)

and:"No ASM events, resulting in the local sampling decision"
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
isSampledBySampler(standAloneBillingTrace)
!hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
Expand Down Expand Up @@ -184,13 +184,13 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
waitForTraceCount(3)

and: "Upstream standalone ASM service having ASM events result in force keep and propagation of the tag"
def upstreamTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME_2)
def upstreamTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME_2)
checkRootSpanPrioritySampling(upstreamTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (upstreamTrace)
hasApmDisabledTag (upstreamTrace)

and:"standalone service must keep the local trace with the local sampling priority"
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
checkRootSpanPrioritySampling(standAloneBillingTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
Expand Down Expand Up @@ -224,11 +224,11 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
def upstreamTraceId = getServiceTrace(APM_ENABLED_SERVICE_NAME).spans[0].traceId

and: 'No ASM events, resulting in the local sampling decision'
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
isSampledBySampler(standAloneBillingTrace)
!hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
def standAloneBillingTraceId = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME).spans[0].traceId
def standAloneBillingTraceId = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME).spans[0].traceId
upstreamTraceId == standAloneBillingTraceId //There is propagation

and: 'Propagation is stopped'
Expand All @@ -255,18 +255,18 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
waitForTraceCount(3)
and: 'Upstream ASM events'
def upstreamTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME_2)
def upstreamTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME_2)
checkRootSpanPrioritySampling(upstreamTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (upstreamTrace)
hasApmDisabledTag (upstreamTrace)
def upstreamTraceId = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME_2).spans[0].traceId
def upstreamTraceId = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME_2).spans[0].traceId
and: 'No ASM events, resulting in the local sampling decision'
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
checkRootSpanPrioritySampling(standAloneBillingTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
def standAloneBillingTraceId = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME).spans[0].traceId
def standAloneBillingTraceId = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME).spans[0].traceId
upstreamTraceId == standAloneBillingTraceId //There is propagation
and: 'Default APM distributed tracing behavior with'
Expand Down Expand Up @@ -300,11 +300,11 @@ class AsmStandaloneBillingMatrixSmokeTest extends AbstractAsmStandaloneBillingSm
def upstreamTraceId = getServiceTrace(APM_ENABLED_SERVICE_NAME).spans[0].traceId
and: 'ASM events, resulting in force keep and appsec propagation'
def standAloneBillingTrace = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME)
def standAloneBillingTrace = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME)
checkRootSpanPrioritySampling(standAloneBillingTrace, PrioritySampling.USER_KEEP)
hasAppsecPropagationTag (standAloneBillingTrace)
hasApmDisabledTag (standAloneBillingTrace)
def standAloneBillingTraceId = getServiceTrace(STANDALONE_BILLING_SERVICE_NAME).spans[0].traceId
def standAloneBillingTraceId = getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME).spans[0].traceId
upstreamTraceId == standAloneBillingTraceId //There is propagation
and: 'Default APM distributed tracing behavior with'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package datadog.smoketest.asmstandalonebilling
package datadog.smoketest.apmtracingdisabled

import datadog.trace.api.sampling.PrioritySampling
import datadog.trace.test.util.Flaky
import groovy.json.JsonSlurper
import okhttp3.Request

@Flaky
class AsmStandaloneBillingSamplingSmokeTest extends AbstractAsmStandaloneBillingSmokeTest {
class ApmTracingDisabledSamplingSmokeTest extends AbstractApmTracingDisabledSmokeTest {

@Override
ProcessBuilder createProcessBuilder(){
final String[] processProperties = [
"-Ddd.experimental.appsec.standalone.enabled=true",
"-Ddd.apm.tracing.enabled=false",
"-Ddd.iast.enabled=true",
"-Ddd.appsec.enabled=true",
"-Ddd.iast.detection.mode=FULL",
"-Ddd.iast.debug.enabled=true",
"-Ddd.service.name=asm-standalone-billing-sampling-spring-smoketest-app",
"-Ddd.service.name=apm-tracing-disabled-sampling-spring-smoketest-app",
]
return createProcess(processProperties)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package datadog.smoketest.asmstandalonebilling
package datadog.smoketest.apmtracingdisabled

import okhttp3.Request

class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTest {
class ApmTracingDisabledSmokeTest extends AbstractApmTracingDisabledSmokeTest {

private static final String STANDALONE_BILLING_SERVICE_NAME = "asm-standalone-billing-smoketest-app"
private static final String APM_TRACING_DISABLED_SERVICE_NAME = "asm-standalone-billing-smoketest-app"
private static final String APM_ENABLED_SERVICE_NAME = "apm-enabled-smoketest-app"

static final String[] STANDALONE_BILLING_PROPERTIES = [
"-Ddd.experimental.appsec.standalone.enabled=true",
static final String[] APM_TRACING_DISABLED_PROPERTIES = [
"-Ddd.apm.tracing.enabled=false",
"-Ddd.iast.enabled=true",
"-Ddd.iast.detection.mode=FULL",
"-Ddd.iast.debug.enabled=true",
"-Ddd.appsec.enabled=true",
"-Ddd.trace.tracer.metrics.enabled=true",
"-Ddd.service.name=${STANDALONE_BILLING_SERVICE_NAME}",
"-Ddd.service.name=${APM_TRACING_DISABLED_SERVICE_NAME}",
]

static final String[] APM_ENABLED_PROPERTIES = ["-Ddd.service.name=${APM_ENABLED_SERVICE_NAME}", "-Ddd.trace.tracer.metrics.enabled=true",]
Expand All @@ -26,7 +26,7 @@ class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTes
@Override
ProcessBuilder createProcessBuilder(int processIndex) {
if(processIndex == 0){
return createProcess(processIndex, STANDALONE_BILLING_PROPERTIES)
return createProcess(processIndex, APM_TRACING_DISABLED_PROPERTIES)
}
return createProcess(processIndex, APM_ENABLED_PROPERTIES)
}
Expand All @@ -46,7 +46,7 @@ class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTes
response1.successful
response2.successful
waitForTraceCount(2)
hasApmDisabledTag(getServiceTrace(STANDALONE_BILLING_SERVICE_NAME))
hasApmDisabledTag(getServiceTrace(APM_TRACING_DISABLED_SERVICE_NAME))
!hasApmDisabledTag(getServiceTrace(APM_ENABLED_SERVICE_NAME))
}

Expand All @@ -68,7 +68,7 @@ class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTes
isLogPresent { it.contains('datadog.trace.agent.common.metrics.MetricsAggregatorFactory - tracer metrics disabled') }
}

void 'test _dd.p.appsec propagation for appsec event'() {
void 'test _dd.p.ts propagation for appsec event'() {
setup:
final downstreamUrl = "http://localhost:${httpPorts[1]}/rest-api/greetings"
final url = localUrl + "url=${downstreamUrl}"
Expand All @@ -77,7 +77,7 @@ class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTes
when: "Request to an endpoint that triggers ASM events and then calls another endpoint"
final response1 = client.newCall(request).execute()

then: "Both traces should have a root span with _dd.p.appsec=1 tag"
then: "Both traces should have a root span with _dd.p.ts=02 tag"
response1.successful
waitForTraceCount(2)
assert traces.size() == 2
Expand Down
Loading

0 comments on commit bfd572e

Please sign in to comment.