Skip to content

Commit

Permalink
feat(analytics): add success, flakiness and run duration (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy authored Nov 15, 2023
1 parent 471073b commit fd7848d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit fd7848d

Please sign in to comment.