EdColeman commented on code in PR #4527: URL: https://github.com/apache/accumulo/pull/4527#discussion_r1591413838
########## server/base/src/main/java/org/apache/accumulo/server/metrics/NoOpDistributionSummary.java: ########## @@ -0,0 +1,78 @@ +/* + * 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 + * + * https://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.accumulo.server.metrics; + +import io.micrometer.core.instrument.DistributionSummary; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.instrument.distribution.HistogramSnapshot; + +/** + * Provides a default DistributionSummary that does not do anything. This can be used to prevent NPE + * if metrics have not been initialized when a DistributionSummary is expected. + * <p> + * Normally DistributionSummaries are created using a builder that takes a registry. + * + * <pre> + * DistributionSummary distSum; + * ... + * public void registerMetrics(MeterRegistry registry) { + * ... + * distSum = DistributionSummary.builder("metric name") .description("...").register(registry); + * ... + * } + * </pre> + * + * Until the registration is called, the instance variable is null. If code then tries to update the + * metric, a NPE is thrown. Using this class to provide a default value prevents this from occurring + * and on registration, it is replaced with a valid instance. + */ +public class NoOpDistributionSummary implements DistributionSummary { Review Comment: Adding logging (at debug) in 8aaf8776da -- 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: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org