From 758628077f62c29e42153779fa493617dbb0c536 Mon Sep 17 00:00:00 2001 From: aleka Date: Tue, 24 Sep 2024 17:02:44 -0400 Subject: [PATCH] Add api state params to tracking (#672) --- build.gradle.kts | 2 +- .../state/v2/supervisor/NetworkHelper.kt | 13 +++++++++++++ .../state/v2/supervisor/NetworkSupervisor.kt | 3 +-- .../v2/supervisor/SubaccountTransactionTracker.kt | 2 +- v4_abacus.podspec | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3853f483b..ef118d7f1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.11.16" +version = "1.11.17" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt index 7edeee266..7864ebf5f 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt @@ -25,6 +25,7 @@ import exchange.dydx.abacus.utils.JsonEncoder import exchange.dydx.abacus.utils.ParsingHelper import exchange.dydx.abacus.utils.ServerTime import exchange.dydx.abacus.utils.UIImplementations +import exchange.dydx.abacus.utils.iMapOf import kollections.iListOf import kollections.iSetOf import kollections.toIMap @@ -555,4 +556,16 @@ class NetworkHelper( } } } + + internal fun apiStateParams(): IMap? { + val indexerTime = lastIndexerCallTime?.toEpochMilliseconds() + val validatorTime = lastValidatorCallTime?.toEpochMilliseconds() + val interval = indexerTime?.let { Clock.System.now().toEpochMilliseconds() - it } + return iMapOf( + "lastSuccessfulIndexerRPC" to indexerTime?.toDouble(), + "lastSuccessfulFullNodeRPC" to validatorTime?.toDouble(), + "elapsedTime" to interval?.toDouble(), + "validatorUrl" to validatorUrl, + ) as IMap? + } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt index 61b18ddb4..a21b9586e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt @@ -9,7 +9,6 @@ import exchange.dydx.abacus.utils.AnalyticsUtils import exchange.dydx.abacus.utils.IMap import exchange.dydx.abacus.utils.ParsingHelper import exchange.dydx.abacus.utils.filterNotNull -import exchange.dydx.abacus.utils.iMapOf import kollections.iListOf internal open class NetworkSupervisor( @@ -85,7 +84,7 @@ internal open class NetworkSupervisor( } internal fun tracking(eventName: String, params: IMap?) { - val requiredParams = helper.validatorUrl?.let { iMapOf("validatorUrl" to it) } ?: iMapOf() + val requiredParams = helper.apiStateParams() val mergedParams = params?.let { ParsingHelper.merge(params.filterNotNull(), requiredParams) } ?: requiredParams val paramsAsString = helper.jsonEncoder.encode(mergedParams) helper.ioImplementations.threading?.async(ThreadingType.main) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionTracker.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionTracker.kt index 367d7cdc0..769ee55ba 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionTracker.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionTracker.kt @@ -47,7 +47,7 @@ internal class SubaccountTransactionTracker( } override fun tracking(eventName: String, params: IMap?) { - val requiredParams = helper.validatorUrl?.let { iMapOf("validatorUrl" to it) } ?: iMapOf() + val requiredParams = helper.apiStateParams() val mergedParams = params?.let { ParsingHelper.merge(params.filterNotNull(), requiredParams) } ?: requiredParams diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 7ce4450df..1e475ac89 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.11.16' + spec.version = '1.11.17' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''