From fd7848d85f9c0ef4a14b221fa42092919f97a1a4 Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Wed, 15 Nov 2023 12:20:39 +1000 Subject: [PATCH] feat(analytics): add success, flakiness and run duration (#861) --- .../marathon/usageanalytics/Event.kt | 5 ++++- .../usageanalytics/tracker/GrafanaCloud.kt | 20 ++++++++++++++----- .../marathon/report/bill/BillingReporter.kt | 8 +++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt b/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt index 3fa6304d9..092a0cef2 100644 --- a/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt +++ b/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt @@ -14,6 +14,9 @@ sealed class Event { ) : Event() data class Executed( - val seconds: Long + val seconds: Long, + val success: Boolean, + val flakinessSeconds: Long, + val durationSeconds: Long, ) : Event() } diff --git a/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt b/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt index 1288acd20..5988e557d 100644 --- a/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt +++ b/analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt @@ -37,12 +37,22 @@ class GrafanaCloud : UsageTracker { append( events.map { event -> when (event) { - is Event.Devices -> Metric(name = "testing.device", value = event.total, tags = tags) - is Event.Executed -> Metric(name = "testing.duration", value = event.seconds, tags = tags) - is Event.TestsTotal -> Metric(name = "testing.test", value = event.total, tags = tags) - is Event.TestsRun -> Metric(name = "testing.executed", value = event.value, tags = tags) + is Event.Devices -> + setOf(Metric(name = "testing.device", value = event.total, tags = tags)) + + is Event.Executed -> { + setOf( + Metric(name = "testing.duration", value = event.seconds, tags = tags), + Metric(name = "testing.flakiness", value = event.flakinessSeconds, tags = tags), + Metric(name = "testing.result", value = if (event.success) 1 else 0, tags = tags), + Metric(name = "testing.duration.run", value = event.durationSeconds, tags = tags), + ) + } + + is Event.TestsTotal -> setOf(Metric(name = "testing.test", value = event.total, tags = tags)) + is Event.TestsRun -> setOf(Metric(name = "testing.executed", value = event.value, tags = tags)) } - }.joinToString(separator = ",") { it.toJson() } + }.flatten().joinToString(separator = ",") { it.toJson() } ) append("]") }.toString() diff --git a/core/src/main/kotlin/com/malinskiy/marathon/report/bill/BillingReporter.kt b/core/src/main/kotlin/com/malinskiy/marathon/report/bill/BillingReporter.kt index 2443f14bf..46481f8aa 100644 --- a/core/src/main/kotlin/com/malinskiy/marathon/report/bill/BillingReporter.kt +++ b/core/src/main/kotlin/com/malinskiy/marathon/report/bill/BillingReporter.kt @@ -61,7 +61,13 @@ internal class BillingReporter( } usageTracker.trackEvent(Event.Devices(bills.size)) - usageTracker.trackEvent(Event.Executed(seconds = bills.sumOf { it.duration } / 1000)) + val result = executionReport.summary.pools.map { it.failed.size == 0 }.reduce { acc, b -> acc && b } + val flakiness = executionReport.summary.pools.sumOf { it.rawDurationMillis - it.durationMillis / 1000 } + val durationSeconds = ((Instant.now().toEpochMilli() - defaultStart.toEpochMilli()) / 1000) + usageTracker.trackEvent(Event.Executed(seconds = bills.sumOf { it.duration } / 1000, + success = result, + flakinessSeconds = flakiness, + durationSeconds = durationSeconds)) } }