nfsantos commented on code in PR #1182:
URL: https://github.com/apache/jackrabbit-oak/pull/1182#discussion_r1394404746


##########
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 added documentation explaining the intended use of this method and renamed 
it to `setCounterOnce`. I did not rename the class as that seems excessive. And 
in the future we may want to have other util methods in this class that do not 
have the restriction of this method. 
   
   I'm not totally satisfied with this design, maybe this can be revised in a 
future PR. One option would be to update the metrics directly when the events 
occur instead of having internal counters. But for the time being, I think this 
will be enough.



-- 
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]

Reply via email to