From 5c1d8fb4b5bb89ad8d2b30398b84d72c02635784 Mon Sep 17 00:00:00 2001 From: Andrea Selva Date: Wed, 18 Dec 2024 18:15:20 +0100 Subject: [PATCH] Remove unused monitoring frameworks (#884) * Removed BugSnag * Removed Librato and Dropwizard dependencies --- broker/pom.xml | 31 ------ .../java/io/moquette/BrokerConstants.java | 8 -- .../moquette/broker/BugSnagErrorsHandler.java | 41 -------- .../io/moquette/broker/NewNettyAcceptor.java | 25 ----- .../metrics/DropWizardMetricsHandler.java | 95 ------------------- distribution/src/main/resources/moquette.conf | 24 ----- 6 files changed, 224 deletions(-) delete mode 100644 broker/src/main/java/io/moquette/broker/BugSnagErrorsHandler.java delete mode 100644 broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java diff --git a/broker/pom.xml b/broker/pom.xml index 05e14b9b1..cb21135e4 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -81,7 +81,6 @@ ${netty.version} - io.netty netty-transport-native-epoll @@ -107,7 +106,6 @@ osx-x86_64 - io.netty netty-tcnative-boringssl-static @@ -140,7 +138,6 @@ runtime - com.h2database h2-mvstore @@ -153,34 +150,6 @@ 2.4.7 - - io.dropwizard.metrics - metrics-core - 3.2.2 - - - io.dropwizard.metrics - metrics-jvm - 3.2.2 - - - - com.librato.metrics - metrics-librato - 5.1.0 - - - com.librato.metrics - librato-java - 2.1.0 - - - - com.bugsnag - bugsnag - [3.0,4.0) - - commons-codec commons-codec diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 210ba09e6..6e905c391 100644 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -113,17 +113,9 @@ public final class BrokerConstants { public static final int NO_BUFFER_FLUSH = -1; public static final int IMMEDIATE_BUFFER_FLUSH = 0; - public static final String METRICS_ENABLE_PROPERTY_NAME = "use_metrics"; - public static final String METRICS_LIBRATO_EMAIL_PROPERTY_NAME = "metrics.librato.email"; - public static final String METRICS_LIBRATO_TOKEN_PROPERTY_NAME = "metrics.librato.token"; - public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source"; - @Deprecated public static final String ENABLE_TELEMETRY_NAME = IConfig.ENABLE_TELEMETRY_NAME; - public static final String BUGSNAG_ENABLE_PROPERTY_NAME = "use_bugsnag"; - public static final String BUGSNAG_TOKEN_PROPERTY_NAME = "bugsnag.token"; - @Deprecated public static final String PERSISTENT_CLIENT_EXPIRATION_PROPERTY_NAME = IConfig.PERSISTENT_CLIENT_EXPIRATION_PROPERTY_NAME; diff --git a/broker/src/main/java/io/moquette/broker/BugSnagErrorsHandler.java b/broker/src/main/java/io/moquette/broker/BugSnagErrorsHandler.java deleted file mode 100644 index 8f8ab5081..000000000 --- a/broker/src/main/java/io/moquette/broker/BugSnagErrorsHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012-2018 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.moquette.broker; - -import com.bugsnag.Bugsnag; -import io.moquette.broker.config.IConfig; -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -import static io.moquette.BrokerConstants.BUGSNAG_TOKEN_PROPERTY_NAME; - -@Sharable -public class BugSnagErrorsHandler extends ChannelInboundHandlerAdapter { - - private Bugsnag bugsnag; - - public void init(IConfig props) { - final String token = props.getProperty(BUGSNAG_TOKEN_PROPERTY_NAME); - this.bugsnag = new Bugsnag(token); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - bugsnag.notify(cause); - ctx.fireExceptionCaught(cause); - } -} diff --git a/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java b/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java index dbf6b4226..f80976931 100644 --- a/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java +++ b/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java @@ -132,8 +132,6 @@ public void operationComplete(ChannelFuture future) throws Exception { private final Map ports = new HashMap<>(); private BytesMetricsCollector bytesMetricsCollector = new BytesMetricsCollector(); private MessageMetricsCollector metricsCollector = new MessageMetricsCollector(); - private Optional metrics; - private Optional errorsCather; private int nettySoBacklog; private boolean nettySoReuseaddr; @@ -173,23 +171,6 @@ public void initialize(NewNettyMQTTHandler mqttHandler, IConfig props, ISslConte channelClass = NioServerSocketChannel.class; } - final boolean useFineMetrics = props.boolProp(METRICS_ENABLE_PROPERTY_NAME, false); - if (useFineMetrics) { - DropWizardMetricsHandler metricsHandler = new DropWizardMetricsHandler(); - metricsHandler.init(props); - this.metrics = Optional.of(metricsHandler); - } else { - this.metrics = Optional.empty(); - } - - final boolean useBugSnag = props.boolProp(BUGSNAG_ENABLE_PROPERTY_NAME, false); - if (useBugSnag) { - BugSnagErrorsHandler bugSnagHandler = new BugSnagErrorsHandler(); - bugSnagHandler.init(props); - this.errorsCather = Optional.of(bugSnagHandler); - } else { - this.errorsCather = Optional.empty(); - } initializePlainTCPTransport(mqttHandler, props, brokerConfiguration); initializeWebSocketTransport(mqttHandler, props, brokerConfiguration); if (securityPortsConfigured(props)) { @@ -287,9 +268,6 @@ private void configureMQTTPipeline(ChannelPipeline pipeline, MoquetteIdleTimeout pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0)); pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler); // pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR)); - if (errorsCather.isPresent()) { - pipeline.addLast("bugsnagCatcher", errorsCather.get()); - } pipeline.addFirst("bytemetrics", new BytesMetricsHandler(bytesMetricsCollector)); if (writeFlushMillis > IMMEDIATE_BUFFER_FLUSH) { pipeline.addLast("autoflush", new AutoFlushHandler(writeFlushMillis, TimeUnit.MILLISECONDS)); @@ -298,9 +276,6 @@ private void configureMQTTPipeline(ChannelPipeline pipeline, MoquetteIdleTimeout pipeline.addLast("encoder", MqttEncoder.INSTANCE); pipeline.addLast("metrics", new MessageMetricsHandler(metricsCollector)); pipeline.addLast("messageLogger", new MQTTMessageLogger()); - if (metrics.isPresent()) { - pipeline.addLast("wizardMetrics", metrics.get()); - } pipeline.addLast("handler", handler); } diff --git a/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java b/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java deleted file mode 100644 index 83ae6f8e6..000000000 --- a/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2012-2018 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.moquette.broker.metrics; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricRegistry; -import com.librato.metrics.reporter.Librato; -import io.moquette.broker.config.IConfig; -import io.moquette.broker.NettyUtils; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.codec.mqtt.MqttMessageType; - -import java.util.concurrent.TimeUnit; - -import static io.moquette.BrokerConstants.*; -import static io.netty.channel.ChannelHandler.Sharable; - -/** - * Pipeline handler use to track some MQTT metrics. - */ -@Sharable -public final class DropWizardMetricsHandler extends ChannelInboundHandlerAdapter { - private MetricRegistry metrics; - private Meter publishesMetrics; - private Meter subscribeMetrics; - private Counter connectedClientsMetrics; - - public void init(IConfig props) { - this.metrics = new MetricRegistry(); - this.publishesMetrics = metrics.meter("publish.requests"); - this.subscribeMetrics = metrics.meter("subscribe.requests"); - this.connectedClientsMetrics = metrics.counter("connect.num_clients"); -// ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) -// .convertRatesTo(TimeUnit.SECONDS) -// .convertDurationsTo(TimeUnit.MILLISECONDS) -// .build(); -// reporter.start(1, TimeUnit.MINUTES); - final String email = props.getProperty(METRICS_LIBRATO_EMAIL_PROPERTY_NAME); - final String token = props.getProperty(METRICS_LIBRATO_TOKEN_PROPERTY_NAME); - final String source = props.getProperty(METRICS_LIBRATO_SOURCE_PROPERTY_NAME); - - Librato.reporter(this.metrics, email, token) - .setSource(source) - .start(10, TimeUnit.SECONDS); - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object message) { - MqttMessage msg = (MqttMessage) message; - MqttMessageType messageType = msg.fixedHeader().messageType(); - switch (messageType) { - case PUBLISH: - this.publishesMetrics.mark(); - break; - case SUBSCRIBE: - this.subscribeMetrics.mark(); - break; - case CONNECT: - this.connectedClientsMetrics.inc(); - break; - case DISCONNECT: - this.connectedClientsMetrics.dec(); - break; - default: - break; - } - ctx.fireChannelRead(message); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - String clientID = NettyUtils.clientID(ctx.channel()); - if (clientID != null && !clientID.isEmpty()) { - this.connectedClientsMetrics.dec(); - } - ctx.fireChannelInactive(); - } - -} diff --git a/distribution/src/main/resources/moquette.conf b/distribution/src/main/resources/moquette.conf index b13faad63..63731edad 100644 --- a/distribution/src/main/resources/moquette.conf +++ b/distribution/src/main/resources/moquette.conf @@ -153,30 +153,6 @@ password_file config/password_file.conf #********************************************************************* # session_queue_size 1024 -#********************************************************************* -# Metrics Configuration -# -# use_metrics: used to enable Dropwizard Metrics sampling metrics. -# metrics.librato.email: Librato account's email -# metrics.librato.token: Librato account's security token -# metrics.librato.source: your application as source in Librato -# definitions -#********************************************************************* -# use_metrics true -# metrics.librato.email john@doe.com -# metrics.librato.token sdfergheghliuhyr2283ehd9827398h -# metrics.librato.source My Fantastic Service - -#********************************************************************* -# Error Monitoring -# -# use_bugsnag: used to enable BugSnag error handler catcher. -# bugsnag.token: the token from your's bugsnag account -#********************************************************************* -# use_bugsnag false -# bugsnag.token wleifb8723784dbfeig74 - - #********************************************************************* # Telemetry information sending #