Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This file contains all changes which are not released yet.
* Fix unsupported-aggregation warning in OpenTelemetry metric SDK exporter to use SLF4J-style `{}` placeholders instead of `%s`, so the metric name and aggregation type are rendered in the log message - [#4466](https://github.com/elastic/apm-agent-java/pull/4466)
* Stop OTel metrics exporter from throwing `IndexOutOfBoundsException` when a histogram has no explicit bucket boundaries - [#4465](https://github.com/elastic/apm-agent-java/pull/4465)
* Cast to parent buffer for Java 8 buffer method compatibility - [#4498](https://github.com/elastic/apm-agent-java/pull/4498)
* Minor fix to remove NPE noise if multiple APM URLs are invalid - [#4501](https://github.com/elastic/apm-agent-java/pull/4501)
<!--FIXES-END-->
# Features and enhancements
<!--ENHANCEMENTS-START-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ public Version withConnection(HttpURLConnection connection) {
return null;
}
});
versions.remove(null);
return getMinVersionOrUnknown(versions);
}

static Version getMinVersionOrUnknown(List<Version> versions) {
while (versions.remove(null)) {
// remove all unavailable server results before comparing versions
}
if (!versions.isEmpty()) {
return Collections.min(versions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -39,4 +42,25 @@ void testParseVersion() throws IOException {
body = "{\"ok\":{\"build_date\":\"2021-10-13T17:29:41Z\",\"build_sha\":\"04a84d8d3d0358af5e73b3581c4ba37fbdbc979e\",\"version\":\"6.8.20\"}}";
assertThat(ApmServerHealthChecker.parseVersion(body).compareTo(Version.of("6.8.20"))).isEqualTo(0);
}

@Test
void testMinVersionIgnoresUnavailableServers() {
List<Version> versions = new ArrayList<>(Arrays.asList(
Version.of("8.0.0"),
null,
Version.of("7.17.0"),
null
));

assertThat(ApmServerHealthChecker.getMinVersionOrUnknown(versions))
.isEqualTo(Version.of("7.17.0"));
}

@Test
void testMinVersionReturnsUnknownWhenAllServersUnavailable() {
List<Version> versions = new ArrayList<>(Arrays.asList(null, null));

assertThat(ApmServerHealthChecker.getMinVersionOrUnknown(versions))
.isEqualTo(ApmServerHealthChecker.UNKNOWN_VERSION);
}
}
Loading