From 1db54d9cb6517a215724d26b68da4a77feaac615 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sat, 23 Feb 2019 18:30:28 -0500 Subject: [PATCH] Add bugsnag --- release_notes.md | 2 ++ test_runner/build.gradle.kts | 2 ++ test_runner/src/main/kotlin/ftl/Main.kt | 12 +++++++----- .../src/main/kotlin/ftl/config/FtlConstants.kt | 14 ++++++++++++++ test_runner/src/main/kotlin/ftl/util/Utils.kt | 10 ++++++++++ test_runner/src/main/resources/revision.txt | 1 + test_runner/src/main/resources/version.txt | 2 +- 7 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 test_runner/src/main/resources/revision.txt diff --git a/release_notes.md b/release_notes.md index 7dd05d20ea..a08609bec2 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,7 @@ ## v? +- Add bugsnag reporting to detect Flank crashes. + ## v4.4.0 - [#505](https://github.com/TestArmada/flank/pull/505) Fix `flank auth login` by using `google-auth-library-java`. ([bootstraponline](https://github.com/bootstraponline)) diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index c94f5991ba..fcc9504e37 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -81,6 +81,8 @@ dependencies { compile(Libs.KOTLIN_STD_LIB) compile(Libs.KOTLIN_COROUTINES_CORE) + compile("com.bugsnag:bugsnag:3.+") + // https://github.com/remkop/picocli/releases compile("info.picocli:picocli:3.9.0") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.6") diff --git a/test_runner/src/main/kotlin/ftl/Main.kt b/test_runner/src/main/kotlin/ftl/Main.kt index cb8d468d6f..733447ad6b 100644 --- a/test_runner/src/main/kotlin/ftl/Main.kt +++ b/test_runner/src/main/kotlin/ftl/Main.kt @@ -1,12 +1,17 @@ package ftl +import com.bugsnag.Bugsnag import ftl.cli.AuthCommand import ftl.cli.FirebaseCommand import ftl.cli.firebase.CancelCommand import ftl.cli.firebase.RefreshCommand import ftl.cli.firebase.test.AndroidCommand import ftl.cli.firebase.test.IosCommand +import ftl.config.FtlConstants +import ftl.config.FtlConstants.bugsnag +import ftl.util.Utils.readRevision import ftl.util.Utils.readTextResource +import ftl.util.Utils.readVersion import picocli.CommandLine @CommandLine.Command( @@ -24,11 +29,8 @@ import picocli.CommandLine class Main : Runnable { override fun run() { if (printVersion) { - // inline functions like .trim aren't counted as code coverage - // https://github.com/jacoco/jacoco/issues/654 - // https://github.com/jacoco/jacoco/issues/754 - val version = readTextResource("version.txt").trim() - println(version) + println(readVersion()) + println(readRevision()) } else { CommandLine.usage(Main::class.java, System.out) } diff --git a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt index af3462a1d2..4ad4ee0f11 100644 --- a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt +++ b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt @@ -1,5 +1,8 @@ package ftl.config +import ch.qos.logback.classic.Level +import ch.qos.logback.classic.Logger +import com.bugsnag.Bugsnag import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport import com.google.api.client.googleapis.util.Utils import com.google.api.client.http.HttpRequestInitializer @@ -13,9 +16,13 @@ import ftl.args.IArgs import ftl.args.IosArgs import ftl.gc.UserAuth import ftl.http.HttpTimeoutIncrease +import ftl.util.Utils.readRevision +import ftl.util.Utils.readVersion import java.nio.file.Path import java.nio.file.Paths import java.util.Date +import org.slf4j.LoggerFactory + object FtlConstants { var useMock = false @@ -36,6 +43,13 @@ object FtlConstants { const val GCS_PREFIX = "gs://" val JSON_FACTORY: JsonFactory by lazy { Utils.getDefaultJsonFactory() } + val bugsnag = Bugsnag(if (useMock) null else "3d5f8ba4ee847d6bb51cb9c347eda74f") + + init { + bugsnag.setAppVersion(readRevision()) + (LoggerFactory.getLogger(Bugsnag::class.java) as Logger).level = Level.OFF + } + val httpTransport: NetHttpTransport by lazy { try { return@lazy GoogleNetHttpTransport.newTrustedTransport() diff --git a/test_runner/src/main/kotlin/ftl/util/Utils.kt b/test_runner/src/main/kotlin/ftl/util/Utils.kt index b167140105..1139280479 100644 --- a/test_runner/src/main/kotlin/ftl/util/Utils.kt +++ b/test_runner/src/main/kotlin/ftl/util/Utils.kt @@ -110,6 +110,16 @@ object Utils { ?: throw RuntimeException("Unable to find resource: $name") } + // app version: flank_snapshot + fun readVersion(): String { + return readTextResource("version.txt").trim() + } + + // git commit name: 5b0d23215e3bd90e5f9c1c57149320634aad8008 + fun readRevision(): String { + return readTextResource("revision.txt").trim() + } + fun readTextResource(name: String): String { return getResource(name).bufferedReader().use { it.readText() } } diff --git a/test_runner/src/main/resources/revision.txt b/test_runner/src/main/resources/revision.txt new file mode 100644 index 0000000000..3546645658 --- /dev/null +++ b/test_runner/src/main/resources/revision.txt @@ -0,0 +1 @@ +unknown diff --git a/test_runner/src/main/resources/version.txt b/test_runner/src/main/resources/version.txt index c9b0707d7f..3546645658 100644 --- a/test_runner/src/main/resources/version.txt +++ b/test_runner/src/main/resources/version.txt @@ -1 +1 @@ -flank_snapshot +unknown