Added BugSnag error tracker

This commit is contained in:
andsel
2017-06-20 22:12:42 +02:00
parent 04a82c4a63
commit ec951738b5
6 changed files with 75 additions and 6 deletions
+11 -5
View File
@@ -100,17 +100,23 @@
<version>5.1.0</version> <version>5.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.bugsnag</groupId>
<artifactId>bugsnag</artifactId>
<version>[3.0,4.0)</version>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<version>1.10</version> <version>1.10</version>
</dependency> </dependency>
<dependency> <!--<dependency>-->
<groupId>org.hdrhistogram</groupId> <!--<groupId>org.hdrhistogram</groupId>-->
<artifactId>HdrHistogram</artifactId> <!--<artifactId>HdrHistogram</artifactId>-->
<version>2.1.4</version> <!--<version>2.1.4</version>-->
</dependency> <!--</dependency>-->
<dependency> <dependency>
<groupId>com.hazelcast</groupId> <groupId>com.hazelcast</groupId>
@@ -61,6 +61,10 @@ public final class BrokerConstants {
public static final String METRICS_LIBRATO_EMAIL_PROPERTY_NAME = "metrics.librato.email"; 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_TOKEN_PROPERTY_NAME = "metrics.librato.token";
public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source"; public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source";
public static final String BUGSNAG_ENABLE_PROPERTY_NAME = "use_bugsnag";
public static final String BUGSNAG_TOKEN_PROPERTY_NAME = "bugsnag.token";
public static final String STORAGE_CLASS_NAME = "storage_class"; public static final String STORAGE_CLASS_NAME = "storage_class";
private BrokerConstants() { private BrokerConstants() {
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2012-2017 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.server.netty;
import com.bugsnag.Bugsnag;
import io.moquette.server.config.IConfig;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import static io.moquette.BrokerConstants.BUGSNAG_TOKEN_PROPERTY_NAME;
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);
}
}
@@ -97,6 +97,7 @@ public class NettyAcceptor implements ServerAcceptor {
BytesMetricsCollector m_bytesMetricsCollector = new BytesMetricsCollector(); BytesMetricsCollector m_bytesMetricsCollector = new BytesMetricsCollector();
MessageMetricsCollector m_metricsCollector = new MessageMetricsCollector(); MessageMetricsCollector m_metricsCollector = new MessageMetricsCollector();
private Optional<? extends ChannelInboundHandler> metrics; private Optional<? extends ChannelInboundHandler> metrics;
private Optional<? extends ChannelInboundHandler> errorsCather;
private int nettySoBacklog; private int nettySoBacklog;
private boolean nettySoReuseaddr; private boolean nettySoReuseaddr;
@@ -145,6 +146,14 @@ public class NettyAcceptor implements ServerAcceptor {
this.metrics = Optional.empty(); this.metrics = Optional.empty();
} }
final boolean useBugSnag = Boolean.parseBoolean(props.getProperty(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); initializePlainTCPTransport(mqttHandler, props);
initializeWebSocketTransport(mqttHandler, props); initializeWebSocketTransport(mqttHandler, props);
String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME); String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
@@ -20,10 +20,13 @@ import io.moquette.persistence.MemoryStorageService;
import io.moquette.spi.impl.subscriptions.Subscription; import io.moquette.spi.impl.subscriptions.Subscription;
import io.moquette.spi.impl.subscriptions.SubscriptionsDirectory; import io.moquette.spi.impl.subscriptions.SubscriptionsDirectory;
import io.moquette.spi.impl.subscriptions.Topic; import io.moquette.spi.impl.subscriptions.Topic;
import static io.netty.handler.codec.mqtt.MqttQoS.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
import static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE;
import static io.netty.handler.codec.mqtt.MqttQoS.EXACTLY_ONCE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class ClientSessionTest { public class ClientSessionTest {
@@ -126,3 +126,11 @@ password_file config/password_file.conf
# metrics.librato.token sdfergheghliuhyr2283ehd9827398h # metrics.librato.token sdfergheghliuhyr2283ehd9827398h
# metrics.librato.source My Fantastic Service # 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