This is an automated email from the ASF dual-hosted git repository.

ycai pushed a commit to branch r/apache/pr109
in repository https://gitbox.apache.org/repos/asf/cassandra-sidecar.git

commit 60d78f2651d0e735c36ec48c343707acd3384f36
Author: Yifan Cai <y...@apache.org>
AuthorDate: Mon Apr 8 13:43:05 2024 -0700

    feedback
---
 .../sidecar/metrics/FilteringMetricRegistry.java   |  81 +++++------
 .../sidecar/metrics/MetricRegistryFactory.java     | 149 +++++++++++++++++++++
 .../sidecar/metrics/MetricRegistryProvider.java    |  83 ------------
 .../cassandra/sidecar/server/MainModule.java       |  16 +--
 .../testing/CassandraSidecarTestContext.java       |  10 +-
 .../metrics/FilteringMetricRegistryTest.java       |  62 ++++-----
 .../cassandra/sidecar/snapshots/SnapshotUtils.java |  12 +-
 7 files changed, 232 insertions(+), 181 deletions(-)

diff --git 
a/src/main/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistry.java
 
b/src/main/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistry.java
index f43efcaf..9ea05ee5 100644
--- 
a/src/main/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistry.java
+++ 
b/src/main/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistry.java
@@ -18,8 +18,11 @@
 
 package org.apache.cassandra.sidecar.metrics;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Predicate;
 
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Gauge;
@@ -36,55 +39,28 @@ import com.codahale.metrics.Timer;
 public class FilteringMetricRegistry extends MetricRegistry
 {
     private static final NoopMetricRegistry NO_OP_METRIC_REGISTRY = new 
NoopMetricRegistry(); // supplies no-op metrics
-    private final List<MetricFilter> include = new ArrayList<>();
-    private final List<MetricFilter> exclude = new ArrayList<>();
+    private final Predicate<String> isAllowed;
+    // all metrics including the allowed and disallowed
+    private final ConcurrentMap<String, Metric> allMetrics = new 
ConcurrentHashMap<>();
 
-    public FilteringMetricRegistry(List<MetricFilter> includeFilters, 
List<MetricFilter> excludeFilters)
+    public FilteringMetricRegistry(Predicate<String> isAllowed)
     {
-        this.include.addAll(includeFilters);
-        this.exclude.addAll(excludeFilters);
-    }
-
-    public synchronized void configureFilters(List<MetricFilter> include, 
List<MetricFilter> exclude)
-    {
-        this.include.clear();
-        this.include.addAll(include);
-        this.exclude.clear();
-        this.exclude.addAll(exclude);
-    }
-
-    public synchronized void resetFilters()
-    {
-        include.clear();
-        exclude.clear();
-    }
-
-    /**
-     * Check if the metric is allowed to register. .
-     * @param name  metric name
-     * @return true if allowed; false otherwise
-     */
-    public boolean isAllowed(String name)
-    {
-        boolean included = include.stream().anyMatch(filter -> 
filter.matches(name));
-        boolean excluded = exclude.stream().anyMatch(filter -> 
filter.matches(name));
-        return included && !excluded;
+        this.isAllowed = isAllowed;
     }
 
     @Override
     public Counter counter(String name)
     {
-        if (isAllowed(name))
-        {
-            return super.counter(name);
-        }
-        return NO_OP_METRIC_REGISTRY.counter(name);
+        // TODO: populate allMetrics in the other methods; it needs to be 
populated in order to let vertx internal that the metric has been registered 
and to avoid registration loop
+        Counter counter = isAllowed.test(name) ? super.counter(name) : 
NO_OP_METRIC_REGISTRY.counter(name);
+        allMetrics.putIfAbsent(name, counter);
+        return counter;
     }
 
     @Override
     public Counter counter(String name, MetricSupplier<Counter> supplier)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.counter(name, supplier);
         }
@@ -94,7 +70,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Histogram histogram(String name)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.histogram(name);
         }
@@ -104,7 +80,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Histogram histogram(String name, MetricSupplier<Histogram> supplier)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.histogram(name, supplier);
         }
@@ -114,7 +90,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Meter meter(String name)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.meter(name);
         }
@@ -124,7 +100,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Meter meter(String name, MetricSupplier<Meter> supplier)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.meter(name, supplier);
         }
@@ -134,7 +110,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Timer timer(String name)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.timer(name);
         }
@@ -144,7 +120,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @Override
     public Timer timer(String name, MetricSupplier<Timer> supplier)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.timer(name, supplier);
         }
@@ -155,7 +131,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @SuppressWarnings({"rawtypes", "unchecked"})
     public <T extends Gauge> T gauge(String name)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.gauge(name);
         }
@@ -166,13 +142,22 @@ public class FilteringMetricRegistry extends 
MetricRegistry
     @SuppressWarnings({"rawtypes", "unchecked"})
     public <T extends Gauge> T gauge(String name, MetricSupplier<T> supplier)
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.gauge(name, supplier);
         }
         return supplier.newMetric(); // unregistered metric
     }
 
+    /**
+     * @return all the metrics including the allowed and disallowed metrics
+     */
+    @Override
+    public Map<String, Metric> getMetrics()
+    {
+        return Collections.unmodifiableMap(allMetrics);
+    }
+
     /**
      * Metric specific retrieve methods such as {@code counter(name)} retrieve 
a noop instance if metric is filtered.
      * Prefer calling those over register method, register method returns an 
unregistered metric if the metric is
@@ -182,7 +167,7 @@ public class FilteringMetricRegistry extends MetricRegistry
     @SuppressWarnings({"rawtypes", "unchecked"})
     public <T extends Metric> T register(String name, T metric) throws 
IllegalArgumentException
     {
-        if (isAllowed(name))
+        if (isAllowed.test(name))
         {
             return super.register(name, metric);
         }
diff --git 
a/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryFactory.java 
b/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryFactory.java
new file mode 100644
index 00000000..c1f7d15f
--- /dev/null
+++ 
b/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryFactory.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.SharedMetricRegistries;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider for getting {@link FilteringMetricRegistry} based on provided 
metrics configuration
+ */
+@Singleton
+public class MetricRegistryFactory
+{
+    private final String globalRegistryName;
+    private final List<FilteringMetricRegistry> createdMetricRegistries;
+    // Use ReadWriteLock to update and read of the inclusion and exclusion 
lists as a whole atomically
+    private final ReadWriteLock readWriteLock;
+    private List<MetricFilter> inclusions;
+    private List<MetricFilter> exclusions;
+
+    @Inject
+    public MetricRegistryFactory(SidecarConfiguration sidecarConfiguration)
+    {
+        this(sidecarConfiguration.metricsConfiguration().registryName(),
+             
MetricFilter.parse(sidecarConfiguration.metricsConfiguration().includeConfigurations()),
+             
MetricFilter.parse(sidecarConfiguration.metricsConfiguration().excludeConfigurations()));
+    }
+
+    @VisibleForTesting
+    public MetricRegistryFactory(String globalRegistryName, List<MetricFilter> 
inclusions, List<MetricFilter> exclusions)
+    {
+        this.globalRegistryName = globalRegistryName;
+        this.readWriteLock = new ReentrantReadWriteLock();
+        this.createdMetricRegistries= new ArrayList<>();
+        this.inclusions = new ArrayList<>(inclusions);
+        this.exclusions = new ArrayList<>(exclusions);
+    }
+
+    /**
+     * TODO add doc
+     * @param inclusions
+     * @param exclusions
+     */
+    public void reconfigureFilters(List<MetricFilter> inclusions, 
List<MetricFilter> exclusions)
+    {
+        List<MetricFilter> newInclusions = new ArrayList<>(inclusions);
+        List<MetricFilter> newExclusions = new ArrayList<>(exclusions);
+        readWriteLock.writeLock().lock();
+        try
+        {
+            this.inclusions = newInclusions;
+            this.exclusions = newExclusions;
+            createdMetricRegistries.forEach(registry -> 
registry.reconfigureFilters(newInclusions, newExclusions));
+        }
+        finally
+        {
+            readWriteLock.writeLock().unlock();
+        }
+    }
+
+    public MetricRegistry getOrCreate()
+    {
+        return getOrCreate(globalRegistryName);
+    }
+
+    public MetricRegistry getOrCreate(int cassInstanceId)
+    {
+        String instanceRegistryName = globalRegistryName + "_" + 
cassInstanceId;
+        return getOrCreate(instanceRegistryName);
+    }
+
+    /**
+     * TODO add doc
+     * @param name
+     * @return
+     */
+    public MetricRegistry getOrCreate(String name)
+    {
+        // the metric registry already exists
+        if (SharedMetricRegistries.names().contains(name))
+        {
+            return SharedMetricRegistries.getOrCreate(name);
+        }
+
+        FilteringMetricRegistry metricRegistry;
+        readWriteLock.readLock().lock();
+        try
+        {
+            metricRegistry = new FilteringMetricRegistry(this::isAllowed);
+            createdMetricRegistries.add(metricRegistry);
+        }
+        finally
+        {
+            readWriteLock.readLock().unlock();
+        }
+        return SharedMetricRegistries.add(name, metricRegistry);
+    }
+
+    /**
+     * Check if the metric is allowed to register
+     * The evaluation order is inclusions first, then exclusions. In other 
words,
+     * a metric name is allowed if it is in the inclusions, but not in the 
exclusions.
+     * <p>
+     * Note that an empty inclusions means including all
+     *
+     * @param name  metric name
+     * @return true if allowed; false otherwise
+     */
+    private boolean isAllowed(String name)
+    {
+        readWriteLock.readLock().lock();
+        try
+        {
+            boolean included = inclusions.isEmpty() || 
inclusions.stream().anyMatch(filter -> filter.matches(name));
+            boolean excluded = exclusions.stream().anyMatch(filter -> 
filter.matches(name));
+            return included && !excluded;
+        }
+        finally
+        {
+            readWriteLock.readLock().unlock();
+        }
+    }
+}
diff --git 
a/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryProvider.java
 
b/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryProvider.java
deleted file mode 100644
index 7c66d043..00000000
--- 
a/src/main/java/org/apache/cassandra/sidecar/metrics/MetricRegistryProvider.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.sidecar.metrics;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.google.common.annotations.VisibleForTesting;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.SharedMetricRegistries;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.apache.cassandra.sidecar.config.SidecarConfiguration;
-
-/**
- * Provider for getting {@link FilteringMetricRegistry} based on provided 
metrics configuration
- */
-@Singleton
-public class MetricRegistryProvider
-{
-    private final String globalRegistryName;
-    private final List<MetricFilter> include = new ArrayList<>();
-    private final List<MetricFilter> exclude = new ArrayList<>();
-
-    @Inject
-    public MetricRegistryProvider(SidecarConfiguration sidecarConfiguration)
-    {
-        this(sidecarConfiguration.metricsConfiguration().registryName(),
-             
MetricFilter.parse(sidecarConfiguration.metricsConfiguration().includeConfigurations()),
-             
MetricFilter.parse(sidecarConfiguration.metricsConfiguration().excludeConfigurations()));
-    }
-
-    @VisibleForTesting
-    public MetricRegistryProvider(String globalRegistryName, 
List<MetricFilter> include, List<MetricFilter> exclude)
-    {
-        this.globalRegistryName = globalRegistryName;
-        this.include.addAll(include);
-        this.exclude.addAll(exclude);
-    }
-
-    public synchronized void configureFilters(List<MetricFilter> include, 
List<MetricFilter> exclude)
-    {
-        this.include.clear();
-        this.exclude.clear();
-        this.include.addAll(include);
-        this.exclude.addAll(exclude);
-    }
-
-    public MetricRegistry registry()
-    {
-        return registry(globalRegistryName);
-    }
-
-    public MetricRegistry registry(int casInstanceId)
-    {
-        String instanceRegistryName = globalRegistryName + "_" + casInstanceId;
-        return registry(instanceRegistryName);
-    }
-
-    public MetricRegistry registry(String name)
-    {
-        FilteringMetricRegistry metricRegistry = new 
FilteringMetricRegistry(include, exclude);
-        SharedMetricRegistries.add(name, metricRegistry);
-        return SharedMetricRegistries.getOrCreate(name);
-    }
-}
diff --git a/src/main/java/org/apache/cassandra/sidecar/server/MainModule.java 
b/src/main/java/org/apache/cassandra/sidecar/server/MainModule.java
index 0fe3d43a..2c6388f5 100644
--- a/src/main/java/org/apache/cassandra/sidecar/server/MainModule.java
+++ b/src/main/java/org/apache/cassandra/sidecar/server/MainModule.java
@@ -75,7 +75,7 @@ import 
org.apache.cassandra.sidecar.db.schema.RestoreSlicesSchema;
 import org.apache.cassandra.sidecar.db.schema.SidecarInternalKeyspace;
 import org.apache.cassandra.sidecar.db.schema.SidecarSchema;
 import org.apache.cassandra.sidecar.logging.SidecarLoggerHandler;
-import org.apache.cassandra.sidecar.metrics.MetricRegistryProvider;
+import org.apache.cassandra.sidecar.metrics.MetricRegistryFactory;
 import org.apache.cassandra.sidecar.routes.CassandraHealthHandler;
 import org.apache.cassandra.sidecar.routes.DiskSpaceProtectionHandler;
 import org.apache.cassandra.sidecar.routes.FileStreamHandler;
@@ -142,14 +142,14 @@ public class MainModule extends AbstractModule
 
     @Provides
     @Singleton
-    public Vertx vertx(SidecarConfiguration sidecarConfiguration, 
MetricRegistryProvider registryProvider)
+    public Vertx vertx(SidecarConfiguration sidecarConfiguration, 
MetricRegistryFactory metricRegistryFactory)
     {
         VertxMetricsConfiguration metricsConfig = 
sidecarConfiguration.metricsConfiguration().vertxConfiguration();
         DropwizardMetricsOptions dropwizardMetricsOptions
         = new DropwizardMetricsOptions().setEnabled(metricsConfig.enabled())
                                         
.setJmxEnabled(metricsConfig.exposeViaJMX())
                                         
.setJmxDomain(metricsConfig.jmxDomainName())
-                                        
.setMetricRegistry(registryProvider.registry());
+                                        
.setMetricRegistry(metricRegistryFactory.getOrCreate());
         for (String regex : metricsConfig.monitoredServerRouteRegexes())
         {
             dropwizardMetricsOptions.addMonitoredHttpServerRoute(new 
Match().setType(MatchType.REGEX).setValue(regex));
@@ -371,7 +371,7 @@ public class MainModule extends AbstractModule
                                            DnsResolver dnsResolver,
                                            CQLSessionProvider 
cqlSessionProvider,
                                            DriverUtils driverUtils,
-                                           MetricRegistryProvider 
registryProvider)
+                                           MetricRegistryFactory 
registryProvider)
     {
         List<InstanceMetadata> instanceMetadataList =
         configuration.cassandraInstances()
@@ -526,9 +526,9 @@ public class MainModule extends AbstractModule
 
     @Provides
     @Singleton
-    public MetricRegistry globalMetricRegistry(MetricRegistryProvider 
registryProvider)
+    public MetricRegistry globalMetricRegistry(MetricRegistryFactory 
registryProvider)
     {
-        return registryProvider.registry();
+        return registryProvider.getOrCreate();
     }
 
     /**
@@ -570,7 +570,7 @@ public class MainModule extends AbstractModule
                                                           JmxConfiguration 
jmxConfiguration,
                                                           CQLSessionProvider 
session,
                                                           DriverUtils 
driverUtils,
-                                                          
MetricRegistryProvider registryProvider)
+                                                          
MetricRegistryFactory metricRegistryFactory)
     {
         String host = cassandraInstance.host();
         int port = cassandraInstance.port();
@@ -601,7 +601,7 @@ public class MainModule extends AbstractModule
                                    .dataDirs(cassandraInstance.dataDirs())
                                    .stagingDir(cassandraInstance.stagingDir())
                                    .delegate(delegate)
-                                   
.metricRegistry(registryProvider.registry(cassandraInstance.id()))
+                                   
.metricRegistry(metricRegistryFactory.getOrCreate(cassandraInstance.id()))
                                    .build();
     }
 }
diff --git 
a/src/test/integration/org/apache/cassandra/sidecar/testing/CassandraSidecarTestContext.java
 
b/src/test/integration/org/apache/cassandra/sidecar/testing/CassandraSidecarTestContext.java
index 225784e8..eb3b8c2c 100644
--- 
a/src/test/integration/org/apache/cassandra/sidecar/testing/CassandraSidecarTestContext.java
+++ 
b/src/test/integration/org/apache/cassandra/sidecar/testing/CassandraSidecarTestContext.java
@@ -48,7 +48,7 @@ import org.apache.cassandra.sidecar.common.JmxClient;
 import org.apache.cassandra.sidecar.common.dns.DnsResolver;
 import org.apache.cassandra.sidecar.common.utils.DriverUtils;
 import org.apache.cassandra.sidecar.metrics.MetricFilter;
-import org.apache.cassandra.sidecar.metrics.MetricRegistryProvider;
+import org.apache.cassandra.sidecar.metrics.MetricRegistryFactory;
 import org.apache.cassandra.sidecar.utils.CassandraVersionProvider;
 import org.apache.cassandra.sidecar.utils.SimpleCassandraVersion;
 import org.apache.cassandra.testing.AbstractCassandraTestContext;
@@ -65,9 +65,9 @@ public class CassandraSidecarTestContext implements 
AutoCloseable
     public final SimpleCassandraVersion version;
     private final List<MetricFilter> includeAll
     = Collections.singletonList(new MetricFilter.Regex(DEFAULT_VALUE));
-    private final MetricRegistryProvider metricRegistryProvider = new 
MetricRegistryProvider("cassandra_sidecar",
-                                                                               
              includeAll,
-                                                                               
              Collections.emptyList());
+    private final MetricRegistryFactory metricRegistryProvider = new 
MetricRegistryFactory("cassandra_sidecar",
+                                                                               
            includeAll,
+                                                                               
            Collections.emptyList());
     private final CassandraVersionProvider versionProvider;
     private final DnsResolver dnsResolver;
     private final AbstractCassandraTestContext abstractCassandraTestContext;
@@ -266,7 +266,7 @@ public class CassandraSidecarTestContext implements 
AutoCloseable
                                              
.dataDirs(Arrays.asList(dataDirectories))
                                              .stagingDir(stagingDir)
                                              .delegate(delegate)
-                                             
.metricRegistry(metricRegistryProvider.registry(i + 1))
+                                             
.metricRegistry(metricRegistryProvider.getOrCreate(i + 1))
                                              .build());
         }
         return new InstancesConfigImpl(metadata, dnsResolver);
diff --git 
a/src/test/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistryTest.java
 
b/src/test/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistryTest.java
index da82c032..b8fe3372 100644
--- 
a/src/test/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistryTest.java
+++ 
b/src/test/java/org/apache/cassandra/sidecar/metrics/FilteringMetricRegistryTest.java
@@ -61,10 +61,10 @@ public class FilteringMetricRegistryTest
     void testNoopInstanceRetrieved()
     {
         MetricFilter.Equals testFilter = new MetricFilter.Equals("testMetric");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
includeAll,
-                                                                             
Collections.singletonList(testFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
includeAll,
+                                                                           
Collections.singletonList(testFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         
assertThat(metricRegistry.timer("testMetric")).isSameAs(NO_OP_METRIC_REGISTRY.timer("any"));
         
assertThat(metricRegistry.meter("testMetric")).isSameAs(NO_OP_METRIC_REGISTRY.meter("any"));
@@ -84,10 +84,10 @@ public class FilteringMetricRegistryTest
     {
         MetricFilter.Equals exactFilter = new 
MetricFilter.Equals("sidecar.metric.exact");
         MetricFilter.Regex regexFilter = new MetricFilter.Regex("vertx.*");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
Collections.singletonList(exactFilter),
-                                                                             
Collections.singletonList(regexFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
Collections.singletonList(exactFilter),
+                                                                           
Collections.singletonList(regexFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.meter("sidecar.metric.exact");
         
assertThat(metricRegistry.getMetrics().containsKey("sidecar.metric.exact")).isTrue();
@@ -98,10 +98,10 @@ public class FilteringMetricRegistryTest
     {
         MetricFilter.Equals exactFilter = new 
MetricFilter.Equals("sidecar.metric.exact");
         MetricFilter.Regex regexFilter = new MetricFilter.Regex("sidecar.*");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
Arrays.asList(exactFilter, regexFilter),
-                                                                             
Collections.emptyList());
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
Arrays.asList(exactFilter, regexFilter),
+                                                                           
Collections.emptyList());
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.meter("sidecar.metric.exact");
         
assertThat(metricRegistry.getMetrics().containsKey("sidecar.metric.exact")).isTrue();
@@ -111,10 +111,10 @@ public class FilteringMetricRegistryTest
     void testExcludingEqualsMetricFilter()
     {
         MetricFilter.Equals exactFilter = new 
MetricFilter.Equals("sidecar.metric.exact");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
includeAll,
-                                                                             
Collections.singletonList(exactFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
includeAll,
+                                                                           
Collections.singletonList(exactFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.meter("sidecar.metric.exact");
         
assertThat(metricRegistry.getMetrics().containsKey("sidecar.metric.exact")).isFalse();
@@ -125,10 +125,10 @@ public class FilteringMetricRegistryTest
     {
         MetricFilter.Regex vertxFilter = new MetricFilter.Regex("vertx.*");
         MetricFilter.Regex sidecarFilter = new MetricFilter.Regex("sidecar.*");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
Collections.singletonList(sidecarFilter),
-                                                                             
Collections.singletonList(vertxFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
Collections.singletonList(sidecarFilter),
+                                                                           
Collections.singletonList(vertxFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.meter("sidecar.metric.exact");
         
assertThat(metricRegistry.getMetrics().containsKey("sidecar.metric.exact")).isTrue();
@@ -141,10 +141,10 @@ public class FilteringMetricRegistryTest
     {
         MetricFilter.Equals exactFilter = new 
MetricFilter.Equals("sidecar.metric.exact");
         MetricFilter.Regex regexFilter = new MetricFilter.Regex("sidecar.*");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
Collections.singletonList(regexFilter),
-                                                                             
Collections.singletonList(exactFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
Collections.singletonList(regexFilter),
+                                                                           
Collections.singletonList(exactFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.meter("sidecar.metric.exact");
         
assertThat(metricRegistry.getMetrics().containsKey("sidecar.metric.exact")).isFalse();
@@ -154,15 +154,15 @@ public class FilteringMetricRegistryTest
     void testReconfiguringMetricFilters()
     {
         MetricFilter.Regex vertxFilter = new MetricFilter.Regex("vertx.*");
-        MetricRegistryProvider registryProvider = new 
MetricRegistryProvider("cassandra_sidecar_" + UUID.randomUUID(),
-                                                                             
includeAll,
-                                                                             
Collections.singletonList(vertxFilter));
-        MetricRegistry metricRegistry = registryProvider.registry();
+        MetricRegistryFactory registryProvider = new 
MetricRegistryFactory("cassandra_sidecar_" + UUID.randomUUID(),
+                                                                           
includeAll,
+                                                                           
Collections.singletonList(vertxFilter));
+        MetricRegistry metricRegistry = registryProvider.getOrCreate();
 
         metricRegistry.timer("vertx.eventbus.message_transfer_time");
         
assertThat(metricRegistry.getMetrics().containsKey("vertx.eventbus.message_transfer_time")).isFalse();
 
-        ((FilteringMetricRegistry) 
metricRegistry).configureFilters(includeAll, Collections.emptyList());
+        ((FilteringMetricRegistry) 
metricRegistry).reconfigureFilters(includeAll, Collections.emptyList());
 
         metricRegistry.timer("vertx.eventbus.message_transfer_time");
         
assertThat(metricRegistry.getMetrics().containsKey("vertx.eventbus.message_transfer_time")).isTrue();
@@ -185,9 +185,9 @@ public class FilteringMetricRegistryTest
         server.start()
               .onFailure(context::failNow)
               .onSuccess(v -> {
-                  MetricRegistryProvider registryProvider = 
injector.getInstance(MetricRegistryProvider.class);
+                  MetricRegistryFactory registryProvider = 
injector.getInstance(MetricRegistryFactory.class);
                   Pattern excludedPattern = 
Pattern.compile("vertx.eventbus.*");
-                  MetricRegistry globalRegistry = registryProvider.registry();
+                  MetricRegistry globalRegistry = 
registryProvider.getOrCreate();
                   
assertThat(globalRegistry.getMetrics().size()).isGreaterThanOrEqualTo(1);
                   assertThat(globalRegistry.getMetrics()
                                            .keySet()
diff --git 
a/src/test/java/org/apache/cassandra/sidecar/snapshots/SnapshotUtils.java 
b/src/test/java/org/apache/cassandra/sidecar/snapshots/SnapshotUtils.java
index 202acbbb..85cba26e 100644
--- a/src/test/java/org/apache/cassandra/sidecar/snapshots/SnapshotUtils.java
+++ b/src/test/java/org/apache/cassandra/sidecar/snapshots/SnapshotUtils.java
@@ -41,7 +41,7 @@ import 
org.apache.cassandra.sidecar.common.MockCassandraFactory;
 import org.apache.cassandra.sidecar.common.dns.DnsResolver;
 import org.apache.cassandra.sidecar.common.utils.DriverUtils;
 import org.apache.cassandra.sidecar.metrics.MetricFilter;
-import org.apache.cassandra.sidecar.metrics.MetricRegistryProvider;
+import org.apache.cassandra.sidecar.metrics.MetricRegistryFactory;
 import org.apache.cassandra.sidecar.utils.CassandraVersionProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -54,9 +54,9 @@ public class SnapshotUtils
 {
     public static final String STAGING_DIR = "staging";
     public static final List<MetricFilter> INCLUDE_ALL = 
Collections.singletonList(new MetricFilter.Regex(".*"));
-    public static final MetricRegistryProvider METRIC_REGISTRY_PROVIDER = new 
MetricRegistryProvider("cassandra_sidecar",
-                                                                               
                      INCLUDE_ALL,
-                                                                               
                      Collections.emptyList());
+    public static final MetricRegistryFactory METRIC_REGISTRY_PROVIDER = new 
MetricRegistryFactory("cassandra_sidecar",
+                                                                               
                    INCLUDE_ALL,
+                                                                               
                    Collections.emptyList());
 
     public static String makeStagingDir(String rootPath)
     {
@@ -130,7 +130,7 @@ public class SnapshotUtils
                                                              
.dataDirs(Collections.singletonList(rootPath + "/d1"))
                                                              
.stagingDir(stagingDir)
                                                              
.delegate(delegate)
-                                                             
.metricRegistry(METRIC_REGISTRY_PROVIDER.registry(1))
+                                                             
.metricRegistry(METRIC_REGISTRY_PROVIDER.getOrCreate(1))
                                                              .build();
         InstanceMetadataImpl localhost2 = InstanceMetadataImpl.builder()
                                                               .id(2)
@@ -139,7 +139,7 @@ public class SnapshotUtils
                                                               
.dataDirs(Collections.singletonList(rootPath + "/d2"))
                                                               
.stagingDir(stagingDir)
                                                               
.delegate(delegate)
-                                                              
.metricRegistry(METRIC_REGISTRY_PROVIDER.registry(2))
+                                                              
.metricRegistry(METRIC_REGISTRY_PROVIDER.getOrCreate(2))
                                                               .build();
         List<InstanceMetadata> instanceMetas = Arrays.asList(localhost, 
localhost2);
         return new InstancesConfigImpl(instanceMetas, DnsResolver.DEFAULT);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org


Reply via email to