Skip to content

Commit

Permalink
fix(smoke-tests): Replace JAVA_TOOL_OPTIONS by jvm.options openlibert…
Browse files Browse the repository at this point in the history
…y configuration file

JAVA_TOOL_OPTIONS is limited to 1024 characters and it starts reaching the limit.
  • Loading branch information
PerfectSlayer committed Nov 28, 2024
1 parent 7c67b63 commit e5ad0f5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import okhttp3.Request
import spock.lang.Requires
import spock.lang.Shared

import java.util.stream.Collectors
import java.nio.file.FileSystems
import java.nio.file.Files

// This test currently fails on IBM JVMs
@Requires({ !Platform.isJ9() })
Expand All @@ -24,30 +25,40 @@ class SpringBootOpenLibertySmokeTest extends AbstractServerSmokeTest {
List<String> command = new ArrayList<>()
command.add(javaPath())

command.addAll((String[]) ["-jar", openLibertyShadowJar, "--server.port=${httpPort}"])
command.addAll("-jar", openLibertyShadowJar, "--server.port=${httpPort}" as String)

List<String> envParams = new ArrayList<>()
envParams.addAll(defaultJavaProperties)
envParams.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter",
List<String> jvmOptions = new ArrayList<>()
jvmOptions.addAll(defaultJavaProperties)
jvmOptions.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter" as String,
"-Ddd.jmxfetch.enabled=false",
"-Ddd.appsec.enabled=true",
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug",
"-Ddd.iast.enabled=true", "-Ddd.iast.request-sampling=100",
"-Ddd.integration.spring-boot.enabled=true"
)


String javaToolOptions = envParams.stream().collect(Collectors.joining(" "))

injectOpenLibertyJvmOptions(jvmOptions)

ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.environment().put("JAVA_TOOL_OPTIONS", javaToolOptions)
processBuilder.environment().put('WLP_JAR_EXTRACT_ROOT', 'application')
processBuilder.directory(new File(buildDirectory))
return processBuilder
}

void injectOpenLibertyJvmOptions(List<String> options) {
def appUri = URI.create("jar:file:$openLibertyShadowJar")
try (def fs = FileSystems.newFileSystem(appUri, [:])) {
def jvmOptionFile = fs.getPath( 'wlp', 'usr', 'servers', 'defaultServer', 'jvm.options')
try (def writer = Files.newBufferedWriter(jvmOptionFile)) {
options.each {
writer.write(it)
writer.newLine()
}
}
}
}

@Override
File createTemporaryFile() {
return new File("${buildDirectory}/tmp/springboot-openliberty.out")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package datadog.smoketest


import datadog.trace.api.Platform
import datadog.trace.test.agent.decoder.DecodedSpan
import okhttp3.Request
import spock.lang.Requires
import spock.lang.Shared
import spock.util.concurrent.PollingConditions

import java.nio.file.FileSystems
import java.nio.file.Files
import java.util.function.Function
import java.util.stream.Collectors

// This test currently fails on IBM JVMs
@Requires({ !Platform.isJ9() })
class SpringBootOpenLibertySmokeVulnerabilityTest extends AbstractServerSmokeTest {

@Shared
int totalInvocations = 100

@Shared
String openLibertyShadowJar = System.getProperty("datadog.smoketest.openliberty.jar.path")

Expand All @@ -26,29 +23,39 @@ class SpringBootOpenLibertySmokeVulnerabilityTest extends AbstractServerSmokeTes
List<String> command = new ArrayList<>()
command.add(javaPath())

command.addAll((String[]) ["-jar", openLibertyShadowJar, "--server.port=${httpPort}"])
command.addAll("-jar", openLibertyShadowJar, "--server.port=${httpPort}" as String)

List<String> envParams = new ArrayList<>()
envParams.addAll(defaultJavaProperties)
envParams.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter",
List<String> jvmOptions = new ArrayList<>()
jvmOptions.addAll(defaultJavaProperties)
jvmOptions.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter" as String,
"-Ddd.jmxfetch.enabled=false",
"-Ddd.appsec.enabled=true",
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug",
"-Ddd.iast.enabled=true", "-Ddd.iast.request-sampling=100"
)


String javaToolOptions = envParams.stream().collect(Collectors.joining(" "))

injectOpenLibertyJvmOptions(jvmOptions)

ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.environment().put("JAVA_TOOL_OPTIONS", javaToolOptions)
processBuilder.environment().put('WLP_JAR_EXTRACT_ROOT', 'application')
processBuilder.directory(new File(buildDirectory))
return processBuilder
}

void injectOpenLibertyJvmOptions(List<String> options) {
def appUri = URI.create("jar:file:$openLibertyShadowJar")
try (def fs = FileSystems.newFileSystem(appUri, [:])) {
def jvmOptionFile = fs.getPath( 'wlp', 'usr', 'servers', 'defaultServer', 'jvm.options')
try (def writer = Files.newBufferedWriter(jvmOptionFile)) {
options.each {
writer.write(it)
writer.newLine()
}
}
}
}

@Override
File createTemporaryFile() {
return new File("${buildDirectory}/tmp/springboot-openliberty.out")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import okhttp3.Request
import spock.lang.Requires
import spock.lang.Shared

import java.util.stream.Collectors
import java.nio.file.FileSystems
import java.nio.file.Files

// This test currently fails on IBM JVMs
@Requires({ !Platform.isJ9() })
Expand All @@ -26,10 +27,10 @@ class SpringBootOpenLibertySmokeTest extends AbstractServerSmokeTest {

command.addAll((String[]) ["-jar", openLibertyShadowJar, "--server.port=${httpPort}"])

List<String> envParams = new ArrayList<>()
envParams.addAll(defaultJavaProperties)
envParams.addAll([
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()}:includeService,DDAgentWriter",
List<String> jvmOptions = new ArrayList<>()
jvmOptions.addAll(defaultJavaProperties)
jvmOptions.addAll([
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()}:includeService,DDAgentWriter" as String,
"-Ddd.jmxfetch.enabled=false",
"-Ddd.appsec.enabled=true",
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
Expand All @@ -38,18 +39,27 @@ class SpringBootOpenLibertySmokeTest extends AbstractServerSmokeTest {
"-Ddd.iast.request-sampling=100",
"-Ddd.integration.spring-boot.enabled=true"
])


String javaToolOptions = envParams.stream().collect(Collectors.joining(" "))

injectOpenLibertyJvmOptions(jvmOptions)

ProcessBuilder processBuilder = new ProcessBuilder(command)
System.err.println(javaToolOptions)
processBuilder.environment().put("JAVA_TOOL_OPTIONS", javaToolOptions)
processBuilder.environment().put('WLP_JAR_EXTRACT_ROOT', 'application')
processBuilder.directory(new File(buildDirectory))
return processBuilder
}

void injectOpenLibertyJvmOptions(List<String> options) {
def appUri = URI.create("jar:file:$openLibertyShadowJar")
try (def fs = FileSystems.newFileSystem(appUri, [:])) {
def jvmOptionFile = fs.getPath( 'wlp', 'usr', 'servers', 'defaultServer', 'jvm.options')
try (def writer = Files.newBufferedWriter(jvmOptionFile)) {
options.each {
writer.write(it)
writer.newLine()
}
}
}
}

@Override
def inferServiceName() {
false // will use spring properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import spock.lang.Requires
import spock.lang.Shared
import spock.util.concurrent.PollingConditions

import java.nio.file.FileSystems
import java.nio.file.Files
import java.util.function.Function
import java.util.stream.Collectors

// This test currently fails on IBM JVMs
@Requires({ !Platform.isJ9() })
class SpringBootOpenLibertySmokeVulnerabilityTest extends AbstractServerSmokeTest {

@Shared
int totalInvocations = 100

@Shared
String openLibertyShadowJar = System.getProperty("datadog.smoketest.openliberty.jar.path")

Expand All @@ -26,29 +24,39 @@ class SpringBootOpenLibertySmokeVulnerabilityTest extends AbstractServerSmokeTes
List<String> command = new ArrayList<>()
command.add(javaPath())

command.addAll((String[]) ["-jar", openLibertyShadowJar, "--server.port=${httpPort}"])
command.addAll("-jar", openLibertyShadowJar, "--server.port=${httpPort}" as String)

List<String> envParams = new ArrayList<>()
envParams.addAll(defaultJavaProperties)
envParams.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter",
List<String> jvmOptions = new ArrayList<>()
jvmOptions.addAll(defaultJavaProperties)
jvmOptions.addAll(
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter" as String,
"-Ddd.jmxfetch.enabled=false",
"-Ddd.appsec.enabled=true",
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug",
"-Ddd.iast.enabled=true", "-Ddd.iast.request-sampling=100"
)


String javaToolOptions = envParams.stream().collect(Collectors.joining(" "))

injectOpenLibertyJvmOptions(jvmOptions)

ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.environment().put("JAVA_TOOL_OPTIONS", javaToolOptions)
processBuilder.environment().put('WLP_JAR_EXTRACT_ROOT', 'application')
processBuilder.directory(new File(buildDirectory))
return processBuilder
}

void injectOpenLibertyJvmOptions(List<String> options) {
def appUri = URI.create("jar:file:$openLibertyShadowJar")
try (def fs = FileSystems.newFileSystem(appUri, [:])) {
def jvmOptionFile = fs.getPath( 'wlp', 'usr', 'servers', 'defaultServer', 'jvm.options')
try (def writer = Files.newBufferedWriter(jvmOptionFile)) {
options.each {
writer.write(it)
writer.newLine()
}
}
}
}

@Override
File createTemporaryFile() {
return new File("${buildDirectory}/tmp/springboot-openliberty.out")
Expand Down

0 comments on commit e5ad0f5

Please sign in to comment.