From d3512d563ea5dec07f08ee6c6b34ee8572318978 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Mon, 12 Jul 2021 13:27:58 +0200 Subject: [PATCH 1/6] feat: Add Analytics to Flank Wrapper --- buildSrc/src/main/kotlin/Modules.kt | 4 ++ flank-scripts/build.gradle.kts | 4 +- flank_wrapper/build.gradle.kts | 5 ++- .../flank/wrapper/internal/CrashReporter.kt | 6 +-- .../wrapper/internal/DownloadLatestVersion.kt | 1 + .../flank/wrapper/internal/FlankExecutor.kt | 2 + .../wrapper/internal/FlankWrapperAnalytics.kt | 20 ++++++++++ integration_tests/build.gradle.kts | 2 +- settings.gradle.kts | 1 + test_runner/build.gradle.kts | 4 +- .../src/main/kotlin/ftl/util/CrashReporter.kt | 1 + test_runner/src/main/kotlin/ftl/util/Utils.kt | 1 + tool/analytics/README.md | 9 +++++ .../flank/analytics/UsageStatisticsClient.kt | 37 +++++++++++++++++++ tool/apk/build.gradle.kts | 1 - 15 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 buildSrc/src/main/kotlin/Modules.kt create mode 100644 flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt create mode 100644 tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt diff --git a/buildSrc/src/main/kotlin/Modules.kt b/buildSrc/src/main/kotlin/Modules.kt new file mode 100644 index 0000000000..aa7806bb96 --- /dev/null +++ b/buildSrc/src/main/kotlin/Modules.kt @@ -0,0 +1,4 @@ +object Modules { + const val COMMON = ":common" + const val ANALYTICS = ":tool:analytics" +} diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 93a172cc15..30cb62d5fe 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -25,7 +25,7 @@ shadowJar.apply { } } // .. -version = "1.9.22" +version = "1.9.23" group = "com.github.flank" application { @@ -93,7 +93,7 @@ repositories { dependencies { implementation(Dependencies.KOTLIN_SERIALIZATION) - implementation(project(":common")) + implementation(project(Modules.COMMON)) implementation(Dependencies.CLIKT) implementation(Dependencies.JCABI_GITHUB) implementation(Dependencies.SLF4J_NOP) diff --git a/flank_wrapper/build.gradle.kts b/flank_wrapper/build.gradle.kts index 0a83d94704..43983bce83 100644 --- a/flank_wrapper/build.gradle.kts +++ b/flank_wrapper/build.gradle.kts @@ -23,7 +23,7 @@ shadowJar.apply { } } // .. -version = "1.1.0" +version = "1.2.0" group = "com.github.flank" repositories { @@ -75,7 +75,8 @@ publishing { } dependencies { - implementation(project(":common")) + implementation(project(Modules.ANALYTICS)) + implementation(project(Modules.COMMON)) implementation(Dependencies.SENTRY) implementation(Dependencies.Fuel.CORE) testImplementation(Dependencies.JUNIT) diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt index f8e67a0610..bfd23b21ff 100644 --- a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt @@ -1,8 +1,8 @@ package com.github.flank.wrapper.internal +import flank.analytics.sessionId import flank.common.config.isTest import io.sentry.Sentry -import java.util.UUID private const val SESSION_ID = "session.id" private const val OS_NAME = "os.name" @@ -17,7 +17,7 @@ fun setupCrashReporter() { } logTags( - SESSION_ID to sessionID, + SESSION_ID to sessionId, OS_NAME to osName, FLANK_WRAPPER_VERSION to flankWrapperVersion, ) @@ -28,8 +28,6 @@ private fun logTags(vararg tags: Pair) { tags.forEach { (key, value) -> Sentry.setTag(key, value) } } -private val sessionID by lazy { UUID.randomUUID().toString() } - private val osName: String get() = System.getProperty("os.name") diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/DownloadLatestVersion.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/DownloadLatestVersion.kt index 1b554135bc..464b0ba95d 100644 --- a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/DownloadLatestVersion.kt +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/DownloadLatestVersion.kt @@ -7,6 +7,7 @@ internal fun downloadLatestFlankVersion() { sourceUrl = FLANK_JAR_REMOTE_PATH, destination = flankRunnerPath ) + sendAnalyticsNewFlankVersionDownloaded() } private const val FLANK_JAR_REMOTE_PATH = "https://github.com/Flank/flank/releases/latest/download/flank.jar" diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankExecutor.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankExecutor.kt index 57cfddb28e..cab26a0910 100644 --- a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankExecutor.kt +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankExecutor.kt @@ -3,6 +3,8 @@ package com.github.flank.wrapper.internal import kotlin.system.exitProcess internal fun executeFlank(args: Array) { + sendAnalyticsFlankRun() + ProcessBuilder() .command(buildRunCommand(args)) .inheritIO() diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt new file mode 100644 index 0000000000..0744146e34 --- /dev/null +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt @@ -0,0 +1,20 @@ +package com.github.flank.wrapper.internal + +import flank.analytics.send +import flank.analytics.toEvent + +private const val FLANK_WRAPPER = "flank_wrapper" +private const val EVENT_RUN = "flank run" +private const val EVENT_NEW_FLANK_VERSION_DOWNLOADED = "new_version_downloaded" + +internal fun sendAnalyticsNewFlankVersionDownloaded() { + eventWithoutProperties(EVENT_NEW_FLANK_VERSION_DOWNLOADED).send() +} + +internal fun sendAnalyticsFlankRun() { + eventWithoutProperties(EVENT_RUN).send() +} + +private fun eventWithoutProperties( + eventName: String +) = emptyMap().toEvent(FLANK_WRAPPER, eventName) diff --git a/integration_tests/build.gradle.kts b/integration_tests/build.gradle.kts index 0254d62764..f3948ed974 100644 --- a/integration_tests/build.gradle.kts +++ b/integration_tests/build.gradle.kts @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation(project(":common")) + implementation(project(Modules.COMMON)) testImplementation(Dependencies.JUNIT) testImplementation(Dependencies.JACKSON_XML) testImplementation(Dependencies.JACKSON_KOTLIN) diff --git a/settings.gradle.kts b/settings.gradle.kts index a14c00ab89..53ff47465d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,6 +21,7 @@ include( ":corellium:adapter", ":corellium:client", ":corellium:sandbox", + ":tool:apk", ":tool:config", ":tool:filter", diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 14d61f497d..75fcd1f8a1 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -173,9 +173,9 @@ tasks.withType { } dependencies { - implementation(project(":common")) + implementation(project(Modules.COMMON)) + implementation(project(Modules.ANALYTICS)) implementation(Dependencies.SENTRY) - implementation(Dependencies.MIXPANEL) implementation(Dependencies.DD_PLIST) implementation(Dependencies.DEX_TEST_PARSER) diff --git a/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt b/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt index b84608c071..34dadfb454 100644 --- a/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt +++ b/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt @@ -1,5 +1,6 @@ package ftl.util +import flank.analytics.sessionId import flank.common.config.isTest import flank.tool.analytics.mixpanel.SESSION_ID import flank.tool.analytics.mixpanel.sessionId diff --git a/test_runner/src/main/kotlin/ftl/util/Utils.kt b/test_runner/src/main/kotlin/ftl/util/Utils.kt index 81f8382864..b906c7abb1 100644 --- a/test_runner/src/main/kotlin/ftl/util/Utils.kt +++ b/test_runner/src/main/kotlin/ftl/util/Utils.kt @@ -3,6 +3,7 @@ package ftl.util import com.fasterxml.jackson.annotation.JsonProperty +import flank.analytics.sessionId import flank.common.logLn import flank.tool.analytics.mixpanel.sessionId import ftl.run.exception.FlankGeneralError diff --git a/tool/analytics/README.md b/tool/analytics/README.md index e69de29bb2..05c5eb781c 100644 --- a/tool/analytics/README.md +++ b/tool/analytics/README.md @@ -0,0 +1,9 @@ +# Analytics + +Module responsible for sending usage statistics. + +### References + +* Module type - [tool](../../docs/architecture.md#tool) +* Dependency type - [dynamic](../../docs/architecture.md#dynamic_dependencies) +* Public API - [UsageStatisticsClient.kt](./src/main/kotlin/flank/analytics/UsageStatisticsClient.kt) diff --git a/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt b/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt new file mode 100644 index 0000000000..21963e523c --- /dev/null +++ b/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt @@ -0,0 +1,37 @@ +package flank.analytics + +import com.mixpanel.mixpanelapi.MessageBuilder +import com.mixpanel.mixpanelapi.MixpanelAPI +import flank.common.toJSONObject +import org.json.JSONObject +import java.util.UUID + +private const val MIXPANEL_API_TOKEN = "d9728b2c8e6ca9fd6de1fcd32dd8cdc2" +private const val SESSION_ID = "session.id" +private const val PROJECT_ID = "project_id" +private const val NAME_KEY = "name" + +internal val messageBuilder by lazy { + MessageBuilder(MIXPANEL_API_TOKEN) +} + +private val apiClient by lazy { + MixpanelAPI() +} + +fun JSONObject.send() = apiClient.sendMessage(this) + +fun Map.toEvent(projectId: String, eventName: String): JSONObject = + messageBuilder.event(projectId, eventName, (this + sessionIdField).toJSONObject()) + +val sessionId by lazy { + UUID.randomUUID().toString() +} + +fun registerUser(userKey: String) { + messageBuilder.set( + userKey, mapOf(PROJECT_ID to userKey, NAME_KEY to userKey).toJSONObject() + ).send() +} + +private val sessionIdField = Pair(SESSION_ID, sessionId) diff --git a/tool/apk/build.gradle.kts b/tool/apk/build.gradle.kts index 2d970c1bd3..10fa2662bc 100644 --- a/tool/apk/build.gradle.kts +++ b/tool/apk/build.gradle.kts @@ -23,5 +23,4 @@ dependencies { tasks.test { maxHeapSize = "3072m" minHeapSize = "512m" - dependsOn(":resolveArtifacts") } From 3061c58ec1d77a2d39ee83832367bbd961397cf9 Mon Sep 17 00:00:00 2001 From: piotradamczyk5 Date: Mon, 12 Jul 2021 11:39:43 +0000 Subject: [PATCH 2/6] [Auto-commit] Added files fixed by Detekt --- flank_wrapper/src/main/resources/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flank_wrapper/src/main/resources/version.txt b/flank_wrapper/src/main/resources/version.txt index 1cc5f657e0..867e52437a 100644 --- a/flank_wrapper/src/main/resources/version.txt +++ b/flank_wrapper/src/main/resources/version.txt @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.2.0 \ No newline at end of file From c736d60bb1ce8887d25b4b2c670ade0cd007757f Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Wed, 14 Jul 2021 19:33:22 +0200 Subject: [PATCH 3/6] remove unecessary changes --- tool/analytics/README.md | 9 --------- tool/apk/build.gradle.kts | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 tool/analytics/README.md diff --git a/tool/analytics/README.md b/tool/analytics/README.md deleted file mode 100644 index 05c5eb781c..0000000000 --- a/tool/analytics/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Analytics - -Module responsible for sending usage statistics. - -### References - -* Module type - [tool](../../docs/architecture.md#tool) -* Dependency type - [dynamic](../../docs/architecture.md#dynamic_dependencies) -* Public API - [UsageStatisticsClient.kt](./src/main/kotlin/flank/analytics/UsageStatisticsClient.kt) diff --git a/tool/apk/build.gradle.kts b/tool/apk/build.gradle.kts index 10fa2662bc..2d970c1bd3 100644 --- a/tool/apk/build.gradle.kts +++ b/tool/apk/build.gradle.kts @@ -23,4 +23,5 @@ dependencies { tasks.test { maxHeapSize = "3072m" minHeapSize = "512m" + dependsOn(":resolveArtifacts") } From 9595d79e6b8f718793befdf6635997de445ddd49 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Wed, 14 Jul 2021 19:36:42 +0200 Subject: [PATCH 4/6] remove unecessary changes --- .../flank/analytics/UsageStatisticsClient.kt | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt diff --git a/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt b/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt deleted file mode 100644 index 21963e523c..0000000000 --- a/tool/analytics/src/main/kotlin/flank/analytics/UsageStatisticsClient.kt +++ /dev/null @@ -1,37 +0,0 @@ -package flank.analytics - -import com.mixpanel.mixpanelapi.MessageBuilder -import com.mixpanel.mixpanelapi.MixpanelAPI -import flank.common.toJSONObject -import org.json.JSONObject -import java.util.UUID - -private const val MIXPANEL_API_TOKEN = "d9728b2c8e6ca9fd6de1fcd32dd8cdc2" -private const val SESSION_ID = "session.id" -private const val PROJECT_ID = "project_id" -private const val NAME_KEY = "name" - -internal val messageBuilder by lazy { - MessageBuilder(MIXPANEL_API_TOKEN) -} - -private val apiClient by lazy { - MixpanelAPI() -} - -fun JSONObject.send() = apiClient.sendMessage(this) - -fun Map.toEvent(projectId: String, eventName: String): JSONObject = - messageBuilder.event(projectId, eventName, (this + sessionIdField).toJSONObject()) - -val sessionId by lazy { - UUID.randomUUID().toString() -} - -fun registerUser(userKey: String) { - messageBuilder.set( - userKey, mapOf(PROJECT_ID to userKey, NAME_KEY to userKey).toJSONObject() - ).send() -} - -private val sessionIdField = Pair(SESSION_ID, sessionId) From 5ce340b466036074702607b81e57ea0dfd52b510 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Wed, 14 Jul 2021 19:41:24 +0200 Subject: [PATCH 5/6] fix modules dependencies --- buildSrc/src/main/kotlin/Modules.kt | 1 + corellium/domain/build.gradle.kts | 4 ++-- flank_wrapper/build.gradle.kts | 2 +- .../com/github/flank/wrapper/internal/CrashReporter.kt | 2 +- .../github/flank/wrapper/internal/FlankWrapperAnalytics.kt | 4 ++-- test_runner/build.gradle.kts | 6 +++--- tool/analytics/mixpanel/build.gradle.kts | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/buildSrc/src/main/kotlin/Modules.kt b/buildSrc/src/main/kotlin/Modules.kt index aa7806bb96..6e4ced7bb9 100644 --- a/buildSrc/src/main/kotlin/Modules.kt +++ b/buildSrc/src/main/kotlin/Modules.kt @@ -1,4 +1,5 @@ object Modules { const val COMMON = ":common" const val ANALYTICS = ":tool:analytics" + const val MIXPANEL_ANALYTICS = ":tool:analytics:mixpanel" } diff --git a/corellium/domain/build.gradle.kts b/corellium/domain/build.gradle.kts index 7b26caabb8..89b5d91249 100644 --- a/corellium/domain/build.gradle.kts +++ b/corellium/domain/build.gradle.kts @@ -26,8 +26,8 @@ dependencies { api(project(":tool:instrument:log")) api(project(":tool:junit")) api(project(":tool:log")) - api(project(":tool:analytics")) - api(project(":tool:analytics:mixpanel")) + api(project(Modules.ANALYTICS)) + api(project(Modules.MIXPANEL_ANALYTICS)) testImplementation(Dependencies.JUNIT) testImplementation(project(":corellium:adapter")) diff --git a/flank_wrapper/build.gradle.kts b/flank_wrapper/build.gradle.kts index 43983bce83..3fcc0bc27e 100644 --- a/flank_wrapper/build.gradle.kts +++ b/flank_wrapper/build.gradle.kts @@ -75,7 +75,7 @@ publishing { } dependencies { - implementation(project(Modules.ANALYTICS)) + implementation(project(Modules.MIXPANEL_ANALYTICS)) implementation(project(Modules.COMMON)) implementation(Dependencies.SENTRY) implementation(Dependencies.Fuel.CORE) diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt index bfd23b21ff..1d42c9b64d 100644 --- a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt @@ -1,7 +1,7 @@ package com.github.flank.wrapper.internal -import flank.analytics.sessionId import flank.common.config.isTest +import flank.tool.analytics.mixpanel.sessionId import io.sentry.Sentry private const val SESSION_ID = "session.id" diff --git a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt index 0744146e34..9b8a636199 100644 --- a/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt +++ b/flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankWrapperAnalytics.kt @@ -1,7 +1,7 @@ package com.github.flank.wrapper.internal -import flank.analytics.send -import flank.analytics.toEvent +import flank.tool.analytics.mixpanel.send +import flank.tool.analytics.mixpanel.toEvent private const val FLANK_WRAPPER = "flank_wrapper" private const val EVENT_RUN = "flank run" diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 75fcd1f8a1..cbd19f6222 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -174,7 +174,7 @@ tasks.withType { dependencies { implementation(project(Modules.COMMON)) - implementation(project(Modules.ANALYTICS)) + implementation(project(Modules.MIXPANEL_ANALYTICS)) implementation(Dependencies.SENTRY) implementation(Dependencies.DD_PLIST) @@ -212,8 +212,8 @@ dependencies { implementation(project(":corellium:cli")) - implementation(project(":tool:analytics")) - implementation(project(":tool:analytics:mixpanel")) + implementation(project(Modules.ANALYTICS)) + implementation(project(Modules.MIXPANEL_ANALYTICS)) testImplementation(Dependencies.JUNIT) testImplementation(Dependencies.SYSTEM_RULES) diff --git a/tool/analytics/mixpanel/build.gradle.kts b/tool/analytics/mixpanel/build.gradle.kts index 61ee799a01..b37e93f0fd 100644 --- a/tool/analytics/mixpanel/build.gradle.kts +++ b/tool/analytics/mixpanel/build.gradle.kts @@ -17,8 +17,8 @@ dependencies { implementation(Dependencies.MIXPANEL) implementation(Dependencies.JACKSON_KOTLIN) implementation(Dependencies.JACKSON_YAML) - implementation(project(":common")) - implementation(project(":tool:analytics")) + implementation(project(Modules.COMMON)) + implementation(project(Modules.ANALYTICS)) testImplementation(Dependencies.JUNIT) } From 17e05441ff178b3c56c7cee51bf5206a1709b16f Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Wed, 14 Jul 2021 21:48:23 +0200 Subject: [PATCH 6/6] fix modules dependencies --- test_runner/src/main/kotlin/ftl/util/CrashReporter.kt | 1 - test_runner/src/main/kotlin/ftl/util/Utils.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt b/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt index 34dadfb454..b84608c071 100644 --- a/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt +++ b/test_runner/src/main/kotlin/ftl/util/CrashReporter.kt @@ -1,6 +1,5 @@ package ftl.util -import flank.analytics.sessionId import flank.common.config.isTest import flank.tool.analytics.mixpanel.SESSION_ID import flank.tool.analytics.mixpanel.sessionId diff --git a/test_runner/src/main/kotlin/ftl/util/Utils.kt b/test_runner/src/main/kotlin/ftl/util/Utils.kt index b906c7abb1..81f8382864 100644 --- a/test_runner/src/main/kotlin/ftl/util/Utils.kt +++ b/test_runner/src/main/kotlin/ftl/util/Utils.kt @@ -3,7 +3,6 @@ package ftl.util import com.fasterxml.jackson.annotation.JsonProperty -import flank.analytics.sessionId import flank.common.logLn import flank.tool.analytics.mixpanel.sessionId import ftl.run.exception.FlankGeneralError