Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
39 changes: 28 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,46 @@ jobs:
run: ./gradlew build -x test

test:
name: test (${{ matrix.test-java-version }})
runs-on: ubuntu-latest
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- macos-13
- ubuntu-latest
- windows-latest
test-java-version:
- 8
- 11
- 17
- 21
- 23
fail-fast: false
# macos-latest drops support for java 8 temurin. Run java 8 on macos-13. Run java 11, 17, 21 on macos-latest.
exclude:
- os: macos-latest
test-java-version: 8
- os: macos-13
test-java-version: 11
- os: macos-13
test-java-version: 17
- os: macos-13
test-java-version: 21
- os: macos-13
test-java-version: 23
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- id: setup-test-java
name: Set up JDK ${{ matrix.test-java-version }} for running tests
- id: setup-java-test
name: Set up Java ${{ matrix.test-java-version }} for tests
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
# using zulu because new releases get published quickly
distribution: zulu
distribution: temurin
java-version: ${{ matrix.test-java-version }}

- name: Set up JDK for running Gradle
- id: setup-java
name: Set up Java for build
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: temurin
Expand All @@ -71,9 +88,9 @@ jobs:
- name: Gradle test
run: >
./gradlew test
-PtestJavaVersion=${{ matrix.test-java-version }}
-Porg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
-Porg.gradle.java.installations.auto-download=false
"-PtestJavaVersion=${{ matrix.test-java-version }}"
"-Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }}"
"-Porg.gradle.java.installations.auto-download=false"

integration-test:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.ReadableFile;
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.WritableFile;
import io.opentelemetry.sdk.common.Clock;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;

public final class FolderManager {
public final class FolderManager implements Closeable {
private final File folder;
private final Clock clock;
private final StorageConfiguration configuration;
Expand All @@ -30,6 +31,16 @@ public FolderManager(File folder, StorageConfiguration configuration, Clock cloc
this.clock = clock;
}

@Override
public void close() throws IOException {
if (currentReadableFile != null) {
currentReadableFile.close();
}
if (currentWritableFile != null) {
currentWritableFile.close();
}
}

@Nullable
public synchronized ReadableFile getReadableFile() throws IOException {
currentReadableFile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -103,6 +104,11 @@ void setUp() throws IOException {
logger = createLoggerProvider(logToDiskExporter).get("LogInstrumentationScope");
}

@AfterEach
void tearDown() throws IOException {
spanStorage.close();
}

@NotNull
private <T> ToDiskExporter<T> buildToDiskExporter(
SignalSerializer<T> serializer, Function<Collection<T>, CompletableResultCode> exporter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -40,6 +41,11 @@ void setUp() {
folderManager = new FolderManager(rootDir, TestData.getDefaultConfiguration(rootDir), clock);
}

@AfterEach
void tearDown() throws Exception {
folderManager.close();
}

@Test
void createWritableFile_withTimeMillisAsName() throws IOException {
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1000L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -47,6 +48,11 @@ void setUp() throws IOException {
storage = new Storage(folderManager, true);
}

@AfterEach
void tearDown() throws IOException {
storage.close();
}

@Test
void whenReadingAndProcessingSuccessfully_returnSuccess() throws IOException {
when(folderManager.getReadableFile()).thenReturn(readableFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -104,6 +105,11 @@ void setUp() throws IOException {
source, CREATED_TIME_MILLIS, clock, getConfiguration(temporaryFileProvider, dir));
}

@AfterEach
void tearDown() throws IOException {
readableFile.close();
}

private static void addFileContents(File source) throws IOException {
List<byte[]> items = new ArrayList<>();
items.add(SERIALIZER.serialize(Collections.singleton(FIRST_LOG_RECORD)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -47,6 +48,11 @@ void setUp() throws IOException {
clock);
}

@AfterEach
void tearDown() throws IOException {
writableFile.close();
}

@Test
void hasNotExpired_whenWriteAgeHasNotExpired() {
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1500L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.condition.OS.WINDOWS;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
Expand All @@ -31,9 +32,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

@DisabledOnOs(WINDOWS) // Uses async-profiler, which is not supported on Windows
public class InferredSpansAutoConfigTest {

@BeforeEach
Expand Down Expand Up @@ -107,7 +108,6 @@ public void checkDisabledbyDefault() {
}

@DisabledOnOpenJ9
@DisabledOnOs(OS.WINDOWS)
@Test
public void checkProfilerWorking() {
try (AutoConfigTestProperties props =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.List;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junitpioneer.jupiter.ClearSystemProperty;

class JmxScraperTest {
Expand Down Expand Up @@ -46,8 +48,10 @@ private static void testInvalidArguments(String... args) {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldCreateConfig_propertiesLoadedFromFile() throws InvalidArgumentException {
// Given
// Windows returns /C:/path/to/file, which is not a valid path for Path.get() in Java.
String filePath =
ClassLoader.getSystemClassLoader().getResource("validConfig.properties").getPath();
List<String> args = Arrays.asList("-config", filePath);
Expand Down
38 changes: 20 additions & 18 deletions opamp-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.DownloadExtension
import groovy.json.JsonSlurper
import java.net.HttpURLConnection
import java.net.URL

plugins {
id("otel.java-conventions")
Expand All @@ -16,19 +16,9 @@ dependencies {
compileOnly("com.google.auto.value:auto-value-annotations")
}

val opampReleaseInfo = tasks.register<Download>("opampLastReleaseInfo") {
group = "opamp"
src("https://api.github.com/repos/open-telemetry/opamp-spec/releases/latest")
dest(project.layout.buildDirectory.file("opamp/release.json"))
}

val opampProtos = tasks.register<DownloadOpampProtos>("opampProtoDownload", download)
opampProtos.configure {
group = "opamp"
dependsOn(opampReleaseInfo)
lastReleaseInfoJson.set {
opampReleaseInfo.get().dest
}
outputProtosDir.set(project.layout.buildDirectory.dir("opamp/protos"))
downloadedZipFile.set(project.layout.buildDirectory.file("intermediate/$name/release.zip"))
}
Expand All @@ -46,20 +36,32 @@ abstract class DownloadOpampProtos @Inject constructor(
private val fileOps: FileSystemOperations,
) : DefaultTask() {

@get:InputFile
abstract val lastReleaseInfoJson: RegularFileProperty

@get:OutputDirectory
abstract val outputProtosDir: DirectoryProperty

@get:Internal
abstract val downloadedZipFile: RegularFileProperty

@Suppress("UNCHECKED_CAST")
@TaskAction
fun execute() {
val releaseInfo = JsonSlurper().parse(lastReleaseInfoJson.get().asFile) as Map<String, String>
val zipUrl = releaseInfo["zipball_url"]
// Get the latest release tag by following the redirect from GitHub's latest release URL
val latestReleaseUrl = "https://github.com/open-telemetry/opamp-spec/releases/latest"
val connection = URL(latestReleaseUrl).openConnection() as HttpURLConnection
connection.instanceFollowRedirects = false
connection.requestMethod = "HEAD"

val redirectLocation = connection.getHeaderField("Location")
connection.disconnect()

val latestTag = if (redirectLocation != null && redirectLocation.contains("/releases/tag/")) {
// Extract tag from URL like: https://github.com/open-telemetry/opamp-spec/releases/tag/v0.12.0
redirectLocation.substringAfterLast("/")
} else {
throw RuntimeException("Could not determine latest release tag from redirect. Redirect location: $redirectLocation")
}
// Download the source code for the latest release
val zipUrl = "https://github.com/open-telemetry/opamp-spec/zipball/$latestTag"

download.run {
src(zipUrl)
dest(downloadedZipFile)
Expand Down
Loading