suneet-s commented on code in PR #12730:
URL: https://github.com/apache/druid/pull/12730#discussion_r912299269


##########
server/src/main/java/org/apache/druid/server/metrics/SegmentRowCountBuckets.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.druid.server.metrics;
+
+import org.apache.druid.java.util.emitter.EmittingLogger;
+
+import java.util.function.ObjIntConsumer;
+
+/**
+ * Class that creates a count of segments that have row counts in certain 
buckets
+ */
+public class SegmentRowCountBuckets
+{
+  private static final EmittingLogger log = new 
EmittingLogger(SegmentRowCountBuckets.class);
+
+  private final int[] buckets = new int[8];
+
+  /**
+   * Increments the count for a particular bucket held in this class
+   *
+   * @param rowCount the number of rows to figure out which bucket to increment
+   */
+  public void addRowCountToBucket(long rowCount)
+  {
+    int bucketIndex = determineBucket(rowCount);
+    buckets[bucketIndex]++;
+  }
+
+  /**
+   * Decrements the count for a particular bucket held in this class
+   *
+   * @param rowCount the count which determines which bucket to decrement
+   */
+  public void removeRowCountfromBucket(long rowCount)
+  {
+    int bucketIndex = determineBucket(rowCount);
+    buckets[bucketIndex]--;
+    if (buckets[bucketIndex] < 0) {
+      // can this ever go negative?
+      log.error("somehow got a count of less than 0, resetting value to 0");
+      buckets[bucketIndex] = 0;
+    }
+  }
+
+  /**
+   * Determines the name of the dimension used for a bucket
+   *
+   * @param index the index of the bucket
+   * @return the dimension which the bucket index refers to
+   */
+  static String getBucketDimensionFromIndex(int index)
+  {
+    switch (index) {
+      case 0:

Review Comment:
   Since there are a few ways number of rows can be reported as 0 - eg. lazy 
loading, I think we should have the first bucket be `0` The next bucket can be 
`1 - 10k`
   
   So to end up with ~ 8 buckets. How about these ranges
   * 0
   * 1 - 10k
   * 10k  - 2M
   * 2M - 4M
   * 4M - 6M
   * 6M - 10M
   * 10M+
   * NA



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

Reply via email to