diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1df47c..9a7d5e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Changelog for Management API, new PRs should update the `main / unreleased` sect * [ENHANCEMENT] [#552](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/552) Improve "liveness" probe implementation * [BUGFIX] [#553](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/553) Fix CassandraTaskExports metric filtering to make it work with 5.0.x Major compactions * [BUGFIX] [#560](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/560) Fix LatencyMetrics bucketing on 4.1 and 5.0 as their reservoir stores the data in microseconds, not nano (unlike 3.11 and 4.0) +* [BUGFIX] [#562](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/562) Fix version detection ## v0.1.87 (2024-10-02) * [FEATURE] [#535](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/535) Add Cassandra 5.0.0 to the build matrix diff --git a/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/CassandraMetricRegistryListener.java b/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/CassandraMetricRegistryListener.java index c50bc86e..b74ab04f 100644 --- a/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/CassandraMetricRegistryListener.java +++ b/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/CassandraMetricRegistryListener.java @@ -31,7 +31,6 @@ import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.cassandra.utils.CassandraVersion; import org.apache.cassandra.utils.EstimatedHistogram; import org.apache.cassandra.utils.FBUtilities; import org.slf4j.LoggerFactory; @@ -54,6 +53,8 @@ public class CassandraMetricRegistryListener implements MetricRegistryListener { Pattern.compile("([1-9]\\d*)\\.(\\d+)\\.(\\d+)(?:-([a-zA-Z0-9]+))?"); private static final String SERVER_VERSION = FBUtilities.getReleaseVersionString(); + private static final int SERVER_MAJOR_VERSION; + private static final int SERVER_MINOR_VERSION; private static final int SERVER_PATCH_VERSION; private boolean microLatencyBuckets = false; @@ -61,10 +62,14 @@ public class CassandraMetricRegistryListener implements MetricRegistryListener { static { Matcher matcher = VERSION_PATTERN.matcher(SERVER_VERSION); if (matcher.matches()) { + SERVER_MAJOR_VERSION = Integer.parseInt(matcher.group(1)); + SERVER_MINOR_VERSION = Integer.parseInt(matcher.group(2)); SERVER_PATCH_VERSION = Integer.parseInt(matcher.group(3)); } else { // unexpected Server version logger.warn("Unexpected Server Version string: " + SERVER_VERSION); + SERVER_MAJOR_VERSION = -1; + SERVER_MINOR_VERSION = -1; SERVER_PATCH_VERSION = -1; } } @@ -86,12 +91,8 @@ public CassandraMetricRegistryListener( parser = CassandraMetricNameParser.getDefaultParser(config); cache = new ConcurrentHashMap<>(); - CassandraVersion cassandraVersion = new CassandraVersion(FBUtilities.getReleaseVersionString()); - - if (cassandraVersion.major > 4 || (cassandraVersion.major == 4 && cassandraVersion.minor > 0)) { - // 4.1 and up should use microsecond buckets - microLatencyBuckets = true; - } + // 4.1 and up should use microsecond buckets + microLatencyBuckets = isMicrosecondLatencyBuckets(); this.familyCache = familyCache; } @@ -517,4 +518,22 @@ public void onTimerAdded(String dropwizardName, Timer timer) { public void onTimerRemoved(String name) { onHistogramRemoved(name); } + + /** + * Returns true if the server version should use microsecond latency buckets, as opposed to + * nanosecond latency buckets. For Cassandra 4.1 and newer, this should return true. For Cassandra + * 4.0 and older, and DSE 6.8/6.9, this should return false. + * + * @return true if microsecond latency buckets should be used, false if nanosecond should be used. + */ + private boolean isMicrosecondLatencyBuckets() { + + // This should only catch Cassandra 4.1+ and 5+ versions. DSE 6.8 reports something like + // 4.0.0.6851 and 6.9 reports something like 4.0.0.693, both of which would follow C* 4.0.x + // nanosecond buckets + if (SERVER_MAJOR_VERSION > 4 || (SERVER_MAJOR_VERSION == 4 && SERVER_MINOR_VERSION > 0)) { + return true; + } + return false; + } }