IDEA-345401 Report cancelled health checks

GitOrigin-RevId: 2380fa4f35433f12b3a7186f4a02654b48949c52
This commit is contained in:
Liudmila Kornilova
2024-03-21 21:38:54 +00:00
committed by intellij-monorepo-bot
parent 56bf3f8534
commit 9606d15f40
2 changed files with 39 additions and 4 deletions
@@ -11,7 +11,7 @@ import com.intellij.openapi.project.Project
*/
internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollector() {
private val GROUP = EventLogGroup("indexable.files.filter",
7,
8,
"FUS",
"Collects statistics of ProjectIndexableFilesFilterHealthCheck. " +
"See more here: https://youtrack.jetbrains.com/articles/IJPL-A-300/indexable.files.filter")
@@ -22,6 +22,7 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto
private val attemptNumberInProjectField = EventFields.Int("attempt_number_in_project", "Health check attempt number in a given project. First is 1.")
private val successfulAttemptNumberInProjectField = EventFields.Int("successful_attempt_number_in_project", "Finished (not-cancelled) health check attempt number in a given project. First is 1.")
private val durationMsFiled = EventFields.Int("duration_ms", "Health check duration in milliseconds")
private val cancelledAttemptNumberInProjectField = EventFields.Int("cancelled_attempt_number_in_project", "Cancelled health check attempt number in a given project. First is 1.")
private val nonIndexableFilesInFilterField = EventFields.Int("non_indexable_files_in_filter_count")
private val indexableFilesNotInFilterField = EventFields.Int("indexable_files_not_in_filter_count")
@@ -40,7 +41,16 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto
"indexable_files_filter_health_check_started",
filterNameField,
attemptNumberInProjectField,
description = "Even which happens every time health check is started."
description = "Event which happens every time health check is started."
)
private val indexableFilesFilterHealthCheckCancelled = GROUP.registerVarargEvent(
"indexable_files_filter_health_check_cancelled",
description = "Event which happens every time health check is cancelled e.g. because scanning was in progress.",
filterNameField,
attemptNumberInProjectField,
cancelledAttemptNumberInProjectField,
durationMsFiled,
)
fun reportIndexableFilesFilterHealthcheckStarted(project: Project,
@@ -72,6 +82,20 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto
)
}
fun reportIndexableFilesFilterHealthcheckCancelled(project: Project,
filter: ProjectIndexableFilesFilter,
attemptNumber: Int,
cancelledAttemptNumber: Int,
durationMs: Int) {
indexableFilesFilterHealthCheckCancelled.log(
project,
filterNameField.with(getFilterName(filter)),
attemptNumberInProjectField.with(attemptNumber),
cancelledAttemptNumberInProjectField.with(cancelledAttemptNumber),
durationMsFiled.with(durationMs),
)
}
private fun getFilterName(filter: ProjectIndexableFilesFilter): String? {
return when (filter) {
is CachingProjectIndexableFilesFilter -> "caching"
@@ -59,6 +59,7 @@ private class ProjectIndexableFilesFilterHealthCheckStarter : ProjectActivity {
class ProjectIndexableFilesFilterHealthCheck(private val project: Project, private val coroutineScope: CoroutineScope) {
private val isRunning = AtomicBoolean()
private val attemptsCount = AtomicInteger()
private val cancelledAttemptsCount = AtomicInteger()
private val successfulAttemptsCount = AtomicInteger()
fun launchHealthCheck() {
@@ -99,9 +100,19 @@ class ProjectIndexableFilesFilterHealthCheck(private val project: Project, priva
val startTime = System.currentTimeMillis()
Observation.awaitConfiguration(project) // wait for project import IDEA-348501
val (nonIndexableFilesInFilter, indexableFilesNotInFilter) = smartReadAction(project) {
val res = smartReadAction(project) {
runHealthCheck(project, filter)
} ?: return
}
if (res == null) {
IndexableFilesFilterHealthCheckCollector.reportIndexableFilesFilterHealthcheckCancelled(
project,
filter,
attemptNumber,
cancelledAttemptsCount.incrementAndGet(),
(System.currentTimeMillis() - startTime).toInt())
return
}
val (nonIndexableFilesInFilter, indexableFilesNotInFilter) = res
nonIndexableFilesInFilter.fix(filter)
indexableFilesNotInFilter.fix(filter)