Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): add success, flakiness and run duration #861

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
) : 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 @@
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