Phillippko commented on code in PR #7647:
URL: https://github.com/apache/ignite-3/pull/7647#discussion_r2845979419


##########
modules/runner/src/main/java/org/apache/ignite/internal/metrics/logstorage/LogStorageMetrics.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.logstorage;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.hasCause;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.raft.storage.LogStorageManager;
+import 
org.apache.ignite.internal.raft.storage.impl.VolatileLogStorageManagerCreator;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+
+/**
+ * Component that collects metrics about log storages.
+ */
+public class LogStorageMetrics implements IgniteComponent {
+    private static final IgniteLogger LOG = 
Loggers.forClass(LogStorageMetrics.class);
+
+    private static final long DEFAULT_UPDATE_PERIOD_MS = 1000;
+
+    private final String nodeName;
+
+    private final MetricManager metricManager;
+
+    private final LogStorageManager cmgLogStorageManager;
+    private final LogStorageManager metastorageLogStorageManager;
+    private final LogStorageManager partitionsLogStorageManager;
+    private final VolatileLogStorageManagerCreator 
volatileLogStorageManagerCreator;
+
+    private final long updatePeriodMs;
+
+    private final LogStorageMetricSource metricSource = new 
LogStorageMetricSource();
+
+    private volatile ScheduledExecutorService executorService;
+    private volatile ScheduledFuture<?> taskFuture;
+
+    /** Constructor. */
+    public LogStorageMetrics(
+            String nodeName,
+            MetricManager metricManager,
+            LogStorageManager cmgLogStorageManager,
+            LogStorageManager metastorageLogStorageManager,
+            LogStorageManager partitionsLogStorageManager,
+            VolatileLogStorageManagerCreator volatileLogStorageManagerCreator
+    ) {
+        this(
+                nodeName,
+                metricManager,
+                cmgLogStorageManager,
+                metastorageLogStorageManager,
+                partitionsLogStorageManager,
+                volatileLogStorageManagerCreator,
+                DEFAULT_UPDATE_PERIOD_MS
+        );
+    }
+
+    /** Constructor. */
+    LogStorageMetrics(
+            String nodeName,
+            MetricManager metricManager,
+            LogStorageManager cmgLogStorageManager,
+            LogStorageManager metastorageLogStorageManager,
+            LogStorageManager partitionsLogStorageManager,
+            VolatileLogStorageManagerCreator volatileLogStorageManagerCreator,
+            long updatePeriodMs
+    ) {
+        this.nodeName = nodeName;
+        this.metricManager = metricManager;
+        this.cmgLogStorageManager = cmgLogStorageManager;
+        this.metastorageLogStorageManager = metastorageLogStorageManager;
+        this.partitionsLogStorageManager = partitionsLogStorageManager;
+        this.volatileLogStorageManagerCreator = 
volatileLogStorageManagerCreator;
+        this.updatePeriodMs = updatePeriodMs;
+    }
+
+    @Override
+    public CompletableFuture<Void> startAsync(ComponentContext 
componentContext) {
+        metricManager.registerSource(metricSource);
+        metricManager.enable(metricSource);
+
+        executorService = Executors.newSingleThreadScheduledExecutor(
+                IgniteThreadFactory.create(nodeName, 
"log-storage-metrics-collector", LOG)
+        );
+        taskFuture = executorService.scheduleAtFixedRate(this::updateMetrics, 
0, updatePeriodMs, MILLISECONDS);
+
+        return nullCompletedFuture();
+    }
+
+    private void updateMetrics() {
+        try {
+            
metricSource.cmgLogStorageSize(cmgLogStorageManager.totalBytesOnDisk());

Review Comment:
   I wonder why we need this component to update storage size instead of 
calling cmgLogStorageManager.totalBytesOnDisk() from LogStorageMetricSource 
every time we need to export metrics? I think this is the usual approach



##########
modules/raft/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItLogStorageMetricsTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.raftsnapshot;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.randomBytes;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.Random;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.raft.storage.impl.DefaultLogStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class ItLogStorageMetricsTest extends ClusterPerTestIntegrationTest {
+    private static final String TABLE_NAME = "TEST_TABLE";
+
+    private Ignite node;
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @BeforeEach
+    void prepare() {
+        node = cluster.node(0);
+    }
+
+    @Test
+    void totalLogStorageMetricIsUpdated() throws Exception {
+        LongGauge totalLogStorageSize = totalLogStorageSizeGauge();
+
+        int valueLength = 1_000_000;
+
+        feedLogStorageWithBlob(valueLength);
+
+        await().alias("Total log storage size should reach the expected value")
+                .until(totalLogStorageSize::value, 
is(greaterThanOrEqualTo((long) valueLength)));
+    }
+
+    private LongGauge totalLogStorageSizeGauge() {
+        MetricSet logStorageMetrics = unwrapIgniteImpl(node)
+                .metricManager()
+                .metricSnapshot()
+                .metrics()
+                .get("log.storage");
+        assertThat(logStorageMetrics, is(notNullValue()));
+
+        LongGauge totalLogStorageSize = 
logStorageMetrics.get("TotalLogStorageSize");

Review Comment:
   why in this test we check only total log  storage size? 



##########
modules/metrics/src/testFixtures/java/org/apache/ignite/internal/metrics/TestMetricManager.java:
##########
@@ -110,6 +111,7 @@ public Collection<MetricExporter> enabledExporters() {
     }
 
     /** Returns the metric for the arguments if it exists. */
+    @TestOnly

Review Comment:
   is there any sense adding test only annotation for test manager class? 



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