amaliujia commented on code in PR #12071: URL: https://github.com/apache/ozone/pull/12071#discussion_r4662546011
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMStoragePolicyMetrics.java: ########## @@ -0,0 +1,165 @@ +/* + * 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.hadoop.ozone.om; + +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.commons.lang3.tuple.Triple; +import org.apache.hadoop.hdds.client.ContainerBlockID; +import org.apache.hadoop.hdds.client.OzoneStoragePolicy; +import org.apache.hadoop.hdds.client.StorageTier; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.Interns; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup; +import org.apache.hadoop.ozone.util.MetricUtil; + +/** + * Committed logical bytes attributed to each block's storage-policy allocation outcome. Bytes from a key + * spanning multiple tiers are counted separately per tier. These are per-OM counters with the same commit + * boundary as {@code OMMetrics.TotalDataCommitted}, not current physical-volume usage. + */ +public final class OMStoragePolicyMetrics implements MetricsSource { + private static final String SOURCE_NAME = OMStoragePolicyMetrics.class.getSimpleName(); + private static final MetricsInfo POLICY = Interns.info("Policy", "Recorded key storage policy"); + private static final MetricsInfo REQUESTED_TIER = Interns.info("RequestedTier", "Policy creation tier"); + private static final MetricsInfo ACTUAL_TIER = Interns.info("ActualTier", "SCM-selected tiers of committed blocks"); + private static final MetricsInfo OUTCOME = Interns.info("Outcome", "Preferred, fallback or unknown allocation"); + private static final MetricsInfo COMMITTED_BYTES = Interns.info("CommittedBytes", "Committed logical key bytes"); + + private final ConcurrentMap<Triple<OzoneStoragePolicy, Tier, Outcome>, AtomicLong> committedBytes = + new ConcurrentHashMap<>(); + private String sourceName; + + // These values bound metric cardinality; key, bucket and volume names are never retained or exported. + private enum Tier { + SSD, DISK, ARCHIVE, UNKNOWN + } + + private enum Outcome { + PREFERRED, FALLBACK, UNKNOWN + } + + void register(ConfigurationSource conf) { + sourceName = MetricUtil.getMetricsSourceName(SOURCE_NAME, + conf == null ? null : conf.get(OMConfigKeys.OZONE_OM_INTERNAL_SERVICE_ID), + conf == null ? null : conf.get(OMConfigKeys.OZONE_OM_NODE_ID_KEY)); + DefaultMetricsSystem.instance().register(sourceName, "OM storage policy commit metrics", this); Review Comment: Do we need to have something like ``` if (notRegistered) { // then register } ``` Basically what if `register` is called multiple times? -- 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]
