|
1 | 1 | package datadog.telemetry |
2 | 2 |
|
| 3 | + |
| 4 | +import com.squareup.moshi.Moshi |
| 5 | +import com.squareup.moshi.Types |
3 | 6 | import datadog.telemetry.api.RequestType |
4 | 7 | import datadog.trace.api.ConfigOrigin |
5 | 8 | import datadog.trace.api.ConfigSetting |
| 9 | +import datadog.trace.api.ProcessTags |
6 | 10 | import datadog.trace.api.telemetry.ProductChange |
7 | | -import okio.Buffer |
| 11 | +import datadog.trace.test.util.DDSpecification |
8 | 12 | import okhttp3.RequestBody |
9 | | -import spock.lang.Specification |
| 13 | +import okio.Buffer |
10 | 14 |
|
| 15 | +import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED |
11 | 16 | import static datadog.trace.api.telemetry.ProductChange.ProductType.APPSEC |
12 | 17 | import static datadog.trace.api.telemetry.ProductChange.ProductType.DYNAMIC_INSTRUMENTATION |
13 | 18 | import static datadog.trace.api.telemetry.ProductChange.ProductType.PROFILER |
14 | 19 |
|
15 | 20 | /** |
16 | 21 | * This test only verifies non-functional specifics that are not covered in TelemetryServiceSpecification |
17 | 22 | */ |
18 | | -class TelemetryRequestBodySpecification extends Specification { |
| 23 | +class TelemetryRequestBodySpecification extends DDSpecification { |
19 | 24 |
|
20 | 25 | def 'throw SerializationException in case of JSON nesting problem'() { |
21 | 26 | setup: |
@@ -112,17 +117,17 @@ class TelemetryRequestBodySpecification extends Specification { |
112 | 117 | drainToString(req).contains("\"debug\":true") |
113 | 118 | } |
114 | 119 |
|
115 | | - void 'test writeProducts'(){ |
| 120 | + void 'test writeProducts'() { |
116 | 121 | setup: |
117 | 122 | TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_PRODUCT_CHANGE) |
118 | 123 | final products = new HashMap<ProductChange.ProductType, Boolean>() |
119 | | - if(appsecChange) { |
| 124 | + if (appsecChange) { |
120 | 125 | products.put(APPSEC, appsecEnabled) |
121 | 126 | } |
122 | | - if(profilerChange) { |
| 127 | + if (profilerChange) { |
123 | 128 | products.put(PROFILER, profilerEnabled) |
124 | 129 | } |
125 | | - if(dynamicInstrumentationChange) { |
| 130 | + if (dynamicInstrumentationChange) { |
126 | 131 | products.put(DYNAMIC_INSTRUMENTATION, dynamicInstrumentationEnabled) |
127 | 132 | } |
128 | 133 |
|
@@ -154,4 +159,33 @@ class TelemetryRequestBodySpecification extends Specification { |
154 | 159 | buf.read(bytes) |
155 | 160 | return new String(bytes) |
156 | 161 | } |
| 162 | + |
| 163 | + def 'Should propagate process tags when enabled #processTagsEnabled'() { |
| 164 | + setup: |
| 165 | + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "$processTagsEnabled") |
| 166 | + ProcessTags.reset() |
| 167 | + TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_STARTED) |
| 168 | + |
| 169 | + when: |
| 170 | + req.beginRequest(true) |
| 171 | + req.endRequest() |
| 172 | + |
| 173 | + then: |
| 174 | + def type = Types.newParameterizedType(Map, String, Object) |
| 175 | + def adapter = new Moshi.Builder().build().adapter(type) |
| 176 | + def parsed = (Map<String, Object>)adapter.fromJson(drainToString(req)) |
| 177 | + def parsedTags = ((Map<String, Object>)parsed.get("application")).get("process_tags") |
| 178 | + if (processTagsEnabled) { |
| 179 | + assert parsedTags == ProcessTags.tagsForSerialization.toString() |
| 180 | + } else { |
| 181 | + assert parsedTags == null |
| 182 | + } |
| 183 | + |
| 184 | + cleanup: |
| 185 | + injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false") |
| 186 | + ProcessTags.reset() |
| 187 | + |
| 188 | + where: |
| 189 | + processTagsEnabled << [true, false] |
| 190 | + } |
157 | 191 | } |
0 commit comments