dant3 commented on code in PR #7855:
URL: https://github.com/apache/ignite-3/pull/7855#discussion_r3010724858


##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/SimpleMetricSource.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.ignite.internal.metrics;
+
+import java.util.HashMap;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * A {@link MetricSource} with factory methods for creating and registering 
metrics.
+ *
+ * <p>Metrics are created via factory methods and stored in a {@link 
ConcurrentHashMap}.
+ * Enable/disable controls registry visibility only — metrics themselves are 
always alive
+ * and values persist across enable/disable cycles.
+ *
+ * <p>Usage:
+ * <pre>{@code
+ * public class MyMetrics {
+ *     private final LongAdderMetric requests;
+ *     private final DistributionMetric duration;
+ *
+ *     public MyMetrics(SimpleMetricSource source) {
+ *         requests = source.longAdder("Requests", "Total requests.");
+ *         duration = source.distribution("Duration", "Request duration in 
ms.",
+ *                 new long[]{1, 5, 10, 50, 100, 500});
+ *     }
+ *
+ *     public void onRequest(long durationMs) {
+ *         requests.increment();
+ *         duration.add(durationMs);
+ *     }
+ * }
+ * }</pre>
+ */
+public final class SimpleMetricSource implements MetricSource {
+    private final String name;
+
+    private final @Nullable String description;
+
+    private final @Nullable String group;
+
+    private final ConcurrentHashMap<String, Metric> metrics = new 
ConcurrentHashMap<>();
+
+    /** Non-null when enabled. */
+    private @Nullable MetricSet metricSet;
+
+    /** Constructor. */
+    public SimpleMetricSource(String name) {
+        this(name, null, null);
+    }
+
+    /** Constructor. */
+    public SimpleMetricSource(String name, @Nullable String description) {
+        this(name, description, null);
+    }
+
+    /** Constructor. */
+    public SimpleMetricSource(String name, @Nullable String description, 
@Nullable String group) {

Review Comment:
   It's used for grouping in JMX: sources with the same group get folded under 
one MBean folder. Most sources don't set it. This is a preexisting contract of 
our metrics framework.



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