sk0x50 commented on code in PR #5901:
URL: https://github.com/apache/ignite-3/pull/5901#discussion_r2109606685


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/metrics/ClusterTopologyMetricsSource.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.cluster.management.metrics;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.ignite.internal.cluster.management.ClusterTag;
+import org.apache.ignite.internal.cluster.management.topology.LogicalTopology;
+import org.apache.ignite.internal.metrics.AbstractMetricSource;
+import org.apache.ignite.internal.metrics.IntGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.ObjectGauge;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * The source of cluster topology metrics.
+ */
+public class ClusterTopologyMetricsSource extends 
AbstractMetricSource<ClusterTopologyMetricsSource.Holder> {
+    /** Source name. */
+    static final String SOURCE_NAME = "topology.cluster";
+
+    /** Logical topology. */
+    private final LogicalTopology logicalTopology;
+
+    /** Provider of the cluster's tag. */
+    private final Supplier<ClusterTag> clusterTagSupplier;
+
+    /**
+     * Creates a new instance of the topology metrics source.
+     *
+     * @param logicalTopology Logical topology.
+     * @param clusterTagSupplier Supplier of the cluster's tag.
+     */
+    public ClusterTopologyMetricsSource(LogicalTopology logicalTopology, 
Supplier<ClusterTag> clusterTagSupplier) {
+        super(SOURCE_NAME);
+
+        this.logicalTopology = logicalTopology;
+        this.clusterTagSupplier = clusterTagSupplier;
+    }
+
+    @Override
+    protected Holder createHolder() {
+        return new Holder();
+    }
+
+    /**
+     * Returns name of the cluster.
+     *
+     * @return Name of the cluster, or empty string if the holder is not 
initialized.
+     */
+    public String clusterName() {
+        Holder h = holder();
+
+        if (h == null) {
+            return "";
+        }
+
+        return h.clusterName.value();
+    }
+
+    /**
+     * Returns the unique identifier of the cluster.
+     *
+     * @return Returns the unique identifier of the cluster, or {@code null} 
if the holder is not initialized.
+     */
+    public @Nullable UUID clusterId() {
+        Holder h = holder();
+
+        if (h == null) {
+            return null;
+        }
+
+        return h.clusterId.value();
+    }
+
+    /**
+     * Returns the total number of nodes in the logical topology.
+     *
+     * @return Returns the total number of nodes in the logical topology, or 
{@code 0} if the holder is not initialized.
+     */
+    public int totalNodes() {
+        Holder h = holder();
+
+        if (h == null) {
+            return 0;
+        }
+
+        return h.clusterSize.value();
+    }
+
+    /** Holder. */
+    protected class Holder implements AbstractMetricSource.Holder<Holder> {
+        private final IntGauge clusterSize = new IntGauge(
+                "TotalNodes",
+                "Number of nodes in the logical topology",
+                () -> logicalTopology.getLogicalTopology().nodes().size());
+
+        private final ObjectGauge<UUID> clusterId = new ObjectGauge<>(

Review Comment:
   Ok. `StringGauge` and `UuidGauge` are added.



##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/ObjectMetricImpl.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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 org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {@link ObjectMetric}.
+ */
+public class ObjectMetricImpl<T> extends AbstractMetric implements 
ObjectMetric<T> {
+    /** Value. */
+    private volatile T val;
+
+    /** Type. */
+    private final Class<T> type;
+
+    /**
+     * Creates a new instance of ObjectMetricImpl.
+     *
+     * @param name Name.
+     * @param desc Description.
+     * @param type Type.
+     */
+    public ObjectMetricImpl(String name, @Nullable String desc, Class<T> type) 
{

Review Comment:
   Removed.



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to