Galsza commented on code in PR #3865:
URL: https://github.com/apache/ozone/pull/3865#discussion_r1004077856


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/TableCacheMetrics.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.utils;
+
+import org.apache.hadoop.hdds.utils.db.cache.CacheStats;
+import org.apache.hadoop.hdds.utils.db.cache.TableCache;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * This class emits table level cache metrics.
+ */
+public final class TableCacheMetrics implements MetricsSource {
+  private enum MetricsInfos implements MetricsInfo {
+    TableName("Table Name."),
+    Size("Size of the cache."),
+    HitCount("Number of time the lookup methods return a cached value."),
+    MissCount("Number of times the requested value is not in the cache."),
+    IterationCount("Number of times the table cache is iterated through.");
+
+    private final String desc;
+
+    MetricsInfos(String desc) {
+      this.desc = desc;
+    }
+
+    @Override
+    public String description() {
+      return desc;
+    }
+  }
+
+  public static final String SOURCE_NAME =
+      TableCacheMetrics.class.getSimpleName();
+
+  public static final String NAME = TableCacheMetrics.class.getSimpleName();
+
+  private final TableCache<?, ?> cache;
+  private final String tableName;
+
+  private TableCacheMetrics(TableCache<?, ?> cache, String name) {
+    this.cache = cache;
+    this.tableName = name;
+  }
+
+  public static TableCacheMetrics create(TableCache<?, ?> cache,
+                                         String tableName) {
+    MetricsSystem ms = DefaultMetricsSystem.instance();
+    return ms.register(sourceName(tableName), "Table cache metrics",
+        new TableCacheMetrics(cache, tableName));
+  }
+
+  private static String sourceName(String tableName) {

Review Comment:
   Nit: this function name is a bit misleading I'd suggest naming it 
getTableSourceName



-- 
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