gortiz commented on code in PR #17674: URL: https://github.com/apache/pinot/pull/17674#discussion_r2821617933
########## pinot-core/src/main/java/org/apache/pinot/core/transport/NettyInspector.java: ########## @@ -0,0 +1,158 @@ +/** + * 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.pinot.core.transport; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Function; +import javax.annotation.Nullable; +import org.apache.pinot.common.metrics.AbstractMetrics; +import org.apache.pinot.spi.utils.DataSizeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/// Utility class to inspect Netty constants and log their values, with the ability to check for specific conditions +/// and log warnings if they are not met. +public class NettyInspector { + private static final Logger LOGGER = LoggerFactory.getLogger(NettyInspector.class); + /// We use a CopyOnWriteArrayList to allow dynamic addition of checks at runtime, if needed. + public static final CopyOnWriteArrayList<Check> CHECKS; + /// We use a CopyOnWriteArrayList to allow dynamic addition of Netty instances at runtime, + /// if needed (e.g. if we want to support other shaded versions of Netty). + public static final CopyOnWriteArrayList<NettyInstance> KNOWN_INSTANCES; + + static { + CHECKS = new CopyOnWriteArrayList<>( + new Check[] { + NettyInspector::checkDirectMemory + } + ); + KNOWN_INSTANCES = new CopyOnWriteArrayList<>(new NettyInstance[] { + new NettyInstance.UnshadedNettyInstance(), + new NettyInstance.GrpcNettyInstance() + }); + } + + private NettyInspector() { + // Private constructor to prevent instantiation + } + + public static void registerMetrics(AbstractMetrics<?, ?, ?, ?> metrics) { + for (NettyInstance instance : KNOWN_INSTANCES) { + metrics.setOrUpdateGauge(instance.getName() + "NettyDirectMemoryUsed", + instance::getUsedDirectMemory); + metrics.setOrUpdateGauge(instance.getName() + "NettyDirectMemoryMax", + instance::getMaxDirectMemory); + } + } + + /// Logs the memory used by each known Netty instance as long as the max memory it can use. + /// It also logs the total memory used by all Netty instances and its max memory. + public static void logMemory() { Review Comment: Removed -- 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]
