All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hackle.sdk.internal.monitoring.metrics.DecisionMetrics.kt Maven / Gradle / Ivy

The newest version!
package io.hackle.sdk.internal.monitoring.metrics

import io.hackle.sdk.common.decision.Decision
import io.hackle.sdk.common.decision.FeatureFlagDecision
import io.hackle.sdk.common.decision.RemoteConfigDecision
import io.hackle.sdk.core.internal.metrics.Metrics
import io.hackle.sdk.core.internal.metrics.Timer

internal object DecisionMetrics {

    fun experiment(sample: Timer.Sample, key: Long, decision: Decision) {
        val tags = hashMapOf(
            "key" to key.toString(),
            "variation" to decision.variation.name,
            "reason" to decision.reason.name
        )
        val timer = Metrics.timer("experiment.decision", tags)
        sample.stop(timer)
    }

    fun featureFlag(sample: Timer.Sample, key: Long, decision: FeatureFlagDecision) {
        val tags = hashMapOf(
            "key" to key.toString(),
            "on" to decision.isOn.toString(),
            "reason" to decision.reason.name
        )
        val timer = Metrics.timer("feature.flag.decision", tags)
        sample.stop(timer)
    }

    fun remoteConfig(sample: Timer.Sample, key: String, decision: RemoteConfigDecision<*>) {
        val tags = hashMapOf(
            "key" to key,
            "reason" to decision.reason.name
        )
        val timer = Metrics.timer("remote.config.decision", tags)
        sample.stop(timer)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy