You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/10/02 00:22:34 UTC

[GitHub] [ozone] symious opened a new pull request, #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

symious opened a new pull request, #3791:
URL: https://github.com/apache/ozone/pull/3791

   ## What changes were proposed in this pull request?
   
   This ticket is to add the metric of EstimatedKeyCount for SCM DB.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-7282
   
   ## How was this patch tested?
   
   unit test.
   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] symious commented on a diff in pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
symious commented on code in PR #3791:
URL: https://github.com/apache/ozone/pull/3791#discussion_r985634038


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMMetadataStoreImpl.java:
##########
@@ -190,6 +200,9 @@ public void start(OzoneConfiguration config)
 
       checkTableStatus(statefulServiceConfigTable,
           STATEFUL_SERVICE_CONFIG.getName());
+
+      mxBean = MBeans.register("SCMMetadataStore", "SCMMetadataStoreImpl",

Review Comment:
   @sodonnel Thank you for your reminder, updated the PR, please have a look.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel merged pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
sodonnel merged PR #3791:
URL: https://github.com/apache/ozone/pull/3791


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on a diff in pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
sodonnel commented on code in PR #3791:
URL: https://github.com/apache/ozone/pull/3791#discussion_r988843365


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMMetadataStoreMetrics.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.scm.metadata;
+
+import com.google.gson.Gson;
+import org.apache.commons.text.WordUtils;
+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.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.MetricsRegistry;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.metrics2.lib.Interns.info;
+
+/**
+ * Class contains metrics related to SCM Metadata Store.
+ */
+@Metrics(about = "SCM Metadata Store Metrics", context = OzoneConsts.OZONE)
+public final class SCMMetadataStoreMetrics implements MetricsSource {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SCMMetadataStoreMetrics.class);
+
+  public static final String METRICS_SOURCE_NAME =
+      SCMMetadataStoreMetrics.class.getSimpleName();
+
+  private static final MetricsInfo ESTIMATED_KEY_COUNT = info(
+      "EstimatedKeyCount",
+      "Tracked estimated key count of all column families");
+
+  private MetricsRegistry registry;
+  private static SCMMetadataStoreMetrics instance;
+
+  private SCMMetadataStoreImpl scmMetadataStore;
+
+  private Map<String, MetricsInfo> columnFamilyMetrics;
+
+  public SCMMetadataStoreMetrics(SCMMetadataStoreImpl scmMetadataStoreImpl) {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+    this.scmMetadataStore = scmMetadataStoreImpl;
+
+    columnFamilyMetrics = scmMetadataStoreImpl.getTableMap().entrySet()
+        .stream().collect(
+        Collectors.toMap(Map.Entry::getKey, e -> getMetricsInfo(e.getKey())));
+  }
+
+  public static synchronized SCMMetadataStoreMetrics create(SCMMetadataStoreImpl
+      scmMetadataStore) {
+    if (instance != null) {
+      return instance;
+    }
+    instance = DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "SCM Metadata store related metrics",
+        new SCMMetadataStoreMetrics(scmMetadataStore));
+    return instance;
+  }
+
+  @Override
+  public void getMetrics(MetricsCollector collector, boolean all) {
+    MetricsRecordBuilder builder = collector.addRecord(METRICS_SOURCE_NAME);
+
+    Map<String, Long> keyCountMap = new HashMap<>();
+    for (Map.Entry<String, MetricsInfo> entry: columnFamilyMetrics.entrySet()) {
+      long count = 0L;
+      try {
+        count = scmMetadataStore.getTableMap().get(entry.getKey())
+            .getEstimatedKeyCount();
+      } catch (IOException e) {
+        LOG.error("Can not get estimated key count for table {}",
+            entry.getKey(), e);
+      }
+      builder.addGauge(entry.getValue(), count);
+      keyCountMap.put(entry.getKey(), count);
+    }
+
+    Gson gson = new Gson();
+    builder.tag(ESTIMATED_KEY_COUNT, gson.toJson(keyCountMap));
+  }
+
+  public static void unRegister() {

Review Comment:
   Does `unRegister` need to be synchronized too, as it can access `instance` while register is running? I'm not sure if it does or not, but might be safer to make it synchronized.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on a diff in pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
sodonnel commented on code in PR #3791:
URL: https://github.com/apache/ozone/pull/3791#discussion_r985820087


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMMetadataStoreImpl.java:
##########
@@ -313,6 +330,20 @@ private void checkTableStatus(Table table, String name) throws IOException {
       LOG.error(String.format(logMessage, name));
       throw new IOException(String.format(errMsg, name));
     }
+    tableMap.put(name, table);
+  }
+
+  @Override
+  public String getEstimatedKeyCount() {

Review Comment:
   I typed this earlier, but forgot to post it. This means we are going to have a metric where the value is a command seperated list of key value pairs, eg:
   
   ```
   metric -> tab1 : 10, tab2 : 15 ... etc.
   ```
   Have we got any other metrics like this? Would it be better if we had a metric for each table directly, so they can be charted etc if needed? Ie
   
   ```
   SCMEstimatedKeyCountTab1 -> 10
   SCMEstimatedKeyCounttab2 -> 15
   etc
   ```
   
   You would need to have dynamic metric names for this, but there is an example of doing that in ReplicationManagerMetrics



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on a diff in pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
sodonnel commented on code in PR #3791:
URL: https://github.com/apache/ozone/pull/3791#discussion_r985631511


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMMetadataStoreImpl.java:
##########
@@ -190,6 +200,9 @@ public void start(OzoneConfiguration config)
 
       checkTableStatus(statefulServiceConfigTable,
           STATEFUL_SERVICE_CONFIG.getName());
+
+      mxBean = MBeans.register("SCMMetadataStore", "SCMMetadataStoreImpl",

Review Comment:
   I suspect this needs an "unRegister" in the `stop()` method?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] symious commented on a diff in pull request #3791: HDDS-7282. Add EstimatedKeyCount metrics for SCM DB

Posted by GitBox <gi...@apache.org>.
symious commented on code in PR #3791:
URL: https://github.com/apache/ozone/pull/3791#discussion_r988845251


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SCMMetadataStoreMetrics.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.scm.metadata;
+
+import com.google.gson.Gson;
+import org.apache.commons.text.WordUtils;
+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.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.MetricsRegistry;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.metrics2.lib.Interns.info;
+
+/**
+ * Class contains metrics related to SCM Metadata Store.
+ */
+@Metrics(about = "SCM Metadata Store Metrics", context = OzoneConsts.OZONE)
+public final class SCMMetadataStoreMetrics implements MetricsSource {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SCMMetadataStoreMetrics.class);
+
+  public static final String METRICS_SOURCE_NAME =
+      SCMMetadataStoreMetrics.class.getSimpleName();
+
+  private static final MetricsInfo ESTIMATED_KEY_COUNT = info(
+      "EstimatedKeyCount",
+      "Tracked estimated key count of all column families");
+
+  private MetricsRegistry registry;
+  private static SCMMetadataStoreMetrics instance;
+
+  private SCMMetadataStoreImpl scmMetadataStore;
+
+  private Map<String, MetricsInfo> columnFamilyMetrics;
+
+  public SCMMetadataStoreMetrics(SCMMetadataStoreImpl scmMetadataStoreImpl) {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+    this.scmMetadataStore = scmMetadataStoreImpl;
+
+    columnFamilyMetrics = scmMetadataStoreImpl.getTableMap().entrySet()
+        .stream().collect(
+        Collectors.toMap(Map.Entry::getKey, e -> getMetricsInfo(e.getKey())));
+  }
+
+  public static synchronized SCMMetadataStoreMetrics create(SCMMetadataStoreImpl
+      scmMetadataStore) {
+    if (instance != null) {
+      return instance;
+    }
+    instance = DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "SCM Metadata store related metrics",
+        new SCMMetadataStoreMetrics(scmMetadataStore));
+    return instance;
+  }
+
+  @Override
+  public void getMetrics(MetricsCollector collector, boolean all) {
+    MetricsRecordBuilder builder = collector.addRecord(METRICS_SOURCE_NAME);
+
+    Map<String, Long> keyCountMap = new HashMap<>();
+    for (Map.Entry<String, MetricsInfo> entry: columnFamilyMetrics.entrySet()) {
+      long count = 0L;
+      try {
+        count = scmMetadataStore.getTableMap().get(entry.getKey())
+            .getEstimatedKeyCount();
+      } catch (IOException e) {
+        LOG.error("Can not get estimated key count for table {}",
+            entry.getKey(), e);
+      }
+      builder.addGauge(entry.getValue(), count);
+      keyCountMap.put(entry.getKey(), count);
+    }
+
+    Gson gson = new Gson();
+    builder.tag(ESTIMATED_KEY_COUNT, gson.toJson(keyCountMap));
+  }
+
+  public static void unRegister() {

Review Comment:
   Sure, let me add it.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org