Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
64 changes: 64 additions & 0 deletions modules/spring/src/test/config/metric/regexp-filter-config.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -81,6 +82,8 @@

ClusterStateXmlPropertiesTest.class,

RegexpMetricFilterTest.class,

// CDC tests.
CdcConfigurationTest.class
})
Expand Down