Merge branch 'cassandra-5.0' into trunk

* cassandra-5.0:
  Enforce metric naming contract if scope is used in a metric name
diff --git a/CHANGES.txt b/CHANGES.txt
index 6b391cc..7ddd707 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -40,6 +40,7 @@
  * Add the ability to disable bulk loading of SSTables (CASSANDRA-18781)
  * Clean up obsolete functions and simplify cql_version handling in cqlsh (CASSANDRA-18787)
 Merged from 5.0:
+ * 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 17fd992..642cfd2 100644
--- a/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java
+++ b/src/java/org/apache/cassandra/index/sai/metrics/AbstractMetrics.java
@@ -70,7 +70,7 @@
         return new CassandraMetricsRegistry.MetricName(DefaultNameFactory.GROUP_NAME,
                                                        TYPE,
                                                        name,
-                                                       MetricRegistry.name(keyspace, table, index, scope, name),
+                                                       MetricRegistry.name(keyspace, table, index, scope),
                                                        createMBeanName(name, scope));
     }
 
diff --git a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
index 2464533..dcd883a 100644
--- a/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
+++ b/src/java/org/apache/cassandra/metrics/CassandraMetricsRegistry.java
@@ -1065,6 +1065,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;