thomasmueller commented on code in PR #1182: URL: https://github.com/apache/jackrabbit-oak/pull/1182#discussion_r1394235775
########## oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoDownloadTask.java: ########## @@ -191,15 +196,19 @@ public Result call() throws Exception { } else { downloadWithNaturalOrdering(); } - String enqueueingDelayPercentage = String.format("%1.2f", (100.0 * totalEnqueueWaitTimeMillis) / downloadStartWatch.elapsed(TimeUnit.MILLISECONDS)); + double enqueueingDelayPercentage = (100.0 * totalEnqueueWaitTimeMillis) / downloadStartWatch.elapsed(TimeUnit.MILLISECONDS); Review Comment: Possible division by zero ########## oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/MetricsUtils.java: ########## @@ -0,0 +1,40 @@ +/* + * 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.jackrabbit.oak.plugins.index; + +import org.apache.jackrabbit.oak.stats.CounterStats; +import org.apache.jackrabbit.oak.stats.StatisticsProvider; +import org.apache.jackrabbit.oak.stats.StatsOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MetricsUtils { + private final static Logger LOG = LoggerFactory.getLogger(MetricsUtils.class); + + public static void setCounter(StatisticsProvider statisticsProvider, String name, long value) { + CounterStats metric = statisticsProvider.getCounterStats(name, StatsOptions.METRICS_ONLY); + LOG.debug("Adding metric: {} {}", name, value); + if (metric.getCount() != 0) { + LOG.warn("Counter was not 0: {} {}", name, metric.getCount()); Review Comment: I understand that metrics are used for logging in this case, so each metric is only set once, and then it is not supposed to be called. But that's not the normal usage of metrics. In my view, it is using metrics for something that metrics are not designed for: to log. The main issue, of course, is that delivering the metrics update may not work. It is fine if metrics are not sent from time to time. I understand you do this on purpose, kind of a "best effort". But someone else that sees this class doesn't know that. He will think "MetricsUtils.setCounter... nice, I'll use that". And then we fill the log with warnings... What about adding Javadocs to the class, then renaming the class to "SetOnceMetricsUtils" and the method to "setCounterOnce"? That way, it is more clear about the intended usage, and avoid confusion (and so unnecessarily filling the log file). -- 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: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org