Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version detection in agent-common #563

Merged
merged 1 commit into from
Oct 28, 2024
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,17 +53,23 @@ 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;

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;
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Loading