Skip to content

Commit

Permalink
NH-37575: update benchmark components
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverchuk committed Jul 10, 2024
1 parent 64b7a06 commit d91a134
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand All @@ -56,7 +56,7 @@ jobs:

# Autobuild fails so use custom build steps
- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
Expand Down
13 changes: 7 additions & 6 deletions benchmark/src/test/java/io/opentelemetry/agents/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public class Agent {
"https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar";

public static final Agent NONE = new Agent("none", "no agent at all");
public static final Agent LATEST_RELEASE =
new Agent("latest", "latest mainstream release", OTEL_LATEST);
public static final Agent LATEST_SNAPSHOT =
new Agent("snapshot", "latest available snapshot version from main");
public static final Agent NH_LATEST_RELEASE =
new Agent(LatestSolarwindsAgentResolver.useAOAgent ? "AO" : "NH", "latest Solarwinds agent");
public static final Agent OTEL_LATEST_RELEASE =
new Agent("OTEL latest", "latest mainstream release", OTEL_LATEST);
public static final Agent OTEL_LATEST_SNAPSHOT =
new Agent("OTEL snapshot", "latest available snapshot version from main");
public static final Agent SWO_SNAPSHOT_RELEASE =
new Agent("SWO-snapshot", "Snapshot Solarwinds agent");
public static final Agent SWO_GA_RELEASE = new Agent("SWO-ga", "GA Solarwinds agent");

private final String name;
private final String description;
Expand Down
15 changes: 10 additions & 5 deletions benchmark/src/test/java/io/opentelemetry/agents/AgentResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
public class AgentResolver {

private final LatestAgentSnapshotResolver snapshotResolver = new LatestAgentSnapshotResolver();
private final LatestSolarwindsAgentResolver nighthawkAgentResolver =
new LatestSolarwindsAgentResolver();
private final SnapshotResolver swoSnapshotResolver = new SnapshotResolver();
private final GaResolver swoGaResolver = new GaResolver();

public Optional<Path> resolve(Agent agent) throws Exception {
if (Agent.NONE.equals(agent)) {
return Optional.empty();
}
if (Agent.LATEST_SNAPSHOT.equals(agent)) {

if (Agent.OTEL_LATEST_SNAPSHOT.equals(agent)) {
return snapshotResolver.resolve();
} else if (Agent.NH_LATEST_RELEASE.equals(agent)) {
return nighthawkAgentResolver.resolve();
} else if (Agent.SWO_SNAPSHOT_RELEASE.equals(agent)) {
return swoSnapshotResolver.resolve();
} else if (Agent.SWO_GA_RELEASE.equals(agent)) {
return swoGaResolver.resolve();
}

if (agent.hasUrl()) {
return Optional.of(downloadAgent(agent.getUrl()));
}

throw new IllegalArgumentException("Unknown agent: " + agent);
}

Expand Down
128 changes: 128 additions & 0 deletions benchmark/src/test/java/io/opentelemetry/agents/GaResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.opentelemetry.agents;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Optional;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.testcontainers.shaded.com.fasterxml.jackson.core.type.TypeReference;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;

public class GaResolver {
private static final String GA_URL = "https://api.github.com/repos/solarwinds/apm-java/releases";
private static final String SWO_AGENT_JAR_NAME = "solarwinds-apm-agent.jar";

Optional<Path> resolve() throws Exception {
return Optional.of(downloadAgent());
}

private Path downloadAgent() throws Exception {
String assetURL = null;
OkHttpClient client = new OkHttpClient();
Request request =
new Request.Builder()
.url(GA_URL)
.header("Authorization", "token " + System.getenv("GITHUB_TOKEN"))
.header("Accept", "application/vnd.github.v3+json")
.build();

try (Response response = client.newCall(request).execute()) {
assert response.body() != null;
byte[] raw = response.body().bytes();

ObjectMapper mapper = new ObjectMapper();
List<GithubRelease> releases =
mapper.readValue(raw, new TypeReference<List<GithubRelease>>() {});

outerLoop:
for (GithubRelease release : releases) {
for (Asset asset : release.assets) {
if (asset.name.equals(SWO_AGENT_JAR_NAME)) {
assetURL = asset.url;
break outerLoop;
}
}
}

if (assetURL == null) {
throw new RuntimeException("Asset url not found for the NH agent.");
}
}

Request downloadRequest =
new Request.Builder()
.url(assetURL)
.header("Authorization", "token " + System.getenv("GITHUB_TOKEN"))
.header("Accept", "application/octet-stream")
.build();

Path path = Paths.get(".", SWO_AGENT_JAR_NAME);
try (Response response = client.newCall(downloadRequest).execute()) {
assert response.body() != null;
byte[] fileRaw = response.body().bytes();
Files.write(
path,
fileRaw,
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING);
}
return path;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class GithubRelease {
private List<Asset> assets;

public List<Asset> getAssets() {
return assets;
}

public void setAssets(List<Asset> assets) {
this.assets = assets;
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Asset {
private String url;
private String name;

public String getUrl() {
return url;
}

public String getName() {
return name;
}

public void setUrl(String url) {
this.url = url;
}

public void setName(String name) {
this.name = name;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.opentelemetry.agents;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Optional;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class SnapshotResolver {
private static final String SNAPSHOT_URL =
"https://agent-binaries.global.st-ssp.solarwinds.com/apm/java/latest/solarwinds-apm-agent.jar";
private static final String SWO_AGENT_JAR_NAME = "solarwinds-apm-agent.jar";

Optional<Path> resolve() throws Exception {
return Optional.of(downloadAgent());
}

private Path downloadAgent() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request =
new Request.Builder()
.url(SNAPSHOT_URL)
.header("Authorization", "token " + System.getenv("GITHUB_TOKEN"))
.header("Accept", "application/octet-stream")
.build();

Path path = Paths.get(".", SWO_AGENT_JAR_NAME);
try (Response response = client.newCall(request).execute()) {
assert response.body() != null;
byte[] fileRaw = response.body().bytes();
Files.write(
path,
fileRaw,
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING);
}
return path;
}
}
8 changes: 6 additions & 2 deletions benchmark/src/test/java/io/opentelemetry/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public enum Configs {
RELEASE(
TestConfig.builder()
.name("release")
.description("compares no agent, latest Otel standard, and latest NH/AO agents")
.withAgents(Agent.LATEST_RELEASE, Agent.NH_LATEST_RELEASE, Agent.NONE)
.description("compares no agent, latest Otel standard, and latest SWO agents")
.withAgents(
Agent.OTEL_LATEST_RELEASE,
Agent.SWO_SNAPSHOT_RELEASE,
Agent.SWO_GA_RELEASE,
Agent.NONE)
.warmupSeconds(60)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import io.opentelemetry.agents.Agent;
import io.opentelemetry.agents.AgentResolver;
import io.opentelemetry.agents.LatestSolarwindsAgentResolver;
import io.opentelemetry.util.NamingConventions;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -89,7 +88,7 @@ public GenericContainer<?> build() throws Exception {
@NotNull
private String[] buildCommandline(Optional<Path> agentJar) {
List<String> result = new ArrayList<>();
if (!agent.equals(Agent.NH_LATEST_RELEASE)) {
if (agent.equals(Agent.OTEL_LATEST_RELEASE)) {
result.addAll(
Arrays.asList(
"java",
Expand All @@ -103,22 +102,15 @@ private String[] buildCommandline(Optional<Path> agentJar) {
result.addAll(
Arrays.asList(
"java",
"-Dotel.solarwinds.service.key="
"-Dsw.apm.service.key="
+ System.getenv("SW_APM_SERVICE_KEY")
+ ":sw-java-benchmark"));
}

result.addAll(this.agent.getAdditionalJvmArgs());
agentJar.ifPresent(
path ->
result.add(
"-javaagent:/app/"
+ path.getFileName()
+ (LatestSolarwindsAgentResolver.useAOAgent
? "=service_key="
+ System.getenv("SW_APM_SERVICE_KEY")
+ ":sw-java-benchmark"
: "")));
agentJar.ifPresent(path -> result.add("-javaagent:/app/" + path.getFileName()));
result.add("-jar");

result.add("/app/spring-petclinic-rest.jar");
System.err.println("Running app with command:\n" + String.join(" ", result));
return result.toArray(new String[] {});
Expand Down

0 comments on commit d91a134

Please sign in to comment.