Skip to content

Commit

Permalink
Merge pull request lavalink-devs#97 from napstr/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
freyacodes authored Apr 30, 2018
2 parents bb11cba + d30035f commit 215fc16
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 143 deletions.
10 changes: 10 additions & 0 deletions LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ lavalink:
sentryDsn: ""
bufferDurationMs: 400
youtubePlaylistLoadLimit: 600

logging:
file:
max-history: 30
max-size: 1GB
path: ./logs/

level:
root: INFO
lavalink: INFO
4 changes: 2 additions & 2 deletions LavalinkServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ bootJar {
requiresUnpack '**/jda-nas*.jar' //otherwise we get missing classes exceptions
}

sourceCompatibility = 9
targetCompatibility = 9
sourceCompatibility = 10
targetCompatibility = 10

bootRun {
//compiling tests during bootRun increases the likelyhood of catching broken tests locally instead of on the CI
Expand Down
2 changes: 1 addition & 1 deletion LavalinkServer/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:9-jre-slim
FROM openjdk:10-jre-slim

WORKDIR /opt/Lavalink

Expand Down
45 changes: 1 addition & 44 deletions LavalinkServer/src/main/java/lavalink/server/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

package lavalink.server;

import ch.qos.logback.classic.LoggerContext;
import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.logback.SentryAppender;
import lavalink.server.config.ServerConfig;
import lavalink.server.io.SocketServer;
import lavalink.server.util.SimpleLogToSLF4JAdapter;
import net.dv8tion.jda.utils.SimpleLog;
Expand All @@ -37,9 +32,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import java.io.IOException;
import java.util.Properties;

@SpringBootApplication
@ComponentScan
public class Launcher {
Expand All @@ -54,7 +46,7 @@ public static void main(String[] args) {
sa.run(args);
}

public Launcher(ServerConfig serverConfig, SocketServer socketServer) {
public Launcher(SocketServer socketServer) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("Shutdown hook triggered");
try {
Expand All @@ -66,40 +58,5 @@ public Launcher(ServerConfig serverConfig, SocketServer socketServer) {

SimpleLog.LEVEL = SimpleLog.Level.OFF;
SimpleLog.addListener(new SimpleLogToSLF4JAdapter());
initSentry(serverConfig);
}

private void initSentry(ServerConfig serverConfig) {
String sentryDsn = serverConfig.getSentryDsn();
if (sentryDsn == null || sentryDsn.isEmpty()) {
log.info("No sentry dsn found, turning off sentry.");
turnOffSentry();
return;
}
SentryClient sentryClient = Sentry.init(sentryDsn);
log.info("Set up sentry.");

// set the git commit hash this was build on as the release
Properties gitProps = new Properties();
try {
gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties"));
} catch (NullPointerException | IOException e) {
log.error("Failed to load git repo information", e);
}

String commitHash = gitProps.getProperty("git.commit.id");
if (commitHash != null && !commitHash.isEmpty()) {
log.info("Setting sentry release to commit hash {}", commitHash);
sentryClient.setRelease(commitHash);
} else {
log.warn("No git commit hash found to set up sentry release");
}
}

private void turnOffSentry() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
SentryAppender sentryAppender = (SentryAppender) lc.getLogger(Logger.ROOT_LOGGER_NAME).getAppender("SENTRY");
Sentry.close();
sentryAppender.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package lavalink.server.config;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.filter.ThresholdFilter;
import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.logback.SentryAppender;
import lavalink.server.Launcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.Properties;

/**
* Created by napster on 25.04.18.
*/
@Configuration
public class SentryConfiguration {

private static final Logger log = LoggerFactory.getLogger(SentryConfiguration.class);
private static final String SENTRY_APPENDER_NAME = "SENTRY";

public SentryConfiguration(ServerConfig serverConfig) {
String sentryDsn = serverConfig.getSentryDsn();
if (sentryDsn != null && !sentryDsn.isEmpty()) {
turnOn(sentryDsn);
} else {
turnOff();
}
}


public void turnOn(String dsn) {
log.info("Turning on sentry");
SentryClient sentryClient = Sentry.init(dsn);

// set the git commit hash this was build on as the release
Properties gitProps = new Properties();
try {
gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties"));
} catch (NullPointerException | IOException e) {
log.error("Failed to load git repo information", e);
}

String commitHash = gitProps.getProperty("git.commit.id");
if (commitHash != null && !commitHash.isEmpty()) {
log.info("Setting sentry release to commit hash {}", commitHash);
sentryClient.setRelease(commitHash);
} else {
log.warn("No git commit hash found to set up sentry release");
}

getSentryLogbackAppender().start();
}

public void turnOff() {
log.warn("Turning off sentry");
Sentry.close();
getSentryLogbackAppender().stop();
}

//programmatically creates a sentry appender
private static synchronized SentryAppender getSentryLogbackAppender() {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);

SentryAppender sentryAppender = (SentryAppender) root.getAppender(SENTRY_APPENDER_NAME);
if (sentryAppender == null) {
sentryAppender = new SentryAppender();
sentryAppender.setName(SENTRY_APPENDER_NAME);

ThresholdFilter warningsOrAboveFilter = new ThresholdFilter();
warningsOrAboveFilter.setLevel(Level.WARN.levelStr);
warningsOrAboveFilter.start();
sentryAppender.addFilter(warningsOrAboveFilter);

sentryAppender.setContext(loggerContext);
root.addAppender(sentryAppender);
}
return sentryAppender;
}

}
91 changes: 0 additions & 91 deletions LavalinkServer/src/main/resources/logback.xml

This file was deleted.

7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ ext {
moduleName = 'Lavalink-Parent'
}

import org.gradle.api.tasks.wrapper.Wrapper.DistributionType

task wrapper(type: Wrapper) {
gradleVersion = '4.6'
distributionType = DistributionType.ALL
gradleVersion = '4.7'
//noinspection UnnecessaryQualifiedReference
distributionType = Wrapper.DistributionType.ALL
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 215fc16

Please sign in to comment.