Skip to content

Commit

Permalink
feat: Add Analytics to Flank Wrapper (#2085)
Browse files Browse the repository at this point in the history
Fixes #2068

## Test Plan
> How do we know the code works?

Flank wrapper analytics are visible in mix panel.
New module for analytics is created

## Checklist

- [x] Documented
- [x] Unit tested
  • Loading branch information
piotradamczyk5 authored Jul 16, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ace7b16 commit 4d1583b
Showing 14 changed files with 46 additions and 18 deletions.
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Modules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Modules {
const val COMMON = ":common"
const val ANALYTICS = ":tool:analytics"
const val MIXPANEL_ANALYTICS = ":tool:analytics:mixpanel"
}
4 changes: 2 additions & 2 deletions corellium/domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
4 changes: 2 additions & 2 deletions flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
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)
5 changes: 3 additions & 2 deletions flank_wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
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.MIXPANEL_ANALYTICS))
implementation(project(Modules.COMMON))
implementation(Dependencies.SENTRY)
implementation(Dependencies.Fuel.CORE)
testImplementation(Dependencies.JUNIT)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.flank.wrapper.internal

import flank.common.config.isTest
import flank.tool.analytics.mixpanel.sessionId
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<String, String>) {
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")

Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ package com.github.flank.wrapper.internal
import kotlin.system.exitProcess

internal fun executeFlank(args: Array<out String>) {
sendAnalyticsFlankRun()

ProcessBuilder()
.command(buildRunCommand(args))
.inheritIO()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.flank.wrapper.internal

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"
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<String, Any>().toEvent(FLANK_WRAPPER, eventName)
2 changes: 1 addition & 1 deletion flank_wrapper/src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.2.0
2 changes: 1 addition & 1 deletion integration_tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation(project(":common"))
implementation(project(Modules.COMMON))
testImplementation(Dependencies.JUNIT)
testImplementation(Dependencies.JACKSON_XML)
testImplementation(Dependencies.JACKSON_KOTLIN)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ include(
":corellium:adapter",
":corellium:client",
":corellium:sandbox",

":tool:apk",
":tool:config",
":tool:filter",
8 changes: 4 additions & 4 deletions test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -173,9 +173,9 @@ tasks.withType<Test> {
}

dependencies {
implementation(project(":common"))
implementation(project(Modules.COMMON))
implementation(project(Modules.MIXPANEL_ANALYTICS))
implementation(Dependencies.SENTRY)
implementation(Dependencies.MIXPANEL)

implementation(Dependencies.DD_PLIST)
implementation(Dependencies.DEX_TEST_PARSER)
@@ -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)
Empty file removed tool/analytics/README.md
Empty file.
4 changes: 2 additions & 2 deletions tool/analytics/mixpanel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4d1583b

Please sign in to comment.