Skip to content

Commit

Permalink
Add tag to specify if the user is setting DD_SERVICE (#8318)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mohedano authored Jan 31, 2025
1 parent 64dca18 commit 8d0bb34
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class TestImplTest extends SpanWriterTest {
def coverageStore = Mock(CoverageStore)
coverageStore.getProbes() >> coverageProbes

def coveageStoreFactory = Stub(CoverageStore.Factory)
coveageStoreFactory.create((TestIdentifier) _) >> coverageStore
def coverageStoreFactory = Stub(CoverageStore.Factory)
coverageStoreFactory.create((TestIdentifier) _) >> coverageStore

def test = givenATest(coveageStoreFactory)
def test = givenATest(coverageStoreFactory)

when:
test.setSkipReason("skipped")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,38 @@ import datadog.trace.civisibility.codeowners.Codeowners
import datadog.trace.civisibility.config.EarlyFlakeDetectionSettings
import datadog.trace.civisibility.config.ExecutionSettings
import datadog.trace.civisibility.decorator.TestDecorator
import datadog.trace.civisibility.domain.SpanWriterTest
import datadog.trace.civisibility.source.LinesResolver
import datadog.trace.civisibility.source.SourcePathResolver
import datadog.trace.civisibility.test.ExecutionStrategy
import datadog.trace.test.util.DDSpecification

class HeadlessTestModuleTest extends DDSpecification {

class HeadlessTestModuleTest extends SpanWriterTest {
def "test total retries limit is applied across test cases"() {
given:
def headlessTestModule = givenAHeadlessTestModule()

when:
def retryPolicy1 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN)

then:
retryPolicy1.retry(false, 1L) // 2nd test execution, 1st retry globally
!retryPolicy1.retry(false, 1L) // asking for 3rd test execution - local limit reached

when:
def retryPolicy2 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN)

then:
retryPolicy2.retry(false, 1L) // 2nd test execution, 2nd retry globally (since previous test was retried too)
!retryPolicy2.retry(false, 1L) // asking for 3rd test execution - local limit reached

when:
def retryPolicy3 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN)

then:
!retryPolicy3.retry(false, 1L) // asking for 3rd retry globally - global limit reached
}

private HeadlessTestModule givenAHeadlessTestModule() {
def executionSettings = Stub(ExecutionSettings)
executionSettings.getEarlyFlakeDetectionSettings() >> EarlyFlakeDetectionSettings.DEFAULT
executionSettings.isFlakyTestRetriesEnabled() >> true
Expand All @@ -31,8 +55,7 @@ class HeadlessTestModuleTest extends DDSpecification {

def executionStrategy = new ExecutionStrategy(config, executionSettings, Stub(SourcePathResolver), Stub(LinesResolver))

given:
def headlessTestModule = new HeadlessTestModule(
new HeadlessTestModule(
Stub(AgentSpanContext),
"test-module",
null,
Expand All @@ -46,27 +69,5 @@ class HeadlessTestModuleTest extends DDSpecification {
executionStrategy,
(span) -> { }
)

when:
def retryPolicy1 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN)

then:
retryPolicy1.retry(false, 1L) // 2nd test execution, 1st retry globally
!retryPolicy1.retry(false, 1L) // asking for 3rd test execution - local limit reached

when:
def retryPolicy2 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN)

then:
retryPolicy2.retry(false, 1L) // 2nd test execution, 2nd retry globally (since previous test was retried too)
!retryPolicy2.retry(false, 1L) // asking for 3rd test execution - local limit reached

when:
def retryPolicy3 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN)

then:
!retryPolicy3.retry(false, 1L) // asking for 3rd retry globally - global limit reached
}


}
1 change: 1 addition & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class DDTags {
public static final String LIBRARY_VERSION_TAG_KEY = "library_version";
public static final String CI_ENV_VARS = "_dd.ci.env_vars";
public static final String CI_ITR_TESTS_SKIPPED = "_dd.ci.itr.tests_skipped";
public static final String TEST_IS_USER_PROVIDED_SERVICE = "_dd.test.is_user_provided_service";
public static final String MEASURED = "_dd.measured";
public static final String PID_TAG = "process_id";
public static final String SCHEMA_VERSION_TAG_KEY = "_dd.trace_span_attribute_schema";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datadog.trace.api.Config;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
import datadog.trace.api.interceptor.AbstractTraceInterceptor;
import datadog.trace.api.interceptor.MutableSpan;
Expand Down Expand Up @@ -47,6 +48,9 @@ public Collection<? extends MutableSpan> onTraceComplete(
span.setTag(Tags.OS_ARCHITECTURE, wellKnownTags.getOsArch().toString());
span.setTag(Tags.OS_PLATFORM, wellKnownTags.getOsPlatform().toString());
span.setTag(Tags.OS_VERSION, wellKnownTags.getOsVersion().toString());
span.setTag(
DDTags.TEST_IS_USER_PROVIDED_SERVICE,
wellKnownTags.getIsUserProvidedService().toString());
}
}
return filteredTrace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datadog.communication.serialization.GrowableBuffer;
import datadog.communication.serialization.Writable;
import datadog.communication.serialization.msgpack.MsgPackWriter;
import datadog.trace.api.DDTags;
import datadog.trace.api.DDTraceId;
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
import datadog.trace.api.civisibility.InstrumentationBridge;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class CiTestCycleMapperV1 implements RemoteMapper {
Tags.TEST_SESSION_ID.getBytes(StandardCharsets.UTF_8);
private static final byte[] TEST_MODULE_ID = Tags.TEST_MODULE_ID.getBytes(StandardCharsets.UTF_8);
private static final byte[] TEST_SUITE_ID = Tags.TEST_SUITE_ID.getBytes(StandardCharsets.UTF_8);
private static final byte[] TEST_IS_USER_PROVIDED_SERVICE =
DDTags.TEST_IS_USER_PROVIDED_SERVICE.getBytes(StandardCharsets.UTF_8);
private static final byte[] ITR_CORRELATION_ID =
Tags.ITR_CORRELATION_ID.getBytes(StandardCharsets.UTF_8);

Expand Down Expand Up @@ -240,7 +243,7 @@ private void writeHeader() {
headerWriter.startMap(1);
/* 2,1 */
headerWriter.writeUTF8(METADATA_ASTERISK);
headerWriter.startMap(9);
headerWriter.startMap(10);
/* 2,1,1 */
headerWriter.writeUTF8(ENV);
headerWriter.writeUTF8(wellKnownTags.getEnv());
Expand Down Expand Up @@ -268,6 +271,9 @@ private void writeHeader() {
/* 2,1,9 */
headerWriter.writeUTF8(OS_VERSION);
headerWriter.writeUTF8(wellKnownTags.getOsVersion());
/* 2,1,10 */
headerWriter.writeUTF8(TEST_IS_USER_PROVIDED_SERVICE);
headerWriter.writeUTF8(wellKnownTags.getIsUserProvidedService());
/* 3 */
headerWriter.writeUTF8(EVENTS);
headerWriter.startArray(eventCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import datadog.communication.serialization.ByteBufferConsumer
import datadog.communication.serialization.FlushingBuffer
import datadog.communication.serialization.msgpack.MsgPackWriter
import datadog.trace.api.DDTags
import datadog.trace.api.DDTraceId
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes
Expand Down Expand Up @@ -47,7 +48,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
CiVisibilityWellKnownTags wellKnownTags = new CiVisibilityWellKnownTags(
"runtimeid", "my-env", "language",
"my-runtime-name", "my-runtime-version", "my-runtime-vendor",
"my-os-arch", "my-os-platform", "my-os-version")
"my-os-arch", "my-os-platform", "my-os-version", "false")
CiTestCycleMapperV1 mapper = new CiTestCycleMapperV1(wellKnownTags, false)

List<List<TraceGenerator.PojoSpan>> traces = generateRandomTraces(traceCount, lowCardinality)
Expand Down Expand Up @@ -94,7 +95,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
def span = generateRandomSpan(InternalSpanTypes.TEST, [
(Tags.TEST_SESSION_ID): DDTraceId.from(123),
(Tags.TEST_MODULE_ID) : 456,
(Tags.TEST_SUITE_ID) : 789
(Tags.TEST_SUITE_ID) : 789,
])

when:
Expand All @@ -114,7 +115,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
def span = generateRandomSpan(InternalSpanTypes.TEST_SUITE_END, [
(Tags.TEST_SESSION_ID): DDTraceId.from(123),
(Tags.TEST_MODULE_ID) : 456,
(Tags.TEST_SUITE_ID) : 789
(Tags.TEST_SUITE_ID) : 789,
])

when:
Expand Down Expand Up @@ -186,7 +187,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
CiVisibilityWellKnownTags wellKnownTags = new CiVisibilityWellKnownTags(
"runtimeid", "my-env", "language",
"my-runtime-name", "my-runtime-version", "my-runtime-vendor",
"my-os-arch", "my-os-platform", "my-os-version")
"my-os-arch", "my-os-platform", "my-os-version", "false")
CiTestCycleMapperV1 mapper = new CiTestCycleMapperV1(wellKnownTags, false)

ByteBufferConsumer consumer = new CaptureConsumer()
Expand Down Expand Up @@ -251,7 +252,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
assertEquals(1, unpacker.unpackMapHeader())
assertEquals("*", unpacker.unpackString())

assertEquals(9, unpacker.unpackMapHeader())
assertEquals(10, unpacker.unpackMapHeader())
assertEquals("env", unpacker.unpackString())
assertEquals(wellKnownTags.env as String, unpacker.unpackString())
assertEquals("runtime-id", unpacker.unpackString())
Expand All @@ -270,6 +271,8 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
assertEquals(wellKnownTags.osPlatform as String, unpacker.unpackString())
assertEquals(Tags.OS_VERSION, unpacker.unpackString())
assertEquals(wellKnownTags.osVersion as String, unpacker.unpackString())
assertEquals(DDTags.TEST_IS_USER_PROVIDED_SERVICE, unpacker.unpackString())
assertEquals(wellKnownTags.isUserProvidedService as String, unpacker.unpackString())

assertEquals("events", unpacker.unpackString())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DDIntakeWriterCombinedTest extends DDCoreSpecification {
def wellKnownTags = new CiVisibilityWellKnownTags(
"my-runtime-id", "my-env", "my-language",
"my-runtime-name", "my-runtime-version", "my-runtime-vendor",
"my-os-arch", "my-os-platform", "my-os-version")
"my-os-arch", "my-os-platform", "my-os-version", "false")

def conditions = new PollingConditions(timeout: 5, initialDelay: 0, factor: 1.25)
def monitoring = new MonitoringImpl(StatsDClient.NO_OP, 1, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import datadog.communication.serialization.ByteBufferConsumer
import datadog.communication.serialization.FlushingBuffer
import datadog.communication.serialization.msgpack.MsgPackWriter
import datadog.trace.api.DDTags
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags
import datadog.trace.api.intake.TrackType
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes
Expand All @@ -30,7 +31,7 @@ class DDEvpProxyApiTest extends DDCoreSpecification {
static CiVisibilityWellKnownTags wellKnownTags = new CiVisibilityWellKnownTags(
"my-runtime-id", "my-env", "my-language",
"my-runtime-name", "my-runtime-version", "my-runtime-vendor",
"my-os-arch", "my-os-platform", "my-os-version")
"my-os-arch", "my-os-platform", "my-os-version", "false")

static String intakeSubdomain = "citestcycle-intake"
static msgPackMapper = new ObjectMapper(new MessagePackFactory())
Expand Down Expand Up @@ -131,21 +132,22 @@ class DDEvpProxyApiTest extends DDCoreSpecification {
where:
// spotless:off
trackType | apiVersion | evpProxyEndpoint | compressionEnabled | traces | expectedRequestBody
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [] | [:]
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [] | [:]

TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, "fakeType", ["service.name": "my-service"])]] | new TreeMap<>([
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, "fakeType", ["service.name": "my-service"])]] | new TreeMap<>([
"version" : 1,
"metadata": new TreeMap<>([
"*": new TreeMap<>([
"env" : "my-env",
"runtime-id" : "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME) : "my-runtime-name",
(Tags.RUNTIME_VERSION): "my-runtime-version",
(Tags.RUNTIME_VENDOR) : "my-runtime-vendor",
(Tags.OS_ARCHITECTURE): "my-os-arch",
(Tags.OS_PLATFORM) : "my-os-platform",
(Tags.OS_VERSION) : "my-os-version"
"env" : "my-env",
"runtime-id" : "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME) : "my-runtime-name",
(Tags.RUNTIME_VERSION) : "my-runtime-version",
(Tags.RUNTIME_VENDOR) : "my-runtime-vendor",
(Tags.OS_ARCHITECTURE) : "my-os-arch",
(Tags.OS_PLATFORM) : "my-os-platform",
(Tags.OS_VERSION) : "my-os-version",
(DDTags.TEST_IS_USER_PROVIDED_SERVICE): "false"
])]),
"events" : [new TreeMap<>([
"type" : "span",
Expand All @@ -165,19 +167,20 @@ class DDEvpProxyApiTest extends DDCoreSpecification {
])
])]
])
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, InternalSpanTypes.TEST, ["test_suite_id": 123L, "test_module_id": 456L])]] | new TreeMap<>([
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, InternalSpanTypes.TEST, ["test_suite_id": 123L, "test_module_id": 456L])]] | new TreeMap<>([
"version" : 1,
"metadata": new TreeMap<>([
"*": new TreeMap<>([
"env" : "my-env",
"runtime-id": "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME): "my-runtime-name",
(Tags.RUNTIME_VERSION): "my-runtime-version",
(Tags.RUNTIME_VENDOR): "my-runtime-vendor",
(Tags.OS_ARCHITECTURE): "my-os-arch",
(Tags.OS_PLATFORM): "my-os-platform",
(Tags.OS_VERSION): "my-os-version"
"env" : "my-env",
"runtime-id" : "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME) : "my-runtime-name",
(Tags.RUNTIME_VERSION) : "my-runtime-version",
(Tags.RUNTIME_VENDOR) : "my-runtime-vendor",
(Tags.OS_ARCHITECTURE) : "my-os-arch",
(Tags.OS_PLATFORM) : "my-os-platform",
(Tags.OS_VERSION) : "my-os-version",
(DDTags.TEST_IS_USER_PROVIDED_SERVICE): "false"
])]),
"events" : [new TreeMap<>([
"type" : "test",
Expand All @@ -199,19 +202,20 @@ class DDEvpProxyApiTest extends DDCoreSpecification {
])
])]
])
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, InternalSpanTypes.TEST_SUITE_END, ["test_suite_id": 123L, "test_module_id": 456L])]] | new TreeMap<>([
TrackType.CITESTCYCLE | "v2" | V2_EVP_PROXY_ENDPOINT | false | [[buildSpan(1L, InternalSpanTypes.TEST_SUITE_END, ["test_suite_id": 123L, "test_module_id": 456L])]] | new TreeMap<>([
"version" : 1,
"metadata": new TreeMap<>([
"*": new TreeMap<>([
"env" : "my-env",
"runtime-id": "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME): "my-runtime-name",
(Tags.RUNTIME_VERSION): "my-runtime-version",
(Tags.RUNTIME_VENDOR): "my-runtime-vendor",
(Tags.OS_ARCHITECTURE): "my-os-arch",
(Tags.OS_PLATFORM): "my-os-platform",
(Tags.OS_VERSION): "my-os-version"
"env" : "my-env",
"runtime-id" : "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME) : "my-runtime-name",
(Tags.RUNTIME_VERSION) : "my-runtime-version",
(Tags.RUNTIME_VENDOR) : "my-runtime-vendor",
(Tags.OS_ARCHITECTURE) : "my-os-arch",
(Tags.OS_PLATFORM) : "my-os-platform",
(Tags.OS_VERSION) : "my-os-version",
(DDTags.TEST_IS_USER_PROVIDED_SERVICE): "false"
])]),
"events" : [new TreeMap<>([
"type" : "test_suite_end",
Expand All @@ -230,19 +234,20 @@ class DDEvpProxyApiTest extends DDCoreSpecification {
])
])]
])
TrackType.CITESTCYCLE | "v2" | V4_EVP_PROXY_ENDPOINT | true | [[buildSpan(1L, InternalSpanTypes.TEST_MODULE_END, ["test_module_id": 456L])]] | new TreeMap<>([
TrackType.CITESTCYCLE | "v2" | V4_EVP_PROXY_ENDPOINT | true | [[buildSpan(1L, InternalSpanTypes.TEST_MODULE_END, ["test_module_id": 456L])]] | new TreeMap<>([
"version" : 1,
"metadata": new TreeMap<>([
"*": new TreeMap<>([
"env" : "my-env",
"runtime-id": "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME): "my-runtime-name",
(Tags.RUNTIME_VERSION): "my-runtime-version",
(Tags.RUNTIME_VENDOR): "my-runtime-vendor",
(Tags.OS_ARCHITECTURE): "my-os-arch",
(Tags.OS_PLATFORM): "my-os-platform",
(Tags.OS_VERSION): "my-os-version"
"env" : "my-env",
"runtime-id" : "my-runtime-id",
"language" : "my-language",
(Tags.RUNTIME_NAME) : "my-runtime-name",
(Tags.RUNTIME_VERSION) : "my-runtime-version",
(Tags.RUNTIME_VENDOR) : "my-runtime-vendor",
(Tags.OS_ARCHITECTURE) : "my-os-arch",
(Tags.OS_PLATFORM) : "my-os-platform",
(Tags.OS_VERSION) : "my-os-version",
(DDTags.TEST_IS_USER_PROVIDED_SERVICE): "false"
])]),
"events" : [new TreeMap<>([
"type" : "test_module_end",
Expand Down
Loading

0 comments on commit 8d0bb34

Please sign in to comment.