This is an automated email from the ASF dual-hosted git repository.
namelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 8950aefc115 IGNITE-19620 Provided ability to configure metric exporter
filter from Spring XML (#10757)
8950aefc115 is described below
commit 8950aefc115075158ccd6ab27c83a567a5095805
Author: Nikita Amelchev <[email protected]>
AuthorDate: Fri Jun 2 22:38:12 2023 +0300
IGNITE-19620 Provided ability to configure metric exporter filter from
Spring XML (#10757)
---
.../ignite/spi/metric/MetricExporterSpi.java | 1 +
.../ignite/spi/metric/RegexpMetricFilter.java | 49 +++++++++++++++++
.../test/config/metric/regexp-filter-config.xml | 64 ++++++++++++++++++++++
.../internal/metric/RegexpMetricFilterTest.java | 63 +++++++++++++++++++++
.../ignite/testsuites/IgniteSpringTestSuite.java | 3 +
5 files changed, 180 insertions(+)
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/metric/MetricExporterSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/metric/MetricExporterSpi.java
index 21be6c5f2b9..f8e5db51ed4 100644
---
a/modules/core/src/main/java/org/apache/ignite/spi/metric/MetricExporterSpi.java
+++
b/modules/core/src/main/java/org/apache/ignite/spi/metric/MetricExporterSpi.java
@@ -60,6 +60,7 @@ public interface MetricExporterSpi extends IgniteSpi {
* Metric registry that not satisfy {@code filter} shouldn't be exported.
*
* @param filter Filter.
+ * @see RegexpMetricFilter
*/
public void setExportFilter(Predicate<ReadOnlyMetricRegistry> filter);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/metric/RegexpMetricFilter.java
b/modules/core/src/main/java/org/apache/ignite/spi/metric/RegexpMetricFilter.java
new file mode 100644
index 00000000000..e4340f74c86
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/spi/metric/RegexpMetricFilter.java
@@ -0,0 +1,49 @@
+/*
+ * 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.spi.metric;
+
+import java.util.function.Predicate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.lang.IgniteExperimental;
+
+/**
+ * Metric registry filter based on regular expression.
+ */
+@IgniteExperimental
+public class RegexpMetricFilter implements Predicate<ReadOnlyMetricRegistry> {
+ /** Metric registries pattern. */
+ private final Pattern regPtrn;
+
+ /**
+ * @param regNameRegex Regular expression to filter metric registries.
+ */
+ public RegexpMetricFilter(String regNameRegex) {
+ A.notNull(regNameRegex, "regex");
+
+ regPtrn = Pattern.compile(regNameRegex);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean test(ReadOnlyMetricRegistry mreg) {
+ Matcher m = regPtrn.matcher(mreg.name());
+
+ return m.matches();
+ }
+}
diff --git a/modules/spring/src/test/config/metric/regexp-filter-config.xml
b/modules/spring/src/test/config/metric/regexp-filter-config.xml
new file mode 100644
index 00000000000..0e3ccb3fd4f
--- /dev/null
+++ b/modules/spring/src/test/config/metric/regexp-filter-config.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite Spring configuration file.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
https://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="metricExporterSpi">
+ <bean class="org.apache.ignite.spi.metric.log.LogExporterSpi">
+ <property name="exportFilter">
+ <bean
class="org.apache.ignite.spi.metric.RegexpMetricFilter">
+ <constructor-arg name="regNameRegex" value="other.*"/>
+ </bean>
+ </property>
+ <property name="period">
+ <util:constant
static-field="org.apache.ignite.internal.metric.AbstractExporterSpiTest.EXPORT_TIMEOUT"/>
+ </property>
+ </bean>
+ </property>
+
+ <property name="gridLogger">
+ <bean class="org.apache.ignite.testframework.ListeningTestLogger">
+ <constructor-arg>
+ <bean class="org.apache.ignite.logger.java.JavaLogger"/>
+ </constructor-arg>
+ </bean>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <value>127.0.0.1:47500</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+</beans>
diff --git
a/modules/spring/src/test/java/org/apache/ignite/internal/metric/RegexpMetricFilterTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/metric/RegexpMetricFilterTest.java
new file mode 100644
index 00000000000..913faf373ef
--- /dev/null
+++
b/modules/spring/src/test/java/org/apache/ignite/internal/metric/RegexpMetricFilterTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.metric;
+
+import java.util.Set;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.GridConcurrentHashSet;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/** */
+public class RegexpMetricFilterTest extends AbstractExporterSpiTest {
+ /** */
+ public static final String CONFIG =
"modules/spring/src/test/config/metric/regexp-filter-config.xml";
+
+ /** */
+ @Test
+ public void testFilter() throws Exception {
+ try (Ignite ignite = Ignition.start(CONFIG)) {
+ ListeningTestLogger log =
U.field(ignite.configuration().getGridLogger(), "impl");
+
+ LogListener filtered = LogListener.matches(s ->
s.contains(FILTERED_PREFIX)).build();
+
+ log.registerListener(filtered);
+
+ Set<String> expectedMetrics = new GridConcurrentHashSet<>(asList(
+ "other.prefix.test = 42",
+ "other.prefix.test2 = 43",
+ "other.prefix2.test3 = 44"
+ ));
+
+ log.registerListener(s -> expectedMetrics.removeIf(s::contains));
+
+ createAdditionalMetrics((IgniteEx)ignite);
+
+ assertTrue(waitForCondition(expectedMetrics::isEmpty,
EXPORT_TIMEOUT * 10));
+
+ assertFalse(filtered.check());
+ }
+ }
+}
diff --git
a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
index 4389a5b2fbf..bc05aa6ca87 100644
---
a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
+++
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
@@ -30,6 +30,7 @@ import
org.apache.ignite.internal.GridSpringBeanSerializationSelfTest;
import org.apache.ignite.internal.IgniteClientSpringBeanTest;
import org.apache.ignite.internal.IgniteDynamicCacheConfigTest;
import org.apache.ignite.internal.IgniteSpringBeanTest;
+import org.apache.ignite.internal.metric.RegexpMetricFilterTest;
import
org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheDhtMultiBackupTest;
import
org.apache.ignite.internal.processors.resource.GridTransformSpringInjectionSelfTest;
import org.apache.ignite.p2p.GridP2PUserVersionChangeSelfTest;
@@ -81,6 +82,8 @@ import org.junit.runners.Suite;
ClusterStateXmlPropertiesTest.class,
+ RegexpMetricFilterTest.class,
+
// CDC tests.
CdcConfigurationTest.class
})