Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix windows benchmark fail #11698

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void runAppOnce(TestConfig config, Agent agent) throws Exception {
}

private void startRecording(Agent agent, GenericContainer<?> petclinic) throws Exception {
Path outFile = namingConventions.container.jfrFile(agent);
String outFile = namingConventions.container.jfrFile(agent);
String[] command = {
"jcmd",
"1",
Expand All @@ -123,16 +123,27 @@ private void startRecording(Agent agent, GenericContainer<?> petclinic) throws E
petclinic.execInContainer(command);
}

private void doWarmupPhase(TestConfig testConfig, GenericContainer<?> petclinic) throws IOException, InterruptedException {
System.out.println("Performing startup warming phase for " + testConfig.getWarmupSeconds() + " seconds...");
private void doWarmupPhase(TestConfig testConfig, GenericContainer<?> petclinic)
throws IOException, InterruptedException {
System.out.println(
"Performing startup warming phase for " + testConfig.getWarmupSeconds() + " seconds...");

// excluding the JFR recording from the warmup causes strange inconsistencies in the results
System.out.println("Starting disposable JFR warmup recording...");
String[] startCommand = {"jcmd", "1", "JFR.start", "settings=/app/overhead.jfc", "dumponexit=true", "name=warmup", "filename=warmup.jfr"};
String[] startCommand = {
"jcmd",
"1",
"JFR.start",
"settings=/app/overhead.jfc",
"dumponexit=true",
"name=warmup",
"filename=warmup.jfr"
};
petclinic.execInContainer(startCommand);

long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(testConfig.getWarmupSeconds());
while(System.currentTimeMillis() < deadline) {
long deadline =
System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(testConfig.getWarmupSeconds());
while (System.currentTimeMillis() < deadline) {
GenericContainer<?> k6 =
new GenericContainer<>(DockerImageName.parse("loadimpact/k6"))
.withNetwork(NETWORK)
Expand All @@ -151,7 +162,7 @@ private void doWarmupPhase(TestConfig testConfig, GenericContainer<?> petclinic)

private void writeStartupTimeFile(Agent agent, long start) throws IOException {
long delta = System.currentTimeMillis() - start;
Path startupPath = namingConventions.local.startupDurationFile(agent);
Path startupPath = Path.of(namingConventions.local.startupDurationFile(agent));
Files.writeString(startupPath, String.valueOf(delta));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.opentelemetry.agents.Agent;
import io.opentelemetry.config.TestConfig;
import io.opentelemetry.util.NamingConventions;
import java.nio.file.Path;
import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,7 +34,7 @@ public K6Container(
}

public GenericContainer<?> build() {
Path k6OutputFile = namingConventions.container.k6Results(agent);
String k6OutputFile = namingConventions.container.k6Results(agent);
return new GenericContainer<>(DockerImageName.parse("loadimpact/k6"))
.withNetwork(network)
.withNetworkAliases("k6")
Expand All @@ -52,7 +51,7 @@ public GenericContainer<?> build() {
"--rps",
String.valueOf(config.getMaxRequestRate()),
"--summary-export",
k6OutputFile.toString(),
k6OutputFile,
"/app/basic.js")
.withStartupCheckStrategy(
new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(15)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ private AppPerfResults readAgentResults(Agent agent, TestConfig config) {

private AppPerfResults.Builder addStartupTime(AppPerfResults.Builder builder, Agent agent)
throws IOException {
Path file = namingConvention.startupDurationFile(agent);
Path file = Path.of(namingConvention.startupDurationFile(agent));
long startupDuration = Long.parseLong(new String(Files.readAllBytes(file)).trim());
return builder.startupDurationMs(startupDuration);
}

private AppPerfResults.Builder addK6Results(AppPerfResults.Builder builder, Agent agent)
throws IOException {
Path k6File = namingConvention.k6Results(agent);
Path k6File = Path.of(namingConvention.k6Results(agent));
String json = new String(Files.readAllBytes(k6File));
double iterationAvg = read(json, "$.metrics.iteration_duration.avg");
double iterationP95 = read(json, "$.metrics.iteration_duration['p(95)']");
Expand All @@ -82,7 +82,7 @@ private static double read(String json, String jsonPath) {

private AppPerfResults.Builder addJfrResults(AppPerfResults.Builder builder, Agent agent)
throws IOException {
Path jfrFile = namingConvention.jfrFile(agent);
Path jfrFile = Path.of(namingConvention.jfrFile(agent));
return builder
.totalGCTime(readTotalGCTime(jfrFile))
.totalAllocated(readTotalAllocated(jfrFile))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.util;

import io.opentelemetry.agents.Agent;

public class ContainerNamingConvention implements NamingConvention {
private final String dir;

public ContainerNamingConvention(String dir) {
this.dir = dir;
}

public String k6Results(Agent agent) {

return String.join("/", dir, "k6_out_" + agent.getName() + ".json");
}

public String jfrFile(Agent agent) {
return String.join("/", dir, "petclinic-" + agent.getName() + ".jfr");
}

public String startupDurationFile(Agent agent) {
return String.join("/", dir, "startup-time-" + agent.getName() + ".txt");
}

public String root() {
return dir;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.util;

import io.opentelemetry.agents.Agent;
import java.nio.file.Paths;

public class LocalNamingConvention implements NamingConvention {
private final String dir;

public LocalNamingConvention(String dir) {
this.dir = dir;
}

public String k6Results(Agent agent) {
return Paths.get(dir, "k6_out_" + agent.getName() + ".json").toString();
}

public String jfrFile(Agent agent) {
return Paths.get(dir, "petclinic-" + agent.getName() + ".jfr").toString();
}

public String startupDurationFile(Agent agent) {
return Paths.get(dir, "startup-time-" + agent.getName() + ".txt").toString();
}

public String root() {
return dir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,34 @@
package io.opentelemetry.util;

import io.opentelemetry.agents.Agent;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* This utility class provides the standard file naming conventions, primarily for files that are
* shared between containers and the test runner. It consolidates the naming logic into one place to
* ensure consistency, reduce duplication, and decrease errors.
*/
public class NamingConvention {

private final String dir;

public NamingConvention(String dir) {
this.dir = dir;
}

public interface NamingConvention {
/**
* Returns a path to the location of the k6 results json file.
* Returns a path string to the location of the k6 results json file.
*
* @param agent The agent to get results file path for
*/
public Path k6Results(Agent agent) {
return Paths.get(dir, "k6_out_" + agent.getName() + ".json");
}
String k6Results(Agent agent);

/**
* Returns a path to the location of the jfr output file for a given agent run.
* Returns a path string to the location of the jfr output file for a given agent run.
*
* @param agent The agent to get the jfr file path for.
*/
public Path jfrFile(Agent agent) {
return Paths.get(dir, "petclinic-" + agent.getName() + ".jfr");
}
String jfrFile(Agent agent);

/**
* Returns the path to the file that contains the startup duration for a given agent run.
* Returns the path string to the file that contains the startup duration for a given agent run.
*
* @param agent The agent to get the startup duration for.
*/
public Path startupDurationFile(Agent agent) {
return Paths.get(dir, "startup-time-" + agent.getName() + ".txt");
}
String startupDurationFile(Agent agent);

/** Returns the root path that this naming convention was configured with. */
public String root() {
return dir;
}
String root();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@

package io.opentelemetry.util;

/** An container to hold both the local and container naming conventions. */
/** A container to hold both the local and container naming conventions. */
public class NamingConventions {

public final NamingConvention container = new NamingConvention("/results");
public final NamingConvention local = new NamingConvention(".");
public final NamingConvention container = new ContainerNamingConvention("/results");
123liuziming marked this conversation as resolved.
Show resolved Hide resolved
public final NamingConvention local = new LocalNamingConvention(".");

/** @return Root path for the local naming convention (where results are output) */
/**
* @return Root path for the local naming convention (where results are output)
*/
public String localResults() {
return local.root();
}

/** @return Root path for the container naming convention (where results are output) */
/**
* @return Root path for the container naming convention (where results are output)
*/
public String containerResults() {
return container.root();
}
Expand Down
Loading