uds5501 commented on code in PR #18314:
URL: https://github.com/apache/druid/pull/18314#discussion_r2227583569


##########
server/src/main/java/org/apache/druid/server/metrics/NoopSegmentDiscoveryStatsProviderImpl.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.druid.server.metrics;
+
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.Map;
+
+public class NoopSegmentDiscoveryStatsProviderImpl implements 
SegmentDiscoveryStatsProvider

Review Comment:
   Per my reply here - 
https://github.com/apache/druid/pull/18314#discussion_r2227580619, Iam inclined 
to keep this class 



##########
server/src/main/java/org/apache/druid/server/metrics/SegmentDiscoveryStatsProviderImpl.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.utils.CollectionUtils;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SegmentDiscoveryStatsProviderImpl implements 
SegmentDiscoveryStatsProvider
+{
+
+  private final ConcurrentHashMap<RowKey, AtomicLong> 
totalSuccessfulSegmentLoadCount = new ConcurrentHashMap<>();
+  @GuardedBy("totalSuccessfulSegmentLoadCount")
+  private Map<RowKey, Long> previousSuccessfulSegmentLoadCount = new 
HashMap<>();
+
+  @Override
+  public Map<RowKey, Long> getTotalSuccessfulSegmentLoadCount()
+  {
+    final Map<RowKey, Long> total = 
CollectionUtils.mapValues(totalSuccessfulSegmentLoadCount, AtomicLong::get);
+    synchronized (totalSuccessfulSegmentLoadCount) {
+      final Map<RowKey, Long> delta = getDeltaValues(total, 
previousSuccessfulSegmentLoadCount);
+      previousSuccessfulSegmentLoadCount = total;
+      return delta;
+    }
+  }
+
+  @Override
+  public long incrementSuccessfulSegmentDiscoverCount(DataSegment segment)
+  {
+    return incrementAndGetLong(totalSuccessfulSegmentLoadCount, 
getMetricKey(segment));
+  }
+
+  private static long incrementAndGetLong(ConcurrentHashMap<RowKey, 
AtomicLong> counters, RowKey key)
+  {
+    AtomicLong counter = counters.get(key);
+    if (counter == null) {
+      counter = counters.computeIfAbsent(key, k -> new AtomicLong());
+    }
+    return counter.incrementAndGet();
+  }
+
+  private Map<RowKey, Long> getDeltaValues(Map<RowKey, Long> total, 
Map<RowKey, Long> prev)
+  {
+    final Map<RowKey, Long> deltaValues = new HashMap<>();
+    total.forEach(
+        (dataSource, totalCount) -> deltaValues.put(
+            dataSource,
+            totalCount - prev.getOrDefault(dataSource, 0L)
+        )
+    );
+    return deltaValues;
+  }
+
+  private static RowKey getMetricKey(final DataSegment segment)
+  {
+    if (segment == null) {
+      return RowKey.empty();
+    }
+    return RowKey.with(Dimension.DATASOURCE, segment.getDataSource()).build();

Review Comment:
   Yeah fair, extending this



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