Enforce metric naming contract if scope is used in a metric name
patch by Maxim Muzafarov; reviewed by Caleb Rackliffe, Michael Semb Wever for CASSANDRA-19619
diff --git a/CHANGES.txt b/CHANGES.txt
index 370971f..d3400ec 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0-beta2
+ * Enforce metric naming contract if scope is used in a metric name (CASSANDRA-19619)
* Avoid reading of the same IndexInfo from disk many times for a large partition (CASSANDRA-19557)
* Resolve the oldest hints just from descriptors and current writer if available (CASSANDRA-19600)
* Optionally fail writes when SAI refuses to index a term value exceeding configured term max size (CASSANDRA-19493)
diff --git a/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java b/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java
index 90956e4..1bb0a76 100644
--- a/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java
+++ b/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java
@@ -73,7 +73,7 @@
{
metricScope += '.' + index;
}
- metricScope += '.' + scope + '.' + name;
+ metricScope += '.' + scope;
CassandraMetricsRegistry.MetricName metricName = new CassandraMetricsRegistry.MetricName(DefaultNameFactory.GROUP_NAME,
TYPE, name, metricScope, createMBeanName(name, scope));
diff --git a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
index cd98ceb..598e484 100644
--- a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
+++ b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
@@ -770,6 +770,11 @@
{
throw new IllegalArgumentException("Name needs to be specified");
}
+ if (scope != null && scope.contains(name))
+ {
+ throw new IllegalArgumentException("Scope cannot contain name, this is not neccessary and will cause performance issues. " +
+ "Scope: " + scope + " Name: " + name);
+ }
this.group = group;
this.type = type;
this.name = name;