maedhroz commented on code in PR #2534:
URL: https://github.com/apache/cassandra/pull/2534#discussion_r1317595176


##########
src/java/org/apache/cassandra/metrics/AccordStateCacheMetrics.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.metrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import com.codahale.metrics.Histogram;
+import org.apache.cassandra.cache.CacheSize;
+
+import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
+
+public class AccordStateCacheMetrics extends CacheMetrics
+{
+    public final Histogram objectSize;
+
+    /**
+     * Create metrics for given cache.
+     *
+     * @param type  Type of Cache to identify metrics.
+     * @param cache Cache to measure metrics
+     */
+    public AccordStateCacheMetrics(String type, CacheSize cache)
+    {
+        super(type, cache);
+
+        objectSize = Metrics.histogram(factory.createMetricName("ObjectSize"), 
false);
+    }
+
+    public static class Provider
+    {
+        public static final String ACCORD_STATE_CACHE = "accord-state-cache";
+
+        private final Set<CacheSize> globalCacheSizes;
+        private final AccordStateCacheMetrics globalMetrics;
+
+        private final Map<Class<?>, AccordStateCacheMetrics> instanceMetrics;
+        private final Map<Class<?>, Set<CacheSize>> instanceCacheSizes;
+
+        private final String type;
+
+        public Provider()
+        {
+            this(ACCORD_STATE_CACHE);
+        }
+
+        @VisibleForTesting
+        public Provider(String type)
+        {
+            this.type = type;
+            globalCacheSizes = new CopyOnWriteArraySet<>();
+            globalMetrics = new AccordStateCacheMetrics(type, new 
CacheSize.Summing(globalCacheSizes));

Review Comment:
   I'm a little bit confused about how we're managing the global metrics here. 
`AccordCommandStores` implements `CacheSize` now, but then we also have this 
`Summing` component for `globalMetrics` that has to receive and bookkeep the 
`globalCacheSizes`. Can't we just do something like pass `AccordCommandStores` 
to the provider on construction, where it can then create a 
`AccordStateCacheMetrics(type, stores)` (i.e. `stores` is the 
`AccordCommandStores`) for the globals? That at least gets rid of the 
`globalCacheSizes` set. (Then `forGlobal()` is simpler and no longer has to be 
`synchronized` as well.)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to