This is an automated email from the ASF dual-hosted git repository.
sanpwc pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 929c9d370c7 IGNITE-25938 Add the metric log exporter to the default
configuration (#6350)
929c9d370c7 is described below
commit 929c9d370c7ff38d6f59ff87e9540ddb266d449c
Author: Denis Chudov <[email protected]>
AuthorDate: Mon Aug 4 14:00:02 2025 +0300
IGNITE-25938 Add the metric log exporter to the default configuration
(#6350)
---
.../metrics/exporters/ItOtlpMetricsTest.java | 4 +-
modules/metrics/build.gradle | 2 +
.../ItLogPushExporterEnabledByDefault.java | 48 ++++++++++++++++++++++
.../ignite/internal/metrics/MetricManagerImpl.java | 48 +++++++++++++++++++++-
.../LogPushExporterConfigurationSchema.java | 11 +++--
.../metrics/exporters/log/LogPushExporter.java | 11 +++--
.../java/org/apache/ignite/internal/Cluster.java | 3 +-
7 files changed, 114 insertions(+), 13 deletions(-)
diff --git
a/modules/metrics-exporter-otlp/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItOtlpMetricsTest.java
b/modules/metrics-exporter-otlp/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItOtlpMetricsTest.java
index dd0ebb2e1fb..59d24f47205 100644
---
a/modules/metrics-exporter-otlp/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItOtlpMetricsTest.java
+++
b/modules/metrics-exporter-otlp/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItOtlpMetricsTest.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.metrics.exporters;
import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -95,7 +95,7 @@ public class ItOtlpMetricsTest extends
ClusterPerTestIntegrationTest {
cluster.runningNodes().forEach(node -> {
MetricManager metricManager =
unwrapIgniteImpl(node).metricManager();
- assertThat(metricManager.enabledExporters(),
contains(instanceOf(OtlpPushMetricExporter.class)));
+ assertThat(metricManager.enabledExporters(),
containsInRelativeOrder(instanceOf(OtlpPushMetricExporter.class)));
});
assertFalse(logInspector.isMatched());
diff --git a/modules/metrics/build.gradle b/modules/metrics/build.gradle
index 0125814c166..288f8ff5fc3 100644
--- a/modules/metrics/build.gradle
+++ b/modules/metrics/build.gradle
@@ -43,6 +43,8 @@ dependencies {
integrationTestAnnotationProcessor
project(':ignite-configuration-annotation-processor')
integrationTestAnnotationProcessor libs.auto.service
integrationTestImplementation project(':ignite-core')
+ integrationTestImplementation project(':ignite-api')
+ integrationTestImplementation project(':ignite-runner')
integrationTestImplementation testFixtures(project(':ignite-core'))
integrationTestImplementation
testFixtures(project(':ignite-configuration'))
integrationTestImplementation testFixtures(project(':ignite-runner'))
diff --git
a/modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItLogPushExporterEnabledByDefault.java
b/modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItLogPushExporterEnabledByDefault.java
new file mode 100644
index 00000000000..868c4ca8ad9
--- /dev/null
+++
b/modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/ItLogPushExporterEnabledByDefault.java
@@ -0,0 +1,48 @@
+/*
+ * 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.exporters;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInRelativeOrder;
+import static org.hamcrest.Matchers.instanceOf;
+
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.metrics.exporters.log.LogPushExporter;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Checks that log exporter is enabled by default.
+ */
+public class ItLogPushExporterEnabledByDefault extends
ClusterPerClassIntegrationTest {
+ @Override
+ protected int initialNodes() {
+ return 1;
+ }
+
+ @Test
+ public void checkThatLogExporterIsEnabledByDefault() {
+ IgniteImpl ignite =
unwrapIgniteImpl(CLUSTER.runningNodes().findAny().orElseThrow());
+
+ MetricManager metricManager = ignite.metricManager();
+
+ assertThat(metricManager.enabledExporters(),
containsInRelativeOrder(instanceOf(LogPushExporter.class)));
+ }
+}
diff --git
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java
index 1a027988d65..c734faa2ac6 100644
---
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java
+++
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java
@@ -17,6 +17,8 @@
package org.apache.ignite.internal.metrics;
+import static java.util.Collections.emptyList;
+import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.internal.util.IgniteUtils.closeAllManually;
@@ -27,6 +29,7 @@ import static
org.apache.ignite.lang.ErrorGroups.Common.RESOURCE_CLOSING_ERR;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;
@@ -48,6 +51,9 @@ import
org.apache.ignite.internal.metrics.configuration.MetricConfiguration;
import org.apache.ignite.internal.metrics.configuration.MetricView;
import org.apache.ignite.internal.metrics.exporters.MetricExporter;
import org.apache.ignite.internal.metrics.exporters.configuration.ExporterView;
+import
org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterConfigurationSchema;
+import
org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterView;
+import org.apache.ignite.internal.metrics.exporters.log.LogPushExporter;
import org.apache.ignite.internal.util.IgniteSpinBusyLock;
import org.jetbrains.annotations.VisibleForTesting;
@@ -121,7 +127,10 @@ public class MetricManagerImpl implements MetricManager {
MetricView conf = metricConfiguration.value();
- for (ExporterView exporter : conf.exporters()) {
+ List<ExporterView> exporters =
conf.exporters().stream().collect(toList());
+ exporters.addAll(defaultExporters(exporters));
+
+ for (ExporterView exporter : exporters) {
checkAndStartExporter(exporter.exporterName(), exporter);
}
@@ -247,6 +256,43 @@ public class MetricManagerImpl implements MetricManager {
return inBusyLock(busyLock, enabledMetricExporters::values);
}
+ private static List<ExporterView> defaultExporters(List<? extends
ExporterView> configuredExporters) {
+ if
(configuredExporters.stream().map(ExporterView::exporterName).anyMatch(n ->
n.equals(LogPushExporter.EXPORTER_NAME))) {
+ return emptyList();
+ } else {
+ ExporterView logExporterView = new LogPushExporterView() {
+ private final LogPushExporterConfigurationSchema schema = new
LogPushExporterConfigurationSchema();
+
+ @Override
+ public long periodMillis() {
+ return schema.periodMillis;
+ }
+
+ @Override
+ public boolean oneLinePerMetricSource() {
+ return schema.oneLinePerMetricSource;
+ }
+
+ @Override
+ public String[] enabledMetrics() {
+ return schema.enabledMetrics;
+ }
+
+ @Override
+ public String exporterName() {
+ return LogPushExporter.EXPORTER_NAME;
+ }
+
+ @Override
+ public String name() {
+ return "log";
+ }
+ };
+
+ return List.of(logExporterView);
+ }
+ }
+
private void checkAndStartExporter(String exporterName, ExporterView
exporterConfiguration) {
MetricExporter exporter = availableExporters.get(exporterName);
diff --git
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/configuration/LogPushExporterConfigurationSchema.java
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/configuration/LogPushExporterConfigurationSchema.java
index 6ae7512d9cf..cc100d00ac1 100644
---
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/configuration/LogPushExporterConfigurationSchema.java
+++
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/configuration/LogPushExporterConfigurationSchema.java
@@ -37,9 +37,14 @@ public class LogPushExporterConfigurationSchema extends
ExporterConfigurationSch
public boolean oneLinePerMetricSource = true;
/**
- * List of enabled metric sources. If not empty, metric sources that are
not enumerated will be not printed.
- * Wildcard '*' can be used in the end of each item.
+ * List of enabled metric sources. If not empty, metric sources that are
not enumerated will not be printed.
+ * Wildcard '*' can be used in the end of each item. Some metrics are
logged by default. To disable it, specify the empty list here
+ * explicitly. To print all metrics, include single string '*'.
*/
@Value(hasDefault = true)
- public String[] enabledMetrics = { };
+ public String[] enabledMetrics = {
+ "metastorage",
+ "placement-driver",
+ "resource.vacuum"
+ };
}
diff --git
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporter.java
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporter.java
index 4eb00a013f6..20cccd68589 100644
---
a/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporter.java
+++
b/modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporter.java
@@ -67,17 +67,17 @@ public class LogPushExporter extends PushMetricExporter {
public void report() {
Collection<MetricSet> metricSets = snapshot().metrics().values();
- if (CollectionUtils.nullOrEmpty(metricSets)) {
+ if (CollectionUtils.nullOrEmpty(metricSets) ||
CollectionUtils.nullOrEmpty(enabledMetrics)) {
return;
}
- var report = new StringBuilder("Metric report: \n");
+ var report = new StringBuilder("Metric report:");
for (MetricSet metricSet : metricSets) {
boolean hasMetricsWhiteList = hasMetricsWhiteList(metricSet);
if (hasMetricsWhiteList || metricEnabled(metricSet.name())) {
- report.append(metricSet.name()).append(oneLinePerMetricSource
? ' ' : ':');
+
report.append('\n').append(metricSet.name()).append(oneLinePerMetricSource ? '
' : ':');
appendMetrics(report, metricSet, hasMetricsWhiteList);
}
@@ -108,7 +108,7 @@ public class LogPushExporter extends PushMetricExporter {
}
private String metricSetPostfix() {
- return oneLinePerMetricSource ? "]\n" : "\n";
+ return oneLinePerMetricSource ? "]" : "";
}
private static void appendMetricWithValue(boolean oneLinePerMetricSource,
StringBuilder sb, Metric m, int index) {
@@ -120,8 +120,7 @@ public class LogPushExporter extends PushMetricExporter {
}
private boolean metricEnabled(String name) {
- return enabledMetrics.isEmpty()
- || findAny(enabledMetrics, em -> nameMatches(name,
em)).isPresent();
+ return findAny(enabledMetrics, em -> nameMatches(name,
em)).isPresent();
}
private static String fqn(MetricSet ms, Metric m) {
diff --git
a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
index b1d9ae4b152..77d5ff30242 100644
---
a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
+++
b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
@@ -234,7 +234,8 @@ public class Cluster {
InitParametersBuilder builder = InitParameters.builder()
.metaStorageNodes(metaStorageAndCmgNodes)
- .clusterName(clusterConfiguration.clusterName());
+ .clusterName(clusterConfiguration.clusterName())
+ .clusterConfiguration("ignite { metrics: { exporters { log {
exporterName = logPush, periodMillis = 10000 } } } }");
initParametersConfigurator.accept(builder);