You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "nva (via GitHub)" <gi...@apache.org> on 2024/12/04 15:37:19 UTC
[PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
nva opened a new pull request, #4832:
URL: https://github.com/apache/ignite-3/pull/4832
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1877239249
##########
modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/TestPushMetricExporter.java:
##########
@@ -36,23 +33,13 @@ public class TestPushMetricExporter extends PushMetricExporter<TestPushMetricsEx
private static OutputStream outputStream;
- private long period;
-
- @Override
- public void start(MetricProvider metricsProvider, TestPushMetricsExporterView configuration, Supplier<UUID> clusterIdSupplier,
- String nodeName) {
- period = configuration.period();
-
- super.start(metricsProvider, configuration, clusterIdSupplier, nodeName);
- }
-
public static void setOutputStream(OutputStream outputStream) {
TestPushMetricExporter.outputStream = outputStream;
}
@Override
protected long period() {
- return period;
+ return configuration().period();
Review Comment:
Because configuration in ancestor PushMetricExporter has type ExporterView which is common for push and pull exporters and doesn't contain period. At the same time configuration framework doesn't allow to create base class for PushExporterConfigurationSchema as ExporterConfigurationSchema is a polymorphic configuration.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1877268133
##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporterTest.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.log;
+
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.metrics.AbstractMetricSource;
+import org.apache.ignite.internal.metrics.AtomicDoubleMetric;
+import org.apache.ignite.internal.metrics.AtomicIntMetric;
+import org.apache.ignite.internal.metrics.AtomicLongMetric;
+import org.apache.ignite.internal.metrics.DistributionMetric;
+import org.apache.ignite.internal.metrics.DoubleAdderMetric;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.HitRateMetric;
+import org.apache.ignite.internal.metrics.IntGauge;
+import org.apache.ignite.internal.metrics.LongAdderMetric;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.metrics.MetricManagerImpl;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.configuration.MetricChange;
+import org.apache.ignite.internal.metrics.configuration.MetricConfiguration;
+import org.apache.ignite.internal.metrics.exporters.PushMetricExporter;
+import org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterChange;
+import org.apache.ignite.internal.metrics.exporters.jmx.JmxExporter;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.logging.log4j.core.LogEvent;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Tests for {@link JmxExporter}.
+ */
+@ExtendWith({ConfigurationExtension.class})
+public class LogPushExporterTest extends BaseIgniteAbstractTest {
+ @InjectConfiguration("mock.exporters = {log = {exporterName = logPush, period = 300}}")
+ private MetricConfiguration metricConfiguration;
+
+ private static final UUID CLUSTER_ID = UUID.randomUUID();
+
+ private static final String SRC_NAME = "testSource";
+
+ private static final String MTRC_NAME = "testMetric";
+
+ /**
+ * Metric set with all available metric types.
+ */
+ private static final MetricSet metricSet =
+ new MetricSet(
+ SRC_NAME,
+ Map.of(
+ "intGauge", new IntGauge("intGauge", "", () -> 1),
+ "longGauge", new LongGauge("longGauge", "", () -> 1L),
+ "doubleGauge", new DoubleGauge("doubleGauge", "", () -> 1d),
+ "atomicInt", new AtomicIntMetric("atomicInt", ""),
+ "atomicLong", new AtomicLongMetric("atomicLong", ""),
+ "atomicDouble", new AtomicDoubleMetric("atomicDouble", ""),
+ "longAdder", new LongAdderMetric("longAdder", ""),
+ "doubleAdder", new DoubleAdderMetric("doubleAdder", ""),
+ "distributionMetric", new DistributionMetric("distributionMetric", "", new long[] {0, 1}),
+ "hitRate", new HitRateMetric("hitRate", "", Long.MAX_VALUE)
+ )
+ );
+
+ private MetricManager metricManager;
+
+ private LogPushExporter exporter;
+
+ @BeforeEach
+ void setUp() {
+ metricManager = new MetricManagerImpl();
+ metricManager.configure(metricConfiguration, () -> CLUSTER_ID, "nodeName");
+ metricManager.registerSource(new TestMetricSource(metricSet));
+
+ exporter = new LogPushExporter();
+ }
+
+ @AfterEach
+ void tearDown() {
+ exporter.stop();
+ }
+
+ @Test
+ void testStart() {
+ metricManager.enable(metricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ Awaitility.await()
+ .atMost(Duration.ofMillis(500L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testEnableMetricSet() {
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
Review Comment:
Yes, removed.
##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporterTest.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.log;
+
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.metrics.AbstractMetricSource;
+import org.apache.ignite.internal.metrics.AtomicDoubleMetric;
+import org.apache.ignite.internal.metrics.AtomicIntMetric;
+import org.apache.ignite.internal.metrics.AtomicLongMetric;
+import org.apache.ignite.internal.metrics.DistributionMetric;
+import org.apache.ignite.internal.metrics.DoubleAdderMetric;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.HitRateMetric;
+import org.apache.ignite.internal.metrics.IntGauge;
+import org.apache.ignite.internal.metrics.LongAdderMetric;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.metrics.MetricManagerImpl;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.configuration.MetricChange;
+import org.apache.ignite.internal.metrics.configuration.MetricConfiguration;
+import org.apache.ignite.internal.metrics.exporters.PushMetricExporter;
+import org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterChange;
+import org.apache.ignite.internal.metrics.exporters.jmx.JmxExporter;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.logging.log4j.core.LogEvent;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Tests for {@link JmxExporter}.
+ */
+@ExtendWith({ConfigurationExtension.class})
+public class LogPushExporterTest extends BaseIgniteAbstractTest {
+ @InjectConfiguration("mock.exporters = {log = {exporterName = logPush, period = 300}}")
+ private MetricConfiguration metricConfiguration;
+
+ private static final UUID CLUSTER_ID = UUID.randomUUID();
+
+ private static final String SRC_NAME = "testSource";
+
+ private static final String MTRC_NAME = "testMetric";
+
+ /**
+ * Metric set with all available metric types.
+ */
+ private static final MetricSet metricSet =
+ new MetricSet(
+ SRC_NAME,
+ Map.of(
+ "intGauge", new IntGauge("intGauge", "", () -> 1),
+ "longGauge", new LongGauge("longGauge", "", () -> 1L),
+ "doubleGauge", new DoubleGauge("doubleGauge", "", () -> 1d),
+ "atomicInt", new AtomicIntMetric("atomicInt", ""),
+ "atomicLong", new AtomicLongMetric("atomicLong", ""),
+ "atomicDouble", new AtomicDoubleMetric("atomicDouble", ""),
+ "longAdder", new LongAdderMetric("longAdder", ""),
+ "doubleAdder", new DoubleAdderMetric("doubleAdder", ""),
+ "distributionMetric", new DistributionMetric("distributionMetric", "", new long[] {0, 1}),
+ "hitRate", new HitRateMetric("hitRate", "", Long.MAX_VALUE)
+ )
+ );
+
+ private MetricManager metricManager;
+
+ private LogPushExporter exporter;
+
+ @BeforeEach
+ void setUp() {
+ metricManager = new MetricManagerImpl();
+ metricManager.configure(metricConfiguration, () -> CLUSTER_ID, "nodeName");
+ metricManager.registerSource(new TestMetricSource(metricSet));
+
+ exporter = new LogPushExporter();
+ }
+
+ @AfterEach
+ void tearDown() {
+ exporter.stop();
+ }
+
+ @Test
+ void testStart() {
+ metricManager.enable(metricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ Awaitility.await()
+ .atMost(Duration.ofMillis(500L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testEnableMetricSet() {
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ IgniteTestUtils.runAsync(() -> {
+ Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500L));
+
+ metricManager.enable(metricSet.name());
+ });
+
+ Awaitility.await()
+ .between(Duration.ofMillis(500L), Duration.ofMillis(1000L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testMetricUpdate() {
+ var intMetric = new AtomicIntMetric(MTRC_NAME, "");
+ var additionalMetricSet = new MetricSet(
+ "additionalSource",
+ Map.of(intMetric.name(), intMetric)
+ );
+
+ metricManager.registerSource(new TestMetricSource(additionalMetricSet));
+
+ metricManager.enable(SRC_NAME);
+ metricManager.enable(additionalMetricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains(MTRC_NAME + ":1"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ IgniteTestUtils.runAsync(() -> {
+ Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500L));
Review Comment:
Done
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1877860501
##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java:
##########
@@ -259,7 +259,7 @@ public CompletableFuture<?> onDelete(ConfigurationNotificationEvent<ExporterView
public CompletableFuture<?> onUpdate(ConfigurationNotificationEvent<ExporterView> ctx) {
MetricExporter exporter = enabledMetricExporters.get(ctx.newValue().exporterName());
- if (exporter != null) {
+ if (exporter != null && ctx.oldValue() != null) {
Review Comment:
Nice catch!
This check is not really necessary as it done before calling `onUpdate`.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva merged PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1877239249
##########
modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/TestPushMetricExporter.java:
##########
@@ -36,23 +33,13 @@ public class TestPushMetricExporter extends PushMetricExporter<TestPushMetricsEx
private static OutputStream outputStream;
- private long period;
-
- @Override
- public void start(MetricProvider metricsProvider, TestPushMetricsExporterView configuration, Supplier<UUID> clusterIdSupplier,
- String nodeName) {
- period = configuration.period();
-
- super.start(metricsProvider, configuration, clusterIdSupplier, nodeName);
- }
-
public static void setOutputStream(OutputStream outputStream) {
TestPushMetricExporter.outputStream = outputStream;
}
@Override
protected long period() {
- return period;
+ return configuration().period();
Review Comment:
Because configuration in ancestor PushMetricExporter has type ExporterView which is common for push and pull exporters and doesn't contain period. At the same time configuration framework doesn't allow to create base class for PushExporterConfiguration as it is a polymorphic configuration.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "nva (via GitHub)" <gi...@apache.org>.
nva commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1877239249
##########
modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/TestPushMetricExporter.java:
##########
@@ -36,23 +33,13 @@ public class TestPushMetricExporter extends PushMetricExporter<TestPushMetricsEx
private static OutputStream outputStream;
- private long period;
-
- @Override
- public void start(MetricProvider metricsProvider, TestPushMetricsExporterView configuration, Supplier<UUID> clusterIdSupplier,
- String nodeName) {
- period = configuration.period();
-
- super.start(metricsProvider, configuration, clusterIdSupplier, nodeName);
- }
-
public static void setOutputStream(OutputStream outputStream) {
TestPushMetricExporter.outputStream = outputStream;
}
@Override
protected long period() {
- return period;
+ return configuration().period();
Review Comment:
Because configuration in ancestor PushMetricExporter has type ExporterView which is common for push and pull exporters and doesn't contain period. At the same time configuration framework doesn't allow to create base class for PushExporterConfiguration as ExporterView is a polymorphic configuration.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23828 Updating the configuration of the metric push exporter does not apply at runtime. [ignite-3]
Posted by "kgusakov (via GitHub)" <gi...@apache.org>.
kgusakov commented on code in PR #4832:
URL: https://github.com/apache/ignite-3/pull/4832#discussion_r1875072767
##########
modules/metrics/src/integrationTest/java/org/apache/ignite/internal/metrics/exporters/TestPushMetricExporter.java:
##########
@@ -36,23 +33,13 @@ public class TestPushMetricExporter extends PushMetricExporter<TestPushMetricsEx
private static OutputStream outputStream;
- private long period;
-
- @Override
- public void start(MetricProvider metricsProvider, TestPushMetricsExporterView configuration, Supplier<UUID> clusterIdSupplier,
- String nodeName) {
- period = configuration.period();
-
- super.start(metricsProvider, configuration, clusterIdSupplier, nodeName);
- }
-
public static void setOutputStream(OutputStream outputStream) {
TestPushMetricExporter.outputStream = outputStream;
}
@Override
protected long period() {
- return period;
+ return configuration().period();
Review Comment:
Why can't we use just the period from the ancestor? As i understand we already has the actual value there.
##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/MetricManagerImpl.java:
##########
@@ -259,7 +259,7 @@ public CompletableFuture<?> onDelete(ConfigurationNotificationEvent<ExporterView
public CompletableFuture<?> onUpdate(ConfigurationNotificationEvent<ExporterView> ctx) {
MetricExporter exporter = enabledMetricExporters.get(ctx.newValue().exporterName());
- if (exporter != null) {
+ if (exporter != null && ctx.oldValue() != null) {
Review Comment:
So, if the old value is null - we already set this value during start, am I right?
##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporterTest.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.log;
+
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.metrics.AbstractMetricSource;
+import org.apache.ignite.internal.metrics.AtomicDoubleMetric;
+import org.apache.ignite.internal.metrics.AtomicIntMetric;
+import org.apache.ignite.internal.metrics.AtomicLongMetric;
+import org.apache.ignite.internal.metrics.DistributionMetric;
+import org.apache.ignite.internal.metrics.DoubleAdderMetric;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.HitRateMetric;
+import org.apache.ignite.internal.metrics.IntGauge;
+import org.apache.ignite.internal.metrics.LongAdderMetric;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.metrics.MetricManagerImpl;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.configuration.MetricChange;
+import org.apache.ignite.internal.metrics.configuration.MetricConfiguration;
+import org.apache.ignite.internal.metrics.exporters.PushMetricExporter;
+import org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterChange;
+import org.apache.ignite.internal.metrics.exporters.jmx.JmxExporter;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.logging.log4j.core.LogEvent;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Tests for {@link JmxExporter}.
+ */
+@ExtendWith({ConfigurationExtension.class})
+public class LogPushExporterTest extends BaseIgniteAbstractTest {
+ @InjectConfiguration("mock.exporters = {log = {exporterName = logPush, period = 300}}")
+ private MetricConfiguration metricConfiguration;
+
+ private static final UUID CLUSTER_ID = UUID.randomUUID();
+
+ private static final String SRC_NAME = "testSource";
+
+ private static final String MTRC_NAME = "testMetric";
+
+ /**
+ * Metric set with all available metric types.
+ */
+ private static final MetricSet metricSet =
+ new MetricSet(
+ SRC_NAME,
+ Map.of(
+ "intGauge", new IntGauge("intGauge", "", () -> 1),
+ "longGauge", new LongGauge("longGauge", "", () -> 1L),
+ "doubleGauge", new DoubleGauge("doubleGauge", "", () -> 1d),
+ "atomicInt", new AtomicIntMetric("atomicInt", ""),
+ "atomicLong", new AtomicLongMetric("atomicLong", ""),
+ "atomicDouble", new AtomicDoubleMetric("atomicDouble", ""),
+ "longAdder", new LongAdderMetric("longAdder", ""),
+ "doubleAdder", new DoubleAdderMetric("doubleAdder", ""),
+ "distributionMetric", new DistributionMetric("distributionMetric", "", new long[] {0, 1}),
+ "hitRate", new HitRateMetric("hitRate", "", Long.MAX_VALUE)
+ )
+ );
+
+ private MetricManager metricManager;
+
+ private LogPushExporter exporter;
+
+ @BeforeEach
+ void setUp() {
+ metricManager = new MetricManagerImpl();
+ metricManager.configure(metricConfiguration, () -> CLUSTER_ID, "nodeName");
+ metricManager.registerSource(new TestMetricSource(metricSet));
+
+ exporter = new LogPushExporter();
+ }
+
+ @AfterEach
+ void tearDown() {
+ exporter.stop();
+ }
+
+ @Test
+ void testStart() {
+ metricManager.enable(metricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ Awaitility.await()
+ .atMost(Duration.ofMillis(500L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testEnableMetricSet() {
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ IgniteTestUtils.runAsync(() -> {
+ Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500L));
+
+ metricManager.enable(metricSet.name());
+ });
+
+ Awaitility.await()
+ .between(Duration.ofMillis(500L), Duration.ofMillis(1000L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testMetricUpdate() {
+ var intMetric = new AtomicIntMetric(MTRC_NAME, "");
+ var additionalMetricSet = new MetricSet(
+ "additionalSource",
+ Map.of(intMetric.name(), intMetric)
+ );
+
+ metricManager.registerSource(new TestMetricSource(additionalMetricSet));
+
+ metricManager.enable(SRC_NAME);
+ metricManager.enable(additionalMetricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains(MTRC_NAME + ":1"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ IgniteTestUtils.runAsync(() -> {
+ Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500L));
Review Comment:
Can we just remove this sleeps and replace the between await below by usual atMost?
##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/exporters/log/LogPushExporterTest.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.log;
+
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.metrics.AbstractMetricSource;
+import org.apache.ignite.internal.metrics.AtomicDoubleMetric;
+import org.apache.ignite.internal.metrics.AtomicIntMetric;
+import org.apache.ignite.internal.metrics.AtomicLongMetric;
+import org.apache.ignite.internal.metrics.DistributionMetric;
+import org.apache.ignite.internal.metrics.DoubleAdderMetric;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.HitRateMetric;
+import org.apache.ignite.internal.metrics.IntGauge;
+import org.apache.ignite.internal.metrics.LongAdderMetric;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.MetricManager;
+import org.apache.ignite.internal.metrics.MetricManagerImpl;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.configuration.MetricChange;
+import org.apache.ignite.internal.metrics.configuration.MetricConfiguration;
+import org.apache.ignite.internal.metrics.exporters.PushMetricExporter;
+import org.apache.ignite.internal.metrics.exporters.configuration.LogPushExporterChange;
+import org.apache.ignite.internal.metrics.exporters.jmx.JmxExporter;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.logging.log4j.core.LogEvent;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Tests for {@link JmxExporter}.
+ */
+@ExtendWith({ConfigurationExtension.class})
+public class LogPushExporterTest extends BaseIgniteAbstractTest {
+ @InjectConfiguration("mock.exporters = {log = {exporterName = logPush, period = 300}}")
+ private MetricConfiguration metricConfiguration;
+
+ private static final UUID CLUSTER_ID = UUID.randomUUID();
+
+ private static final String SRC_NAME = "testSource";
+
+ private static final String MTRC_NAME = "testMetric";
+
+ /**
+ * Metric set with all available metric types.
+ */
+ private static final MetricSet metricSet =
+ new MetricSet(
+ SRC_NAME,
+ Map.of(
+ "intGauge", new IntGauge("intGauge", "", () -> 1),
+ "longGauge", new LongGauge("longGauge", "", () -> 1L),
+ "doubleGauge", new DoubleGauge("doubleGauge", "", () -> 1d),
+ "atomicInt", new AtomicIntMetric("atomicInt", ""),
+ "atomicLong", new AtomicLongMetric("atomicLong", ""),
+ "atomicDouble", new AtomicDoubleMetric("atomicDouble", ""),
+ "longAdder", new LongAdderMetric("longAdder", ""),
+ "doubleAdder", new DoubleAdderMetric("doubleAdder", ""),
+ "distributionMetric", new DistributionMetric("distributionMetric", "", new long[] {0, 1}),
+ "hitRate", new HitRateMetric("hitRate", "", Long.MAX_VALUE)
+ )
+ );
+
+ private MetricManager metricManager;
+
+ private LogPushExporter exporter;
+
+ @BeforeEach
+ void setUp() {
+ metricManager = new MetricManagerImpl();
+ metricManager.configure(metricConfiguration, () -> CLUSTER_ID, "nodeName");
+ metricManager.registerSource(new TestMetricSource(metricSet));
+
+ exporter = new LogPushExporter();
+ }
+
+ @AfterEach
+ void tearDown() {
+ exporter.stop();
+ }
+
+ @Test
+ void testStart() {
+ metricManager.enable(metricSet.name());
+
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
+ logInspector -> {
+ metricManager.start(Map.of("logPush", exporter));
+
+ Awaitility.await()
+ .atMost(Duration.ofMillis(500L))
+ .until(logInspector::isMatched);
+ }
+ );
+ }
+
+ @Test
+ void testEnableMetricSet() {
+ withLogInspector(
+ evt -> evt.getMessage().getFormattedMessage().contains("Metric report"),
Review Comment:
Looks like this test is testing the same behaviour as the testStart, but in the window with sleeps.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org