Skip to content

Commit 301d2cf

Browse files
committed
[Ft]:[DEVX-8764]:Clickstream Health refactor
1 parent 5ea23c8 commit 301d2cf

File tree

165 files changed

+5183
-4878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+5183
-4878
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ android {
3333
useSupportLibrary = true
3434
}
3535

36-
buildConfigField("String", "ACCOUNT_ID", "\"${props.getProperty("accountId")}\"")
37-
buildConfigField("String", "SECRET_KEY", "\"${props.getProperty("secretKey")}\"")
3836
buildConfigField("String", "ENDPOINT", "\"${props.getProperty("endpoint")}\"")
39-
buildConfigField("String", "STUB_BEARER", "\"${props.getProperty("bearer")}\"")
37+
buildConfigField("String", "API_KEY", "\"${props.getProperty("apiKey")}\"")
4038
}
4139

4240
sourceSets {

app/src/main/java/com/clickstream/app/App.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package com.clickstream.app
22

33
import android.app.Application
4+
import android.provider.Settings
5+
import android.util.Base64
46
import clickstream.ClickStream
57
import clickstream.config.CSConfiguration
68
import clickstream.connection.CSConnectionEvent
79
import clickstream.connection.CSSocketConnectionListener
810
import clickstream.eventvisualiser.CSEventVisualiserListener
911
import clickstream.eventvisualiser.ui.CSEventVisualiserUI
10-
import clickstream.health.constant.CSTrackedVia
11-
import clickstream.lifecycle.impl.DefaultCSAppLifeCycleObserver
1212
import clickstream.logger.CSLogLevel
13-
import clickstream.logger.CSLogger
14-
import com.clickstream.app.config.AccountId
15-
import com.clickstream.app.config.EndPoint
16-
import com.clickstream.app.config.SecretKey
17-
import com.clickstream.app.config.StubBearer
1813
import com.clickstream.app.config.csConfig
1914
import com.clickstream.app.config.csInfo
15+
import com.clickstream.app.config.getHealthGateway
2016
import com.clickstream.app.helper.printMessage
2117
import dagger.hilt.android.HiltAndroidApp
2218
import kotlinx.coroutines.ExperimentalCoroutinesApi
19+
import java.util.*
2320

2421
@OptIn(ExperimentalCoroutinesApi::class)
2522
@HiltAndroidApp
@@ -28,25 +25,25 @@ class App : Application() {
2825
override fun onCreate() {
2926
super.onCreate()
3027

31-
val csLogger = CSLogger(CSLogLevel.DEBUG)
32-
3328
ClickStream.initialize(
3429
configuration = CSConfiguration.Builder(
3530
context = this,
36-
info = csInfo(),
3731
config = csConfig(
38-
AccountId(BuildConfig.ACCOUNT_ID),
39-
SecretKey(BuildConfig.SECRET_KEY),
40-
EndPoint(BuildConfig.ENDPOINT),
41-
StubBearer(BuildConfig.STUB_BEARER),
42-
CSTrackedVia.Both
32+
url = BuildConfig.ENDPOINT,
33+
deviceId = deviceId(),
34+
apiKey = String(
35+
Base64.encode(
36+
BuildConfig.API_KEY.toByteArray(),
37+
Base64.NO_WRAP
38+
)
39+
)
4340
),
44-
appLifeCycle = DefaultCSAppLifeCycleObserver(csLogger)
45-
)
46-
.applyLogLevel()
47-
.applyEventListener()
48-
.applySocketConnectionListener()
49-
.build()
41+
info = csInfo()
42+
).applyLogLevel()
43+
.applyEventListener()
44+
.applyHealthFactory()
45+
.applySocketConnectionListener()
46+
.build()
5047
)
5148

5249
CSEventVisualiserUI.initialise(this)
@@ -77,4 +74,16 @@ class App : Application() {
7774
})
7875
return this
7976
}
77+
78+
private fun CSConfiguration.Builder.applyHealthFactory(): CSConfiguration.Builder {
79+
setHealthGateway(getHealthGateway(this@App))
80+
return this
81+
}
82+
83+
private fun deviceId(): String {
84+
return Settings.Secure.getString(
85+
contentResolver,
86+
Settings.Secure.ANDROID_ID
87+
) ?: UUID.randomUUID().toString()
88+
}
8089
}

app/src/main/java/com/clickstream/app/config/CSInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import clickstream.api.CSSessionInfo
77
import clickstream.api.CSUserInfo
88

99
fun csInfo() = CSInfo(
10-
appInfo = CSAppInfo(appVersion = "1.1.0"),
10+
appInfo = CSAppInfo(appVersion = "2.1.0"),
1111
locationInfo = CSLocationInfo(
1212
latitude = -6.1753871,
1313
longitude = 106.8249641,

app/src/main/java/com/clickstream/app/config/DefaultCSConfig.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import clickstream.config.CSConfig
44
import clickstream.config.CSEventProcessorConfig
55
import clickstream.config.CSEventSchedulerConfig
66
import clickstream.config.CSNetworkConfig
7-
import clickstream.health.constant.CSTrackedVia
87
import clickstream.health.model.CSHealthEventConfig
98
import com.clickstream.app.helper.load
109

1110
fun csConfig(
12-
accountId: AccountId,
13-
secretKey: SecretKey,
14-
endpoint: EndPoint,
15-
stubBearer: StubBearer,
16-
trackedVia: CSTrackedVia
11+
url: String,
12+
deviceId: String,
13+
apiKey: String,
1714
): CSConfig {
1815
val eventClassification =
1916
CSEventClassificationParser::class.java.load("clickstream_classifier.json")!!
@@ -23,10 +20,12 @@ fun csConfig(
2320
realtimeEvents = eventClassification.realTimeEvents(),
2421
instantEvent = eventClassification.instantEvents()
2522
),
26-
eventSchedulerConfig = CSEventSchedulerConfig.default(),
23+
eventSchedulerConfig = CSEventSchedulerConfig.default().copy(backgroundTaskEnabled = true),
2724
networkConfig = CSNetworkConfig.default(
28-
CSNetworkModule.create(accountId, secretKey, stubBearer)
29-
).copy(endPoint = endpoint.value),
30-
healthEventConfig = CSHealthEventConfig.default(trackedVia)
25+
url = url, mapOf(
26+
"Authorization" to "Basic $apiKey",
27+
"X-UniqueId" to deviceId
28+
)
29+
),
3130
)
3231
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.clickstream.app.config
2+
3+
import DefaultCSHealthGateway
4+
import android.content.Context
5+
import android.util.Log
6+
import clickstream.health.intermediate.CSHealthEventLoggerListener
7+
import clickstream.health.intermediate.CSMemoryStatusProvider
8+
import clickstream.health.model.CSHealthEventConfig
9+
import clickstream.health.time.CSHealthTimeStampGenerator
10+
import clickstream.logger.CSLogLevel
11+
import clickstream.logger.CSLogger
12+
13+
14+
fun getHealthGateway(context: Context) = DefaultCSHealthGateway(
15+
context = context,
16+
csInfo = csInfo(),
17+
logger = CSLogger(CSLogLevel.DEBUG),
18+
timeStampGenerator = timeStampGenerator(),
19+
csMemoryStatusProvider = memoryStatusProvider(),
20+
csHealthEventConfig = healthConfig(),
21+
csHealthEventLoggerListener = healthEventLogger()
22+
)
23+
24+
25+
fun healthEventLogger() = object : CSHealthEventLoggerListener {
26+
override fun logEvent(eventName: String, healthData: HashMap<String, Any>) {
27+
Log.d("CS External Logger", "$eventName: $healthData")
28+
}
29+
30+
}
31+
32+
fun memoryStatusProvider() = object : CSMemoryStatusProvider {
33+
override fun isLowMemory(): Boolean {
34+
return false
35+
}
36+
}
37+
38+
fun timeStampGenerator() = object : CSHealthTimeStampGenerator {
39+
override fun getTimeStamp(): Long {
40+
return System.currentTimeMillis()
41+
}
42+
}
43+
44+
fun healthConfig() =
45+
CSHealthEventConfig(
46+
minTrackedVersion = "1.1.0",
47+
randomUserIdRemainder = (0..9).toList(),
48+
destination = listOf("CS", "CT"),
49+
verbosityLevel = "minimum"
50+
)

app/src/main/java/com/clickstream/app/main/MainViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.clickstream.app.main
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import clickstream.CSEvent
56
import clickstream.ClickStream
6-
import clickstream.model.CSEvent
77
import com.clickstream.app.helper.Dispatcher
88
import com.clickstream.app.helper.printMessage
99
import com.clickstream.app.main.MainIntent.ConnectIntent

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import plugin.DetektConfigurationPlugin
22

33
plugins {
4-
id("org.jetbrains.dokka") version "1.4.32"
4+
id("org.jetbrains.dokka") version "1.6.0"
55
}
66

77
apply(plugin = "binary-compatibility-validator")
@@ -17,7 +17,7 @@ buildscript {
1717

1818
dependencies {
1919
classpath("com.android.tools.build:gradle:7.0.4")
20-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
20+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.32")
2121
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.14")
2222
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:0.8.0")
2323
classpath("com.google.dagger:hilt-android-gradle-plugin:2.41")

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ plugins {
1717

1818
dependencies {
1919
implementation("com.android.tools.build:gradle:7.0.4")
20-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
20+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
2121
implementation("com.github.node-gradle:gradle-node-plugin:2.2.0")
2222
implementation("org.codehaus.groovy:groovy:3.0.9")
2323
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")

buildSrc/src/main/kotlin/deps.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
object versions {
44
internal const val jacoco = "0.8.4"
5-
internal const val detekt = "1.1.1"
5+
internal const val detekt = "1.16.0"
66

7-
internal const val kotlin = "1.4.32"
7+
internal const val kotlin = "1.5.32"
88
internal const val coroutines = "1.5.2"
99

1010
internal const val scarlet = "0.1.10"
1111
internal const val okHttp = "3.12.1"
1212

13-
internal const val room = "2.2.3"
14-
internal const val lifecycle = "2.2.0"
13+
internal const val room = "2.4.2"
14+
internal const val lifecycle = "2.4.1"
1515

1616
internal const val workManagerVersion = "2.7.1"
1717

1818
internal const val csProtoVersion = "1.18.2"
19+
20+
internal const val csEventListenerVersion = "2.0.0-alpha-1"
1921
}
2022

2123
object deps {

clickstream-health-metrics-api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ android {
3535
dependencies {
3636
// Clickstream
3737
compileOnly(files("$rootDir/libs/proto-sdk-1.18.6.jar"))
38+
implementation(deps.kotlin.coroutines.core)
39+
3840

3941
implementation(deps.android.core.annotation)
4042
}
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package clickstream.health
22

33
import androidx.annotation.RestrictTo
4-
import clickstream.health.intermediate.CSEventHealthListener
5-
import clickstream.health.intermediate.CSHealthEventFactory
64
import clickstream.health.intermediate.CSHealthEventProcessor
7-
import clickstream.health.intermediate.CSHealthEventRepository
85

6+
/**
7+
* Wrapper class that creates [CSHealthEventProcessor].
8+
*
9+
* */
910
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
1011
public interface CSHealthGateway {
11-
public val eventHealthListener: CSEventHealthListener
1212

13-
public val healthEventRepository: CSHealthEventRepository
13+
/**
14+
* Class to process health events.
15+
*
16+
* */
17+
public val healthEventProcessor: CSHealthEventProcessor?
1418

15-
public val healthEventProcessor: CSHealthEventProcessor
19+
/**
20+
* Clears health events on app version upgrade.
21+
*
22+
* */
23+
public suspend fun clearHealthEventsForVersionChange()
1624

17-
public val healthEventFactory: CSHealthEventFactory
1825
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package clickstream.health.constant
2+
3+
public object CSErrorConstant {
4+
public const val PARSING_EXCEPTION: String = "parsing_exception"
5+
public const val LOW_BATTERY: String = "low_battery"
6+
public const val NETWORK_UNAVAILABLE: String = "network_unavailable"
7+
public const val SOCKET_NOT_OPEN: String = "socket_not_open"
8+
public const val UNKNOWN: String = "unknown"
9+
public const val USER_UNAUTHORIZED: String = "401 Unauthorized"
10+
public const val SOCKET_TIMEOUT: String = "socket_timeout"
11+
public const val MAX_USER_LIMIT_REACHED: String = "max_user_limit_reached"
12+
public const val MAX_CONNECTION_LIMIT_REACHED: String = "max_connection_limit_reached"
13+
}

0 commit comments

Comments
 (0)