neils-dev commented on code in PR #4140: URL: https://github.com/apache/ozone/pull/4140#discussion_r1094141293
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMHAMetrics.java: ########## @@ -0,0 +1,142 @@ +/** + * 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.ozone.om.ha; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; +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; + +/** + * Class to maintain metrics and info related to OM HA. + */ +@Metrics(about = "OzoneManager HA Metrics", context = OzoneConsts.OZONE) +public final class OMHAMetrics implements MetricsSource { + + private enum OMHAMetricsInfo implements MetricsInfo { + + OzoneManagerHALeaderState("Leader active state " + + "of OzoneManager node (1 leader, 0 follower)"), + NodeId("OM node Id"); + + private final String description; + + OMHAMetricsInfo(String description) { + this.description = description; + } + + @Override + public String description() { + return description; + } + } + + /** + * Private nested class to hold + * the values of OMHAMetricsInfo. + */ + private static final class OMHAInfo { + + private long ozoneManagerHALeaderState; + private String nodeId; + + OMHAInfo() { + this.ozoneManagerHALeaderState = 0L; + this.nodeId = ""; + } + + public long getOzoneManagerHALeaderState() { + return ozoneManagerHALeaderState; + } + + public void setOzoneManagerHALeaderState(long ozoneManagerHALeaderState) { + this.ozoneManagerHALeaderState = ozoneManagerHALeaderState; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + } + + public static final String SOURCE_NAME = + OMHAMetrics.class.getSimpleName(); + private final OMHAInfo omhaInfo = new OMHAInfo(); + private MetricsRegistry metricsRegistry; + + private String currNodeId; + private String leaderId; + + public OMHAMetrics(String currNodeId, String leaderId) { + this.currNodeId = currNodeId; + this.leaderId = leaderId; + this.metricsRegistry = new MetricsRegistry(SOURCE_NAME); + } + + /** + * Create and return OMHAMetrics instance. + * @return OMHAMetrics + */ + public static synchronized OMHAMetrics create( Review Comment: Does this need to be _synchonized_? An intrinsic lock? There should be a single access to create and register with the `MetricsSystem`, then it will pull the metrics periodically. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMHAMetrics.java: ########## @@ -0,0 +1,142 @@ +/** + * 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.ozone.om.ha; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; +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; + +/** + * Class to maintain metrics and info related to OM HA. + */ +@Metrics(about = "OzoneManager HA Metrics", context = OzoneConsts.OZONE) +public final class OMHAMetrics implements MetricsSource { + + private enum OMHAMetricsInfo implements MetricsInfo { + + OzoneManagerHALeaderState("Leader active state " + + "of OzoneManager node (1 leader, 0 follower)"), + NodeId("OM node Id"); + + private final String description; + + OMHAMetricsInfo(String description) { + this.description = description; + } + + @Override + public String description() { + return description; + } + } + + /** + * Private nested class to hold + * the values of OMHAMetricsInfo. + */ + private static final class OMHAInfo { + + private long ozoneManagerHALeaderState; + private String nodeId; + + OMHAInfo() { + this.ozoneManagerHALeaderState = 0L; + this.nodeId = ""; + } + + public long getOzoneManagerHALeaderState() { + return ozoneManagerHALeaderState; + } + + public void setOzoneManagerHALeaderState(long ozoneManagerHALeaderState) { + this.ozoneManagerHALeaderState = ozoneManagerHALeaderState; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + } + + public static final String SOURCE_NAME = + OMHAMetrics.class.getSimpleName(); + private final OMHAInfo omhaInfo = new OMHAInfo(); + private MetricsRegistry metricsRegistry; + + private String currNodeId; + private String leaderId; + + public OMHAMetrics(String currNodeId, String leaderId) { Review Comment: This should be private. The constructor is only accessed by this class. Users create an instance through the static `create` method, OMHAMetrics.create, `public static synchronized OMHAMetrics create` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMHAMetrics.java: ########## @@ -0,0 +1,142 @@ +/** + * 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.ozone.om.ha; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; +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; + +/** + * Class to maintain metrics and info related to OM HA. + */ +@Metrics(about = "OzoneManager HA Metrics", context = OzoneConsts.OZONE) +public final class OMHAMetrics implements MetricsSource { + + private enum OMHAMetricsInfo implements MetricsInfo { Review Comment: Thanks @xBis7 for the recent changes. For the `MetricsInfo` used in the `OMHAMetrics` tag and gauge, we should re-use the Interns.info static method just as the other metrics instances do, https://github.com/apache/hadoop/blob/03cfc852791c14fad39db4e5b14104a276c08e59/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/Interns.java#L117. In our case we can declare 2 static `MetricsInfo` members in the static nested class, `OMHAInfo,` one for the `OzoneManagerHALeaderState`, the other for the `NodeID`, ie: ``` OMHAInfo { ... private static final MetricsInfo OZONEMANAGER_HA_LEADER_STATE = Interns.info( "OzoneManagerHALeaderState", <desc>); } ... ``` -- 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]
