This is an automated email from the ASF dual-hosted git repository. ppkarwasz pushed a commit to branch move-monitor-modules in repository https://gitbox.apache.org/repos/asf/logging-flume.git
commit 2bd009c60366e34f6cc26e8c2839268279d185dd Author: Piotr P. Karwasz <[email protected]> AuthorDate: Wed Jun 10 15:13:00 2026 +0200 Move monitoring services to flume-ng-instrumentation modules Split the Ganglia, HTTP and Prometheus MonitorService implementations out of flume-ng-core into three modules under a new flume-ng-instrumentation parent, each in its own package so there are no split packages. Replace the hardcoded MonitoringType enum with ServiceLoader discovery: MonitorService gains a getType() default method, each provider declares itself via META-INF/services, and the node selects one by matching flume.monitoring.type against getType() (FQCN fallback preserved). The modules are wired through the BOM and bundled by flume-ng-dist only. Core keeps the MonitorService interface and JMXPollUtil, and drops the now unused gson and prometheus dependencies. Assisted-By: Claude Opus 4.8 (1M context) <[email protected]> --- flume-bom/pom.xml | 15 ++++ flume-ng-core/pom.xml | 15 ---- .../flume/instrumentation/MonitorService.java | 16 ++++- flume-ng-dist/pom.xml | 12 ++++ .../flume-ganglia-monitor/pom.xml | 56 +++++++++++++++ .../instrumentation/ganglia}/GangliaServer.java | 8 ++- ...org.apache.flume.instrumentation.MonitorService | 1 + .../flume-http-monitor/pom.xml | 71 +++++++++++++++++++ .../instrumentation/http/HTTPMetricsServer.java | 5 ++ ...org.apache.flume.instrumentation.MonitorService | 1 + .../instrumentation/http/BaseHTTPMetricsTest.java | 0 .../http/TestHTTPMetricsServer.java | 0 .../flume/instrumentation/util/JMXTestUtils.java | 29 ++++---- .../flume-prometheus-monitor/pom.xml | 82 ++++++++++++++++++++++ .../prometheus}/PrometheusHTTPMetricsServer.java | 11 ++- ...org.apache.flume.instrumentation.MonitorService | 1 + .../prometheus}/BaseHTTPMetricsTest.java | 2 +- .../prometheus}/TestPrometheusMetricsServer.java | 2 +- flume-ng-instrumentation/pom.xml | 40 +++++++++++ .../java/org/apache/flume/node/Application.java | 31 ++++---- pom.xml | 1 + 21 files changed, 349 insertions(+), 50 deletions(-) diff --git a/flume-bom/pom.xml b/flume-bom/pom.xml index 5e1dec6f3..aaa0efeee 100644 --- a/flume-bom/pom.xml +++ b/flume-bom/pom.xml @@ -187,6 +187,21 @@ <artifactId>flume-scribe-source</artifactId> <version>${flume-scribe.version}</version> </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-ganglia-monitor</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-http-monitor</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-prometheus-monitor</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.flume.flume-ng-sources</groupId> <artifactId>flume-http-source</artifactId> diff --git a/flume-ng-core/pom.xml b/flume-ng-core/pom.xml index 2c1ee40fa..624b1188c 100644 --- a/flume-ng-core/pom.xml +++ b/flume-ng-core/pom.xml @@ -151,11 +151,6 @@ <artifactId>jetty-jmx</artifactId> </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - </dependency> - <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> @@ -179,16 +174,6 @@ <artifactId>mina-core</artifactId> </dependency> - <dependency> - <groupId>io.prometheus</groupId> - <artifactId>simpleclient</artifactId> - </dependency> - - <dependency> - <groupId>io.prometheus</groupId> - <artifactId>simpleclient_servlet</artifactId> - </dependency> - </dependencies> <build> <plugins> diff --git a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitorService.java b/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitorService.java index d15ff613e..bb1b7d2fe 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitorService.java +++ b/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitorService.java @@ -26,7 +26,19 @@ import org.apache.flume.conf.Configurable; */ public interface MonitorService extends Configurable { - public void start(); + void start(); - public void stop(); + void stop(); + + /** + * The configuration type name used to select this monitoring service. + * + * <p>>(Implementations discovered through the {@link java.util.ServiceLoader} are matched against the + * {@code flume.monitoring.type} value using this method.</p> + * + * @return the type name, or {@code null} if this service is not selectable by type. + */ + default String getType() { + return null; + } } diff --git a/flume-ng-dist/pom.xml b/flume-ng-dist/pom.xml index 92273e741..9a3fcbf25 100644 --- a/flume-ng-dist/pom.xml +++ b/flume-ng-dist/pom.xml @@ -126,6 +126,18 @@ <groupId>org.apache.flume</groupId> <artifactId>flume-legacy-thrift-source</artifactId> </dependency>--> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-ganglia-monitor</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-http-monitor</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-prometheus-monitor</artifactId> + </dependency> <dependency> <groupId>org.apache.flume.flume-ng-sources</groupId> <artifactId>flume-http-source</artifactId> diff --git a/flume-ng-instrumentation/flume-ganglia-monitor/pom.xml b/flume-ng-instrumentation/flume-ganglia-monitor/pom.xml new file mode 100644 index 000000000..3262d4272 --- /dev/null +++ b/flume-ng-instrumentation/flume-ganglia-monitor/pom.xml @@ -0,0 +1,56 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-instrumentation</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-ganglia-monitor</artifactId> + <name>Flume Ganglia Monitor</name> + + <properties> + <!-- TODO fix spotbugs violations --> + <spotbugs.maxAllowedViolations>13</spotbugs.maxAllowedViolations> + <module.name>org.apache.flume.instrumentation.ganglia</module.name> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-sdk</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-core</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/GangliaServer.java b/flume-ng-instrumentation/flume-ganglia-monitor/src/main/java/org/apache/flume/instrumentation/ganglia/GangliaServer.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/instrumentation/GangliaServer.java rename to flume-ng-instrumentation/flume-ganglia-monitor/src/main/java/org/apache/flume/instrumentation/ganglia/GangliaServer.java index cf9535930..367557eff 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/GangliaServer.java +++ b/flume-ng-instrumentation/flume-ganglia-monitor/src/main/java/org/apache/flume/instrumentation/ganglia/GangliaServer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.instrumentation; +package org.apache.flume.instrumentation.ganglia; import java.net.DatagramPacket; import java.net.DatagramSocket; @@ -32,6 +32,7 @@ import org.apache.flume.Context; import org.apache.flume.FlumeException; import org.apache.flume.api.HostInfo; import org.apache.flume.conf.ConfigurationException; +import org.apache.flume.instrumentation.MonitorService; import org.apache.flume.instrumentation.util.JMXPollUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,6 +135,11 @@ public class GangliaServer implements MonitorService { offset = 0; } + @Override + public String getType() { + return "ganglia"; + } + /** * Start this server, causing it to poll JMX at the configured frequency. */ diff --git a/flume-ng-instrumentation/flume-ganglia-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService b/flume-ng-instrumentation/flume-ganglia-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService new file mode 100644 index 000000000..bacdb80df --- /dev/null +++ b/flume-ng-instrumentation/flume-ganglia-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService @@ -0,0 +1 @@ +org.apache.flume.instrumentation.ganglia.GangliaServer diff --git a/flume-ng-instrumentation/flume-http-monitor/pom.xml b/flume-ng-instrumentation/flume-http-monitor/pom.xml new file mode 100644 index 000000000..da9c183c0 --- /dev/null +++ b/flume-ng-instrumentation/flume-http-monitor/pom.xml @@ -0,0 +1,71 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-instrumentation</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-http-monitor</artifactId> + <name>Flume HTTP Monitor</name> + + <properties> + <!-- TODO fix spotbugs violations --> + <spotbugs.maxAllowedViolations>3</spotbugs.maxAllowedViolations> + <module.name>org.apache.flume.instrumentation.http</module.name> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-sdk</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-core</artifactId> + </dependency> + + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-util</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java b/flume-ng-instrumentation/flume-http-monitor/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java rename to flume-ng-instrumentation/flume-http-monitor/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java index 1fefc5ec7..b28a94a86 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java +++ b/flume-ng-instrumentation/flume-http-monitor/src/main/java/org/apache/flume/instrumentation/http/HTTPMetricsServer.java @@ -54,6 +54,11 @@ public class HTTPMetricsServer implements MonitorService { private static int DEFAULT_PORT = 41414; public static String CONFIG_PORT = "port"; + @Override + public String getType() { + return "http"; + } + @Override public void start() { jettyServer = new Server(); diff --git a/flume-ng-instrumentation/flume-http-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService b/flume-ng-instrumentation/flume-http-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService new file mode 100644 index 000000000..94fc8860a --- /dev/null +++ b/flume-ng-instrumentation/flume-http-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService @@ -0,0 +1 @@ +org.apache.flume.instrumentation.http.HTTPMetricsServer diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java b/flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java similarity index 100% copy from flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java copy to flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java b/flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java similarity index 100% rename from flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java rename to flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java diff --git a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitoringType.java b/flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/util/JMXTestUtils.java similarity index 53% rename from flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitoringType.java rename to flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/util/JMXTestUtils.java index c0a5dad68..454473431 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/MonitoringType.java +++ b/flume-ng-instrumentation/flume-http-monitor/src/test/java/org/apache/flume/instrumentation/util/JMXTestUtils.java @@ -14,24 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.instrumentation; +package org.apache.flume.instrumentation.util; + +import java.util.Map; +import org.junit.Assert; /** - * Enum for Monitoring types. + * */ -public enum MonitoringType { - OTHER(null), - GANGLIA(org.apache.flume.instrumentation.GangliaServer.class), - HTTP(org.apache.flume.instrumentation.http.HTTPMetricsServer.class), - PROMETHEUS(org.apache.flume.instrumentation.http.PrometheusHTTPMetricsServer.class); - - private Class<? extends MonitorService> monitoringClass; - - private MonitoringType(Class<? extends MonitorService> klass) { - this.monitoringClass = klass; - } +public class JMXTestUtils { - public Class<? extends MonitorService> getMonitorClass() { - return this.monitoringClass; + public static void checkChannelCounterParams(Map<String, String> attrs) { + Assert.assertNotNull(attrs.get("StartTime")); + Assert.assertNotNull(attrs.get("StopTime")); + Assert.assertTrue(Long.parseLong(attrs.get("ChannelSize")) != 0); + Assert.assertTrue(Long.parseLong(attrs.get("EventPutAttemptCount")) == 2); + Assert.assertTrue(Long.parseLong(attrs.get("EventTakeAttemptCount")) == 1); + Assert.assertTrue(Long.parseLong(attrs.get("EventPutSuccessCount")) == 2); + Assert.assertTrue(Long.parseLong(attrs.get("EventTakeSuccessCount")) == 1); } } diff --git a/flume-ng-instrumentation/flume-prometheus-monitor/pom.xml b/flume-ng-instrumentation/flume-prometheus-monitor/pom.xml new file mode 100644 index 000000000..2b5613e33 --- /dev/null +++ b/flume-ng-instrumentation/flume-prometheus-monitor/pom.xml @@ -0,0 +1,82 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-instrumentation</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-prometheus-monitor</artifactId> + <name>Flume Prometheus Monitor</name> + + <properties> + <!-- TODO fix spotbugs/pmd violations --> + <spotbugs.maxAllowedViolations>6</spotbugs.maxAllowedViolations> + <pmd.maxAllowedViolations>1</pmd.maxAllowedViolations> + <module.name>org.apache.flume.instrumentation.prometheus</module.name> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-sdk</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.flume.flume-ng-instrumentation</groupId> + <artifactId>flume-http-monitor</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>io.prometheus</groupId> + <artifactId>simpleclient</artifactId> + </dependency> + + <dependency> + <groupId>io.prometheus</groupId> + <artifactId>simpleclient_servlet</artifactId> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/PrometheusHTTPMetricsServer.java b/flume-ng-instrumentation/flume-prometheus-monitor/src/main/java/org/apache/flume/instrumentation/prometheus/PrometheusHTTPMetricsServer.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/PrometheusHTTPMetricsServer.java rename to flume-ng-instrumentation/flume-prometheus-monitor/src/main/java/org/apache/flume/instrumentation/prometheus/PrometheusHTTPMetricsServer.java index 3512050eb..5628db0a4 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/instrumentation/http/PrometheusHTTPMetricsServer.java +++ b/flume-ng-instrumentation/flume-prometheus-monitor/src/main/java/org/apache/flume/instrumentation/prometheus/PrometheusHTTPMetricsServer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.instrumentation.http; +package org.apache.flume.instrumentation.prometheus; import com.google.common.base.Throwables; import io.prometheus.client.Collector; @@ -39,7 +39,7 @@ import javax.management.MBeanServer; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.ReflectionException; -import org.apache.flume.instrumentation.MonitorService; +import org.apache.flume.instrumentation.http.HTTPMetricsServer; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; @@ -59,7 +59,7 @@ import org.slf4j.LoggerFactory; * <p> "componentName1":{"metric3" : "metricValue3","metric4":"metricValue4"} * <p> } */ -public class PrometheusHTTPMetricsServer extends HTTPMetricsServer implements MonitorService { +public class PrometheusHTTPMetricsServer extends HTTPMetricsServer { private static final String PROM_DEFAULT_PREFIX = "Flume_"; private Server jettyServer; @@ -68,6 +68,11 @@ public class PrometheusHTTPMetricsServer extends HTTPMetricsServer implements Mo private FlumePrometheusCollector requests; + @Override + public String getType() { + return "prometheus"; + } + @Override public void start() { diff --git a/flume-ng-instrumentation/flume-prometheus-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService b/flume-ng-instrumentation/flume-prometheus-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService new file mode 100644 index 000000000..042e10826 --- /dev/null +++ b/flume-ng-instrumentation/flume-prometheus-monitor/src/main/resources/META-INF/services/org.apache.flume.instrumentation.MonitorService @@ -0,0 +1 @@ +org.apache.flume.instrumentation.prometheus.PrometheusHTTPMetricsServer diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java b/flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/BaseHTTPMetricsTest.java similarity index 98% rename from flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java rename to flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/BaseHTTPMetricsTest.java index 7ae7f36ac..1ac5812f6 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/BaseHTTPMetricsTest.java +++ b/flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/BaseHTTPMetricsTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.instrumentation.http; +package org.apache.flume.instrumentation.prometheus; import java.net.ServerSocket; import org.apache.flume.Channel; diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestPrometheusMetricsServer.java b/flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/TestPrometheusMetricsServer.java similarity index 98% rename from flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestPrometheusMetricsServer.java rename to flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/TestPrometheusMetricsServer.java index f6b78b9eb..135ac830e 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestPrometheusMetricsServer.java +++ b/flume-ng-instrumentation/flume-prometheus-monitor/src/test/java/org/apache/flume/instrumentation/prometheus/TestPrometheusMetricsServer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.instrumentation.http; +package org.apache.flume.instrumentation.prometheus; import java.io.BufferedReader; import java.io.InputStreamReader; diff --git a/flume-ng-instrumentation/pom.xml b/flume-ng-instrumentation/pom.xml new file mode 100644 index 000000000..e664afbbb --- /dev/null +++ b/flume-ng-instrumentation/pom.xml @@ -0,0 +1,40 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flume</groupId> + <artifactId>flume-parent</artifactId> + <version>2.0.0-SNAPSHOT</version> + <relativePath>../flume-parent/pom.xml</relativePath> + </parent> + + <groupId>org.apache.flume</groupId> + <artifactId>flume-ng-instrumentation</artifactId> + <packaging>pom</packaging> + <name>Flume Instrumentation</name> + + <modules> + <module>flume-ganglia-monitor</module> + <module>flume-http-monitor</module> + <module>flume-prometheus-monitor</module> + </modules> + +</project> diff --git a/flume-ng-node/src/main/java/org/apache/flume/node/Application.java b/flume-ng-node/src/main/java/org/apache/flume/node/Application.java index 158297b4a..eeb5c2f01 100644 --- a/flume-ng-node/src/main/java/org/apache/flume/node/Application.java +++ b/flume-ng-node/src/main/java/org/apache/flume/node/Application.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Locale; import java.util.Map.Entry; import java.util.Properties; +import java.util.ServiceLoader; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; import org.apache.commons.cli.CommandLine; @@ -49,7 +50,6 @@ import org.apache.flume.SinkRunner; import org.apache.flume.Source; import org.apache.flume.SourceRunner; import org.apache.flume.instrumentation.MonitorService; -import org.apache.flume.instrumentation.MonitoringType; import org.apache.flume.lifecycle.LifecycleAware; import org.apache.flume.lifecycle.LifecycleState; import org.apache.flume.lifecycle.LifecycleSupervisor; @@ -253,23 +253,13 @@ public class Application { this.loadMonitoring(); } - @SuppressWarnings("unchecked") private void loadMonitoring() { Properties systemProps = System.getProperties(); Set<String> keys = systemProps.stringPropertyNames(); try { if (keys.contains(CONF_MONITOR_CLASS)) { String monitorType = systemProps.getProperty(CONF_MONITOR_CLASS); - Class<? extends MonitorService> klass; - try { - // Is it a known type? - klass = MonitoringType.valueOf(monitorType.toUpperCase(Locale.ENGLISH)) - .getMonitorClass(); - } catch (Exception e) { - // Not a known type, use FQCN - klass = (Class<? extends MonitorService>) Class.forName(monitorType); - } - this.monitorServer = klass.getConstructor().newInstance(); + this.monitorServer = createMonitorService(monitorType); Context context = new Context(); for (String key : keys) { if (key.startsWith(CONF_MONITOR_PREFIX)) { @@ -284,6 +274,23 @@ public class Application { } } + /** + * Resolves the configured monitoring type to a {@link MonitorService}. + * + * <p>The type is first matched (case-insensitively) against the {@link MonitorService#getType()} of the providers + * registered through the {@link ServiceLoader}; if none matches, it is treated as a fully qualified class name.</p> + */ + private MonitorService createMonitorService(String monitorType) throws ReflectiveOperationException { + for (MonitorService service : ServiceLoader.load(MonitorService.class, Application.class.getClassLoader())) { + if (monitorType.equalsIgnoreCase(service.getType())) { + return service; + } + } + // Not a known type, use the fully qualified class name. + Class<? extends MonitorService> klass = Class.forName(monitorType).asSubclass(MonitorService.class); + return klass.getConstructor().newInstance(); + } + public static void main(String[] args) { Properties initProps = loadConfigOpts(); diff --git a/pom.xml b/pom.xml index 7e360462d..c13d27277 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ <module>flume-ng-core</module> <module>flume-ng-configuration</module> <module>flume-ng-sources</module> + <module>flume-ng-instrumentation</module> <module>flume-ng-node</module> <!-- Disable until all snapshots are published <module>flume-ng-dist</module>
