Skip to content

Commit ab205f6

Browse files
authored
Check logs for errors at smoke tests cleanup (#8111)
1 parent 30bb13b commit ab205f6

File tree

17 files changed

+156
-134
lines changed

17 files changed

+156
-134
lines changed

dd-smoke-tests/armeria-grpc/src/test/groovy/datadog/smoketest/ArmeriaSmokeTest.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class ArmeriaSmokeTest extends AbstractServerSmokeTest {
5757
})
5858
waitForTraceCount(totalInvocations) >= totalInvocations
5959
validateLogInjection() == totalInvocations
60-
checkLogPostExit()
61-
!logHasErrors
6260
}
6361

6462
void doAndValidateRequest(int id) {

dd-smoke-tests/asm-standalone-billing/src/test/groovy/datadog/smoketest/asmstandalonebilling/AsmStandaloneBillingSmokeTest.groovy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ class AsmStandaloneBillingSmokeTest extends AbstractAsmStandaloneBillingSmokeTes
6464
def computedStatsHeader = lastTraceRequestHeaders.get('Datadog-Client-Computed-Stats')
6565
assert computedStatsHeader != null && computedStatsHeader == 'true'
6666

67-
then:'metrics should be disabled'
68-
checkLogPostExit { log ->
69-
return log.contains('datadog.trace.agent.common.metrics.MetricsAggregatorFactory - tracer metrics disabled')
70-
}
67+
then: 'metrics should be disabled'
68+
isLogPresent { it.contains('datadog.trace.agent.common.metrics.MetricsAggregatorFactory - tracer metrics disabled') }
7169
}
7270

7371
void 'test _dd.p.appsec propagation for appsec event'() {

dd-smoke-tests/custom-systemloader/src/test/groovy/datadog/smoketest/CustomSystemLoaderSmokeTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ class CustomSystemLoaderSmokeTest extends AbstractSmokeTest {
3030
def "resource types loaded by custom system class-loader are transformed"() {
3131
when:
3232
testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
33+
34+
then:
35+
testedProcess.exitValue() == 0
3336
int loadedResources = 0
3437
int transformedResources = 0
35-
checkLogPostExit {
38+
forEachLogLine { String it ->
3639
if (it =~ /Loading sample.app.Resource[$]Test[1-3] from TestLoader/) {
3740
loadedResources++
3841
}
3942
if (it =~ /Transformed.*class=sample.app.Resource[$]Test[1-3].*classloader=datadog.smoketest.systemloader.TestLoader/) {
4043
transformedResources++
4144
}
4245
}
43-
then:
44-
testedProcess.exitValue() == 0
4546
loadedResources == 3
4647
transformedResources == 3
47-
!logHasErrors
4848
}
4949
}

dd-smoke-tests/iast-util/src/main/java/datadog/smoketest/springboot/controller/SsrfController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public String okHttp2(@RequestParam(value = "url") final String url) {
8080
} catch (final Exception e) {
8181
}
8282
client.getDispatcher().getExecutorService().shutdown();
83-
client.getConnectionPool().evictAll();
83+
com.squareup.okhttp.ConnectionPool pool = client.getConnectionPool();
84+
if (pool != null) {
85+
pool.evictAll();
86+
}
8487
return "ok";
8588
}
8689

dd-smoke-tests/iast-util/src/testFixtures/groovy/datadog/smoketest/AbstractIastServerSmokeTest.groovy

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ abstract class AbstractIastServerSmokeTest extends AbstractServerSmokeTest {
5454
try {
5555
processTestLogLines(closure)
5656
} catch (TimeoutException toe) {
57-
checkLogPostExit(closure)
58-
if (!found) {
59-
throw new AssertionError("No matching tainted found. Tainteds found: ${new JsonBuilder(tainteds).toPrettyString()}")
60-
}
57+
assert found, "No matching tainted found. Tainteds found: ${new JsonBuilder(tainteds).toPrettyString()}"
6158
}
6259
}
6360

@@ -83,10 +80,7 @@ abstract class AbstractIastServerSmokeTest extends AbstractServerSmokeTest {
8380
try {
8481
processTestLogLines(closure)
8582
} catch (TimeoutException toe) {
86-
checkLogPostExit(closure)
87-
if (!found) {
88-
throw new AssertionError("No matching vulnerability found. Vulnerabilities found: ${new JsonBuilder(vulnerabilities).toPrettyString()}")
89-
}
83+
assert found, "No matching vulnerability found. Vulnerabilities found: ${new JsonBuilder(vulnerabilities).toPrettyString()}"
9084
}
9185
}
9286

dd-smoke-tests/iast-util/src/testFixtures/groovy/datadog/smoketest/AbstractIastSpringBootTest.groovy

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,22 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
3939
]
4040
}
4141

42-
void 'IAST subsystem starts'() {
43-
given: 'an initial request has succeeded'
44-
String url = "http://localhost:${httpPort}/greeting"
45-
def request = new Request.Builder().url(url).get().build()
46-
client.newCall(request).execute()
42+
@Override
43+
boolean isErrorLog(String log) {
44+
if (log.contains('no such algorithm: DES for provider SUN')) {
45+
return false
46+
}
4747

48-
when: 'logs are read'
49-
String startMsg = null
50-
String errorMsg = null
51-
checkLogPostExit {
52-
if (it.contains('Not starting IAST subsystem')) {
53-
errorMsg = it
54-
}
55-
if (it.contains('IAST is starting')) {
56-
startMsg = it
57-
}
58-
// Check that there's no logged exception about missing classes from Datadog.
59-
// We had this problem before with JDK9StackWalker.
60-
if (it.contains('java.lang.ClassNotFoundException: datadog/')) {
61-
errorMsg = it
62-
}
48+
if (super.isErrorLog(log) || log.contains('Not starting IAST subsystem')) {
49+
return true
50+
}
51+
// Check that there's no logged exception about missing classes from Datadog.
52+
// We had this problem before with JDK9StackWalker.
53+
if (log.contains('java.lang.ClassNotFoundException: datadog/')) {
54+
return true
6355
}
6456

65-
then: 'there are no errors in the log and IAST has started'
66-
errorMsg == null
67-
startMsg != null
68-
!logHasErrors
57+
return false
6958
}
7059

7160
void 'default home page without errors'() {
@@ -82,9 +71,6 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
8271
responseBodyStr.contains('Sup Dawg')
8372
response.body().contentType().toString().contains('text/plain')
8473
response.code() == 200
85-
86-
checkLogPostExit()
87-
!logHasErrors
8874
}
8975

9076
void 'Multipart Request parameters'() {
@@ -329,13 +315,21 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
329315
def request = new Request.Builder().url(url).get().build()
330316

331317
when: 'ensure the controller is loaded'
332-
client.newCall(request).execute()
318+
def resp = client.newCall(request).execute()
333319

334-
then: 'a vulnerability pops in the logs (startup traces might not always be available)'
335-
hasVulnerabilityInLogs { vul ->
336-
vul.type == 'WEAK_HASH' &&
337-
vul.evidence.value == 'SHA1' &&
338-
vul.location.spanId > 0
320+
then:
321+
resp.code() == 200
322+
resp.close()
323+
324+
and: 'a vulnerability pops in the logs (startup traces might not always be available)'
325+
boolean found = false
326+
isLogPresent { String log ->
327+
def vulns = parseVulnerabilitiesLog(log)
328+
vulns.any { vul ->
329+
vul.type == 'WEAK_HASH' &&
330+
vul.evidence.value == 'SHA1' &&
331+
vul.location.spanId > 0
332+
}
339333
}
340334
}
341335

@@ -1060,8 +1054,10 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
10601054

10611055
then:
10621056
response.successful
1063-
hasVulnerabilityInLogs { vul ->
1064-
vul.type == 'SESSION_REWRITING'
1057+
// Vulnerability may have been detected in a previous request instead, check the full logs.
1058+
isLogPresent { String log ->
1059+
def vulns = parseVulnerabilitiesLog(log)
1060+
vulns.any { it.type == 'SESSION_REWRITING' }
10651061
}
10661062
}
10671063

dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class Java9ModulesSmokeTest extends AbstractSmokeTest {
2323
processBuilder.directory(new File(buildDirectory))
2424
}
2525

26+
@Override
27+
boolean isErrorLog(String line) {
28+
// FIXME: Too many bootstrap errors.
29+
return false
30+
}
31+
2632
def "Module application runs correctly"() {
2733
expect:
2834
assert testedProcess.waitFor(TIMEOUT_SECS, SECONDS)

dd-smoke-tests/jboss-modules/src/test/groovy/datadog/smoketest/AbstractModulesSmokeTest.groovy

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,20 @@ abstract class AbstractModulesSmokeTest extends AbstractSmokeTest {
2828
return processBuilder
2929
}
3030

31+
@Override
32+
boolean isErrorLog(String log) {
33+
super.isErrorLog(log) || log.contains("Cannot resolve type description") || log.contains("Instrumentation muzzled")
34+
}
35+
3136
def "example application runs without errors"() {
3237
when:
3338
testedProcess.waitFor()
34-
boolean instrumentedMessageClient = false
35-
checkLogPostExit {
36-
// check for additional OSGi class-loader issues
37-
if (it.contains("Cannot resolve type description") ||
38-
it.contains("Instrumentation muzzled")) {
39-
println it
40-
logHasErrors = true
41-
}
42-
if (it.contains("Transformed - instrumentation.target.class=datadog.smoketest.jbossmodules.client.MessageClient")) {
43-
println it
44-
instrumentedMessageClient = true
45-
}
46-
}
4739

48-
then:
40+
then: 'MessageClient is transformed'
4941
testedProcess.exitValue() == 0
50-
instrumentedMessageClient
51-
!logHasErrors
42+
processTestLogLines {
43+
it.contains("Transformed - instrumentation.target.class=datadog.smoketest.jbossmodules.client.MessageClient")
44+
}
5245
}
5346

5447
@Override

dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ abstract class LogInjectionSmokeTest extends AbstractSmokeTest {
104104
return processBuilder
105105
}
106106

107+
@Override
108+
boolean isErrorLog(String log) {
109+
// Exclude some errors that we consistently get because of the logging setups used here:
110+
if (log.contains('no applicable action for [immediateFlush]')) {
111+
return false
112+
}
113+
if (log.contains('JSONLayout contains an invalid element or attribute')) {
114+
return false
115+
}
116+
if (log.contains('JSONLayout has no parameter that matches element')) {
117+
return false
118+
}
119+
return super.isErrorLog(log)
120+
}
121+
107122
@Override
108123
def logLevel() {
109124
return "debug"

dd-smoke-tests/osgi/src/test/groovy/datadog/smoketest/AbstractOSGiSmokeTest.groovy

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,20 @@ abstract class AbstractOSGiSmokeTest extends AbstractSmokeTest {
3737

3838
abstract List<String> frameworkArguments()
3939

40+
@Override
41+
boolean isErrorLog(String log) {
42+
super.isErrorLog(log) || log.contains("Cannot resolve type description") || log.contains("Instrumentation muzzled")
43+
}
44+
4045
def "example application runs without errors"() {
4146
when:
4247
testedProcess.waitFor()
43-
boolean instrumentedMessageClient = false
44-
checkLogPostExit {
45-
// check for additional OSGi class-loader issues
46-
if (it.contains("Cannot resolve type description") ||
47-
it.contains("Instrumentation muzzled")) {
48-
println it
49-
logHasErrors = true
50-
}
51-
if (it.contains("Transformed - instrumentation.target.class=datadog.smoketest.osgi.client.MessageClient")) {
52-
println it
53-
instrumentedMessageClient = true
54-
}
55-
}
5648

5749
then:
5850
testedProcess.exitValue() == 0
59-
instrumentedMessageClient
60-
!logHasErrors
51+
processTestLogLines {
52+
it.contains("Transformed - instrumentation.target.class=datadog.smoketest.osgi.client.MessageClient")
53+
}
6154
}
6255

6356
@Override

dd-smoke-tests/quarkus-native/src/test/groovy/datadog/smoketest/QuarkusNativeSmokeTest.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ abstract class QuarkusNativeSmokeTest extends AbstractServerSmokeTest {
5555
})
5656
waitForTraceCount(totalInvocations) == totalInvocations
5757
validateLogInjection(resourceName()) == totalInvocations
58-
checkLogPostExit()
59-
!logHasErrors
6058
}
6159

6260
void doAndValidateRequest(int id) {

dd-smoke-tests/quarkus/src/test/groovy/datadog/smoketest/QuarkusSmokeTest.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ abstract class QuarkusSmokeTest extends AbstractServerSmokeTest {
5757
})
5858
waitForTraceCount(totalInvocations) == totalInvocations
5959
validateLogInjection(resourceName()) == totalInvocations
60-
checkLogPostExit()
61-
!logHasErrors
6260
}
6361

6462
void doAndValidateRequest(int id) {

dd-smoke-tests/spring-boot-3.0-native/src/test/groovy/SpringBootNativeInstrumentationTest.groovy

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
6060
false
6161
}
6262

63+
@Override
64+
boolean isErrorLog(String log) {
65+
// Check that there are no ClassNotFound errors printed from bad reflect-config.json
66+
super.isErrorLog(log) || log.contains("ClassNotFoundException")
67+
}
68+
6369
def "check native instrumentation"() {
6470
setup:
6571
String url = "http://localhost:${httpPort}/hello"
@@ -81,18 +87,6 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
8187
LockSupport.parkNanos(1_000_000)
8288
}
8389
countJfrs() > 0
84-
85-
when:
86-
checkLogPostExit {
87-
// Check that there are no ClassNotFound errors printed from bad reflect-config.json
88-
if (it.contains("ClassNotFoundException")) {
89-
println "Found ClassNotFoundException in log: ${it}"
90-
logHasErrors = true
91-
}
92-
}
93-
94-
then:
95-
!logHasErrors
9690
}
9791

9892
int countJfrs() {

dd-smoke-tests/spring-boot-rabbit/src/test/groovy/datadog/smoketest/SpringBootRabbitIntegrationTest.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ class SpringBootRabbitIntegrationTest extends AbstractServerSmokeTest {
8989
return expected
9090
}
9191

92+
@Override
93+
boolean isErrorLog(String log) {
94+
if (log.contains('org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer - Failed to check/redeclare auto-delete queue(s).')) {
95+
return false
96+
}
97+
return super.isErrorLog(log)
98+
}
99+
92100
def "check message #message roundtrip"() {
93101
setup:
94102
String url = "http://localhost:${httpPort}/roundtrip/${message}"

dd-smoke-tests/springboot/src/test/groovy/datadog/smoketest/IastSpringBootSmokeTest.groovy

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ class IastSpringBootSmokeTest extends AbstractIastSpringBootTest {
4040

4141
then:
4242
response.successful
43-
hasVulnerabilityInLogs {
44-
vul ->
45-
vul.type == 'HARDCODED_SECRET'
46-
&& vul.location.method == 'hardcodedSecret'
47-
&& vul.location.path == 'datadog.smoketest.springboot.controller.HardcodedSecretController'
48-
&& vul.location.line == 11
49-
&& vul.evidence.value == 'age-secret-key'
43+
isLogPresent {
44+
String log ->
45+
def vulns = parseVulnerabilitiesLog(log)
46+
vulns.any {
47+
vul ->
48+
vul.type == 'HARDCODED_SECRET'
49+
&& vul.location.method == 'hardcodedSecret'
50+
&& vul.location.path == 'datadog.smoketest.springboot.controller.HardcodedSecretController'
51+
&& vul.location.line == 11
52+
&& vul.evidence.value == 'age-secret-key'
53+
}
5054
}
5155
}
5256

dd-smoke-tests/src/main/groovy/datadog/smoketest/AbstractSmokeTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ abstract class AbstractSmokeTest extends ProcessManager {
243243

244244
def cleanupSpec() {
245245
stopServer()
246+
assertNoErrorLogs()
246247
}
247248

248249
def startServer() {

0 commit comments

Comments
 (0)