Skip to content

Commit

Permalink
feat(analytics): add success, flakiness and run duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Nov 14, 2023
1 parent 471073b commit 7272da6
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,

Check warning on line 20 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/Event.kt#L17-L20

Added lines #L17 - L20 were not covered by tests
) : 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))

Check warning on line 41 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt#L41

Added line #L41 was not covered by tests

is Event.Executed -> {
setOf(
Metric(name = "testing.duration", value = event.seconds, tags = tags),
Metric(name = "testing.flakiness", value = event.flakinessSeconds, tags = tags),

Check warning on line 46 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt#L44-L46

Added lines #L44 - L46 were not covered by tests
Metric(name = "testing.result", value = if (event.success) 1 else 0, tags = tags),
Metric(name = "testing.duration.run", value = event.durationSeconds, tags = tags),

Check warning on line 48 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt#L48

Added line #L48 was not covered by tests
)
}

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))

Check warning on line 53 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt#L53

Added line #L53 was not covered by tests
}
}.joinToString(separator = ",") { it.toJson() }
}.flatten().joinToString(separator = ",") { it.toJson() }

Check warning on line 55 in analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt

View check run for this annotation

Codecov / codecov/patch

analytics/usage/src/main/kotlin/com/malinskiy/marathon/usageanalytics/tracker/GrafanaCloud.kt#L55

Added line #L55 was not covered by tests
)
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 7272da6

Please sign in to comment.