Skip to content

Commit 0ae3cd5

Browse files
authored
Fix version detection in agent-common (#563)
1 parent 78e7f6d commit 0ae3cd5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Changelog for Management API, new PRs should update the `main / unreleased` sect
1717
* [ENHANCEMENT] [#552](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/552) Improve "liveness" probe implementation
1818
* [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
1919
* [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)
20+
* [BUGFIX] [#562](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/562) Fix version detection
2021

2122
## v0.1.87 (2024-10-02)
2223
* [FEATURE] [#535](https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/535) Add Cassandra 5.0.0 to the build matrix

management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/CassandraMetricRegistryListener.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.function.Supplier;
3232
import java.util.regex.Matcher;
3333
import java.util.regex.Pattern;
34-
import org.apache.cassandra.utils.CassandraVersion;
3534
import org.apache.cassandra.utils.EstimatedHistogram;
3635
import org.apache.cassandra.utils.FBUtilities;
3736
import org.slf4j.LoggerFactory;
@@ -54,17 +53,23 @@ public class CassandraMetricRegistryListener implements MetricRegistryListener {
5453
Pattern.compile("([1-9]\\d*)\\.(\\d+)\\.(\\d+)(?:-([a-zA-Z0-9]+))?");
5554

5655
private static final String SERVER_VERSION = FBUtilities.getReleaseVersionString();
56+
private static final int SERVER_MAJOR_VERSION;
57+
private static final int SERVER_MINOR_VERSION;
5758
private static final int SERVER_PATCH_VERSION;
5859

5960
private boolean microLatencyBuckets = false;
6061

6162
static {
6263
Matcher matcher = VERSION_PATTERN.matcher(SERVER_VERSION);
6364
if (matcher.matches()) {
65+
SERVER_MAJOR_VERSION = Integer.parseInt(matcher.group(1));
66+
SERVER_MINOR_VERSION = Integer.parseInt(matcher.group(2));
6467
SERVER_PATCH_VERSION = Integer.parseInt(matcher.group(3));
6568
} else {
6669
// unexpected Server version
6770
logger.warn("Unexpected Server Version string: " + SERVER_VERSION);
71+
SERVER_MAJOR_VERSION = -1;
72+
SERVER_MINOR_VERSION = -1;
6873
SERVER_PATCH_VERSION = -1;
6974
}
7075
}
@@ -86,12 +91,8 @@ public CassandraMetricRegistryListener(
8691
parser = CassandraMetricNameParser.getDefaultParser(config);
8792
cache = new ConcurrentHashMap<>();
8893

89-
CassandraVersion cassandraVersion = new CassandraVersion(FBUtilities.getReleaseVersionString());
90-
91-
if (cassandraVersion.major > 4 || (cassandraVersion.major == 4 && cassandraVersion.minor > 0)) {
92-
// 4.1 and up should use microsecond buckets
93-
microLatencyBuckets = true;
94-
}
94+
// 4.1 and up should use microsecond buckets
95+
microLatencyBuckets = isMicrosecondLatencyBuckets();
9596

9697
this.familyCache = familyCache;
9798
}
@@ -517,4 +518,22 @@ public void onTimerAdded(String dropwizardName, Timer timer) {
517518
public void onTimerRemoved(String name) {
518519
onHistogramRemoved(name);
519520
}
521+
522+
/**
523+
* Returns true if the server version should use microsecond latency buckets, as opposed to
524+
* nanosecond latency buckets. For Cassandra 4.1 and newer, this should return true. For Cassandra
525+
* 4.0 and older, and DSE 6.8/6.9, this should return false.
526+
*
527+
* @return true if microsecond latency buckets should be used, false if nanosecond should be used.
528+
*/
529+
private boolean isMicrosecondLatencyBuckets() {
530+
531+
// This should only catch Cassandra 4.1+ and 5+ versions. DSE 6.8 reports something like
532+
// 4.0.0.6851 and 6.9 reports something like 4.0.0.693, both of which would follow C* 4.0.x
533+
// nanosecond buckets
534+
if (SERVER_MAJOR_VERSION > 4 || (SERVER_MAJOR_VERSION == 4 && SERVER_MINOR_VERSION > 0)) {
535+
return true;
536+
}
537+
return false;
538+
}
520539
}

0 commit comments

Comments
 (0)