Skip to content

Commit

Permalink
NH-37575: download agent from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverchuk committed Jul 3, 2024
1 parent 9ff38e6 commit 75fc1de
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 95 deletions.
110 changes: 107 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

permissions:
packages: write
contents: read
contents: write
id-token: write

env:
Expand All @@ -24,6 +24,109 @@ env:
STAGE_BUCKET: ${{ secrets.STAGE_BUCKET }}

jobs:
github_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Build agent
run: ./gradlew clean build -x test

- name: Pre-release and upload artifacts
run: |
VERSION=$(unzip -p agent/build/libs/solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }')
VERSION=$(echo $VERSION | sed 's/[^a-z0-9.-]//g') # remove illegal characters
VERSION="$VERSION.alpha"
echo "Current version is $VERSION"
response=$(curl -fs -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/releases \
-d '{"tag_name":"v'"$VERSION"'", "name":"v'"$VERSION"'", "body":"New release: v'"$VERSION"'", "draft":false, "prerelease":true}')
release_id=$(echo "$response" | jq -r '.id')
# Function to upload a file to GitHub release
upload_file_to_release() {
local release_id="$1"
local file_path="$2"
# Extract filename from file path
file_name=$(basename "$file_path")
# Upload file to GitHub release
curl -fs \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$file_path" \
"https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id/assets?name=$file_name"
}
# Upload file to GitHub release
upload_file_to_release "$release_id" "agent/build/libs/solarwinds-apm-agent.jar"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

github_release_clean:
runs-on: ubuntu-latest
if: always()
needs:
- benchmark
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Build agent
run: ./gradlew clean build -x test

- name: Clean up Pre-release
run: |
VERSION=$(unzip -p agent/build/libs/solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }')
VERSION=$(echo $VERSION | sed 's/[^a-z0-9.-]//g') # remove illegal characters
VERSION="$VERSION.alpha"
echo "Current version is $VERSION"
response=$(curl -fs -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/v$VERSION)
# Delete release
release_id=$(echo "$response" | jq -r '.id')
curl -fsL \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id
# Delete tag
curl -fsL \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/git/refs/tags/v$VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

s3-stage-upload: # this job uploads the jar to stage s3
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -84,7 +187,6 @@ jobs:
aws s3 cp VERSION \
s3://$STAGE_BUCKET/apm/java/latest/VERSION \
--acl public-read
build-test-images:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -388,7 +490,7 @@ jobs:
benchmark:
runs-on: ubuntu-latest
needs:
- s3-stage-upload
- github_release
steps:
- uses: actions/checkout@v4

Expand All @@ -402,6 +504,8 @@ jobs:
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin

- name: Benchmark test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: benchmark
run: ./gradlew test

Expand Down
1 change: 0 additions & 1 deletion benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
spotless {
java {
googleJavaFormat()
licenseHeaderFile(rootProject.file("../buildscripts/spotless.license.java"), "(package|import|public)")
target("src/**/*.java")
}
}
Expand Down
50 changes: 35 additions & 15 deletions benchmark/src/test/java/io/opentelemetry/OverheadTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public class OverheadTests {
private static GenericContainer<?> aoCollector;
private final NamingConventions namingConventions = new NamingConventions();
private final Map<String, Long> runDurations = new HashMap<>();
private static Set<String> verboseConfig = new HashSet<>(Arrays.asList(Strings.split(System.getenv("CONTAINER_LOGS") != null ? System.getenv("CONTAINER_LOGS") : "", '|')));
private static Set<String> verboseConfig =
new HashSet<>(
Arrays.asList(
Strings.split(
System.getenv("CONTAINER_LOGS") != null ? System.getenv("CONTAINER_LOGS") : "",
'|')));

@BeforeAll
static void setUp() {
Expand Down Expand Up @@ -104,14 +109,18 @@ void runAppOnce(TestConfig config, Agent agent) throws Exception {

if (verboseConfig.contains("all") || verboseConfig.contains("app")) {
String logs = petclinic.getLogs();
System.err.println(String.format("\n\n===============%s====================\n\n%s\n\n==============================="
, agent.getName(), logs));
System.err.println(
String.format(
"\n\n===============%s====================\n\n%s\n\n===============================",
agent.getName(), logs));
}

if (verboseConfig.contains("all") || verboseConfig.contains("collector")) {
String aoCollectorLogs = aoCollector.getLogs();
System.err.println(String.format("\n\n===============%s====================\n\n%s\n\n==============================="
, aoCollector.getDockerImageName(), aoCollectorLogs));
System.err.println(
String.format(
"\n\n===============%s====================\n\n%s\n\n===============================",
aoCollector.getDockerImageName(), aoCollectorLogs));
}
// This is required to get a graceful exit of the VM before testcontainers kills it forcibly.
// Without it, our jfr file will be empty.
Expand All @@ -136,22 +145,33 @@ 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)
.withCopyFileToContainer(MountableFile.forHostPath("./k6"), "/app")
.withCommand("run", "-u", "5", "-i", "200", "/app/basic.js")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy());
new GenericContainer<>(DockerImageName.parse("loadimpact/k6"))
.withNetwork(NETWORK)
.withCopyFileToContainer(MountableFile.forHostPath("./k6"), "/app")
.withCommand("run", "-u", "5", "-i", "200", "/app/basic.js")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy());
k6.start();
}

Expand Down
3 changes: 2 additions & 1 deletion benchmark/src/test/java/io/opentelemetry/agents/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class Agent {
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 NH_LATEST_RELEASE =
new Agent(LatestSolarwindsAgentResolver.useAOAgent ? "AO" : "NH", "latest Solarwinds agent");

private final String name;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
public class AgentResolver {

private final LatestAgentSnapshotResolver snapshotResolver = new LatestAgentSnapshotResolver();
private final LatestSolarwindsAgentResolver nighthawkAgentResolver = new LatestSolarwindsAgentResolver();
private final LatestSolarwindsAgentResolver nighthawkAgentResolver =
new LatestSolarwindsAgentResolver();

public Optional<Path> resolve(Agent agent) throws Exception {
if (Agent.NONE.equals(agent)) {
Expand Down
Loading

0 comments on commit 75fc1de

Please sign in to comment.