Skip to content

Commit

Permalink
[Improvement] : Move CSHealthMetrics to Optional Setter
Browse files Browse the repository at this point in the history
  • Loading branch information
radityagumay committed Jun 1, 2022
1 parent b4914e7 commit c6e4be0
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 33 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

Based on https://keepachangelog.com/en/1.0.0/

## 0.2.36-snapshot
## 0.2.39

### Update
- Support Pluggable HealthMetrics
- [Improvement] : Move CSHealthMetrics to Optional Setter


## 0.2.36

### Update
- [[Feature] : Support Pluggable HealthMetrics](https://github.com/gojek/clickstream-android/discussions/6)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ dependencies {
// Required
implementation 'com.gojek.clickstream:clickstream-android:[latest_version]'
implementation 'com.gojek.clickstream:clickstream-lifecycle:[latest_version]'
implementation 'com.gojek.clickstream:clickstream-health-metrics-noop:[latest_version]'

// Optional
implementation 'com.gojek.clickstream:clickstream-health-metrics:[latest_version]'
Expand Down Expand Up @@ -105,6 +104,7 @@ class App : Application() {
healthGateway = DefaultOpCSHealthGateway.factory(/*args*/)
).apply {
setLogLevel(DEBUG)
/**/
setCSSocketConnectionListener(connectionListener())
}.build())
}
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ object deps {
object workManager {
const val workRuntimeKtx = "androidx.work:work-runtime-ktx:${versions.workManagerVersion}"
const val workTesting = "androidx.work:work-testing:${versions.workManagerVersion}"

}

object utils {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package clickstream.health

import clickstream.health.time.CSEventGeneratedTimestampListener
package clickstream.health.time

public interface CSTimeStampGenerator {
public fun getTimeStamp(): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ import clickstream.health.internal.DefaultCSHealthEventFactory
import clickstream.health.internal.DefaultCSHealthEventProcessor
import clickstream.health.internal.DefaultCSHealthEventRepository
import clickstream.health.model.CSHealthEventConfig
import clickstream.health.time.CSTimeStampGenerator
import clickstream.lifecycle.CSAppLifeCycle
import clickstream.logger.CSLogger
import clickstream.util.CSAppVersionSharedPref
import clickstream.util.impl.DefaultCSAppVersionSharedPref
import java.util.UUID
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

public object DefaultCSHealthGateway {

public fun factory(
appVersion: String,
sessionId: String,
context: Context,
healthEventConfig: CSHealthEventConfig,
csInfo: CSInfo,
logger: CSLogger,
healthEventLogger: CSHealthEventLoggerListener,
appVersion: String,
timeStampGenerator: CSTimeStampGenerator,
metaProvider: CSMetaProvider,
eventHealthListener: CSEventHealthListener,
Expand All @@ -45,7 +46,7 @@ public object DefaultCSHealthGateway {
override val eventHealthListener: CSEventHealthListener = eventHealthListener
override val healthEventRepository: CSHealthEventRepository by lazy {
DefaultCSHealthEventRepository(
sessionId = UUID.randomUUID().toString(),
sessionId = sessionId,
healthEventDao = CSHealthDatabase.getInstance(context).healthEventDao(),
info = csInfo
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package clickstream.health.internal

import androidx.annotation.RestrictTo
import clickstream.api.CSMetaProvider
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.intermediate.CSHealthEventFactory
import com.gojek.clickstream.internal.Health
Expand Down
4 changes: 4 additions & 0 deletions clickstream/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ dependencies {
// Clickstream
implementation(files("$rootDir/libs/proto-sdk-1.18.6.jar"))
api(projects.clickstreamLogger)
api(projects.clickstreamHealthMetricsNoop)
compileOnly(projects.clickstreamApi)
compileOnly(projects.clickstreamHealthMetricsApi)
compileOnly(projects.clickstreamLifecycle)

// Proto
api(deps.utils.protoLite)

// Common
deps.common.list.forEach(::implementation)

Expand Down
24 changes: 21 additions & 3 deletions clickstream/src/main/kotlin/clickstream/config/CSConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import clickstream.health.intermediate.CSHealthEventLoggerListener
import clickstream.health.intermediate.CSHealthEventProcessor
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.CSHealthGateway
import clickstream.health.NoOpCSHealthGateway
import clickstream.health.time.CSEventGeneratedTimestampListener
import clickstream.internal.NoOpCSEventHealthListener
import clickstream.internal.analytics.impl.NoOpCSHealthEventLogger
Expand Down Expand Up @@ -88,14 +89,17 @@ public class CSConfiguration private constructor(
*/
private val config: CSConfig,

private val appLifeCycle: CSAppLifeCycle,

private val healthGateway: CSHealthGateway
/**
* Specify Clicstream lifecycle, this is needed in order to send events
* to the backend.
*/
private val appLifeCycle: CSAppLifeCycle
) {
private lateinit var dispatcher: CoroutineDispatcher
private lateinit var eventGeneratedListener: CSEventGeneratedTimestampListener
private lateinit var socketConnectionListener: CSSocketConnectionListener
private lateinit var remoteConfig: CSRemoteConfig
private lateinit var healthGateway: CSHealthGateway
private var logLevel: CSLogLevel = CSLogLevel.OFF

/**
Expand Down Expand Up @@ -155,6 +159,17 @@ public class CSConfiguration private constructor(
this.remoteConfig = remoteConfig
}

/**
* Specify implementation of [CSHealthGateway], by default it would use
* [NoOpCSHealthGateway]
*
* @return This [Builder] instance
*/
public fun setHealthGateway(healthGateway: CSHealthGateway): Builder =
apply {
this.healthGateway = healthGateway
}

/**
* Builds a [CSConfiguration] object.
*
Expand All @@ -173,6 +188,9 @@ public class CSConfiguration private constructor(
if (::remoteConfig.isInitialized.not()) {
remoteConfig = NoOpCSRemoteConfig()
}
if(::healthGateway.isInitialized.not()) {
healthGateway = NoOpCSHealthGateway.factory()
}
return CSConfiguration(
context, dispatcher,
info, config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import clickstream.config.CSConfig
import clickstream.config.CSEventSchedulerConfig
import clickstream.config.CSRemoteConfig
import clickstream.connection.CSSocketConnectionListener
import clickstream.health.CSTimeStampGenerator
import clickstream.health.DefaultCSTimeStampGenerator
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.identity.DefaultCSGuIdGenerator
import clickstream.health.intermediate.CSEventHealthListener
import clickstream.health.intermediate.CSHealthEventFactory
import clickstream.health.intermediate.CSHealthEventProcessor
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.time.CSEventGeneratedTimestampListener
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.time.DefaultCSTimeStampGenerator
import clickstream.internal.db.CSDatabase
import clickstream.internal.di.CSServiceLocator
import clickstream.internal.eventprocessor.CSEventProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package clickstream.internal.eventscheduler

import clickstream.api.CSInfo
import clickstream.config.CSEventSchedulerConfig
import clickstream.health.CSTimeStampGenerator
import clickstream.health.constant.CSEventNamesConstant.ClickStreamFlushOnBackground
import clickstream.health.constant.CSEventTypesConstant
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.intermediate.CSEventHealthListener
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.model.CSHealthEventDTO
import clickstream.health.time.CSTimeStampGenerator
import clickstream.internal.di.CSServiceLocator
import clickstream.internal.networklayer.CSBackgroundNetworkManager
import clickstream.internal.utils.CSBatteryStatusObserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package clickstream.internal.eventscheduler
import clickstream.api.CSInfo
import clickstream.config.CSEventSchedulerConfig
import clickstream.extension.isValidMessage
import clickstream.health.CSTimeStampGenerator
import clickstream.health.constant.CSEventNamesConstant.ClickStreamEventBatchCreated
import clickstream.health.constant.CSEventNamesConstant.ClickStreamEventBatchTriggerFailed
import clickstream.health.constant.CSEventNamesConstant.ClickStreamEventCached
Expand All @@ -13,6 +12,7 @@ import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.intermediate.CSEventHealthListener
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.model.CSHealthEventDTO
import clickstream.health.time.CSTimeStampGenerator
import clickstream.internal.analytics.CSErrorReasons
import clickstream.internal.networklayer.CSNetworkManager
import clickstream.internal.utils.CSBatteryLevel
Expand Down Expand Up @@ -236,12 +236,12 @@ internal open class CSEventScheduler(
if (batch.isNotEmpty() && batch[0].messageName != Health::class.qualifiedName.orEmpty()) {
logger.debug {
"CSEventScheduler#forwardEvents#batch - " +
"eventBatchId : ${eventRequest.reqGuid}, " +
"eventId : ${batch.joinToString { it.eventGuid }}"
"eventBatchId : ${eventRequest.reqGuid}, " +
"eventId : ${batch.joinToString { it.eventGuid }}"
}
logger.debug {
"CSEventScheduler#forwardEvents#batch - " +
"messageName : ${batch[0].messageName}"
"messageName : ${batch[0].messageName}"
}
logHealthEvent(
CSHealthEventDTO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package clickstream.internal.networklayer
import clickstream.api.CSInfo
import clickstream.config.CSNetworkConfig
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.internal.utils.CSCallback
import clickstream.logger.CSLogger
import com.gojek.clickstream.de.EventRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package clickstream.internal.networklayer
import clickstream.api.CSInfo
import clickstream.config.CSNetworkConfig
import clickstream.extension.isHealthEvent
import clickstream.health.CSTimeStampGenerator
import clickstream.health.constant.CSEventNamesConstant
import clickstream.health.constant.CSEventTypesConstant
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.health.model.CSHealthEventDTO
import clickstream.health.time.CSTimeStampGenerator
import clickstream.internal.analytics.CSErrorReasons
import clickstream.internal.utils.CSTimeStampMessageBuilder
import clickstream.logger.CSLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public class ClickStreamFunctionalTest {
info = csInfo,
config = createCSConfig(),
appLifeCycle = appLifecycle,
healthGateway = fakeHealthGateway
).setDispatcher(coroutineRule.testDispatcher).build()
).setDispatcher(coroutineRule.testDispatcher).setHealthGateway(fakeHealthGateway).build()
)

sut = ClickStream.getInstance()
Expand Down Expand Up @@ -98,9 +97,8 @@ public class ClickStreamFunctionalTest {
context = app,
info = csInfo,
config = createCSConfig(),
appLifeCycle = appLifecycle,
healthGateway = fakeHealthGateway
).setDispatcher(coroutineRule.testDispatcher).build()
appLifeCycle = appLifecycle
).setDispatcher(coroutineRule.testDispatcher).setHealthGateway(fakeHealthGateway).build()
)
sut = ClickStream.getInstance()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package clickstream.internal.eventprocessor.impl

import clickstream.api.CSMetaProvider
import clickstream.extension.protoName
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.internal.DefaultCSHealthEventFactory
import com.gojek.clickstream.internal.Health
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clickstream.config.CSEventSchedulerConfig
import clickstream.fake.FakeEventBatchDao
import clickstream.fake.defaultEventWrapperData
import clickstream.fake.fakeInfo
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.intermediate.CSHealthEventProcessor
import clickstream.health.intermediate.CSHealthEventRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clickstream.config.CSEventSchedulerConfig
import clickstream.fake.FakeEventBatchDao
import clickstream.fake.defaultEventWrapperData
import clickstream.fake.fakeInfo
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.identity.CSGuIdGenerator
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.internal.eventscheduler.impl.DefaultCSEventRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package clickstream.internal.networklayer

import clickstream.config.CSNetworkConfig
import clickstream.fake.fakeCSInfo
import clickstream.health.CSTimeStampGenerator
import clickstream.health.time.CSTimeStampGenerator
import clickstream.health.intermediate.CSHealthEventRepository
import clickstream.internal.utils.CSFlowStreamAdapterFactory
import clickstream.logger.CSLogLevel.OFF
Expand Down
2 changes: 1 addition & 1 deletion scripts/versioning.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ext {
gitVersionName = "0.2.36"
gitVersionName = "0.2.39"
}

0 comments on commit c6e4be0

Please sign in to comment.