From 08e08e8603d1422a75ea108cb379e1165f2d9fb8 Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Thu, 3 Oct 2024 15:05:26 +0200 Subject: [PATCH] [git] IJPL-84816 Report clone depth in metrics GitOrigin-RevId: e9a20d79aadaac8c38786ff0aef2c30302ff2b06 --- .../platform-impl/api-dump-unreviewed.txt | 2 +- .../CloneableProjectsService.kt | 13 ++++++++---- .../cloneableProjects/VcsCloneCollector.kt | 21 ++++++++++++------- .../checkout/GitCheckoutProvider.java | 12 ++++++++++- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/platform/platform-impl/api-dump-unreviewed.txt b/platform/platform-impl/api-dump-unreviewed.txt index 4f36621f5d1e..1482fa9db585 100644 --- a/platform/platform-impl/api-dump-unreviewed.txt +++ b/platform/platform-impl/api-dump-unreviewed.txt @@ -12696,7 +12696,7 @@ e:com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjects com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService$CloneTask - a:run(com.intellij.openapi.progress.ProgressIndicator):com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService$CloneStatus - a:taskInfo():com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService$CloneTaskInfo -f:com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService$CloneTaskInfo +c:com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService$CloneTaskInfo - com.intellij.openapi.progress.TaskInfo - (java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String):V - f:getActionTitle():java.lang.String diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/CloneableProjectsService.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/CloneableProjectsService.kt index 3c1398cd5609..894c53f1f513 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/CloneableProjectsService.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/CloneableProjectsService.kt @@ -5,6 +5,7 @@ import com.intellij.CommonBundle import com.intellij.ide.RecentProjectMetaInfo import com.intellij.ide.RecentProjectsManager import com.intellij.ide.RecentProjectsManagerBase +import com.intellij.internal.statistic.eventLog.events.EventPair import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.components.Service.Level @@ -21,6 +22,7 @@ import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.ContainerUtil import com.intellij.util.messages.Topic import com.intellij.util.messages.Topic.AppLevel +import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.CalledInAny import org.jetbrains.annotations.Nls import org.jetbrains.annotations.SystemIndependent @@ -39,7 +41,7 @@ class CloneableProjectsService { ApplicationManager.getApplication().executeOnPooledThread { ProgressManager.getInstance().runProcess(Runnable { - val activity = VcsCloneCollector.cloneStarted() + val activity = VcsCloneCollector.cloneStarted(taskInfo) val cloneStatus: CloneStatus = try { cloneTask.run(progressIndicator) } @@ -50,7 +52,7 @@ class CloneableProjectsService { logger().error(exception) CloneStatus.FAILURE } - VcsCloneCollector.cloneFinished(activity, cloneStatus) + VcsCloneCollector.cloneFinished(activity, cloneStatus, taskInfo) when (cloneStatus) { CloneStatus.SUCCESS -> onSuccess(cloneableProject) @@ -171,7 +173,7 @@ class CloneableProjectsService { CANCEL } - class CloneTaskInfo( + open class CloneTaskInfo( private val title: @NlsContexts.ProgressTitle String, private val cancelTooltipText: @Nls String, val actionTitle: @Nls String, @@ -179,12 +181,15 @@ class CloneableProjectsService { val failedTitle: @Nls String, val canceledTitle: @Nls String, val stopTitle: @Nls String, - val stopDescription: @Nls String + val stopDescription: @Nls String, ) : TaskInfo { override fun getTitle(): String = title override fun getCancelText(): String = CommonBundle.getCancelButtonText() override fun getCancelTooltipText(): String = cancelTooltipText override fun isCancellable(): Boolean = true + + @ApiStatus.Internal + open fun getActivityData(): List> = emptyList() } data class CloneableProject( diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/VcsCloneCollector.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/VcsCloneCollector.kt index f289970aa76d..47cc40fb931d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/VcsCloneCollector.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/cloneableProjects/VcsCloneCollector.kt @@ -4,28 +4,35 @@ package com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects import com.intellij.internal.statistic.StructuredIdeActivity import com.intellij.internal.statistic.eventLog.EventLogGroup import com.intellij.internal.statistic.eventLog.events.EventFields -import com.intellij.internal.statistic.eventLog.events.EventPair import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService.CloneStatus +import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService.CloneTaskInfo internal object VcsCloneCollector : CounterUsagesCollector() { override fun getGroup(): EventLogGroup { return GROUP } - private val GROUP = EventLogGroup("vcs.clone", 1) - + private val GROUP = EventLogGroup("vcs.clone", 2) private val CLONE_STATUS_EVENT_FIELD = EventFields.Enum("status", CloneStatus::class.java) + + @JvmField + internal val SHALLOW_CLONE_DEPTH = EventFields.Int("status") + private val CLONE_ACTIVITY = GROUP.registerIdeActivity( activityName = "cloning", finishEventAdditionalFields = arrayOf(CLONE_STATUS_EVENT_FIELD) ) - fun cloneStarted(): StructuredIdeActivity { - return CLONE_ACTIVITY.started(null) + fun cloneStarted(cloneTaskInfo: CloneTaskInfo): StructuredIdeActivity { + return CLONE_ACTIVITY.started(null) { + cloneTaskInfo.getActivityData() + } } - fun cloneFinished(activity: StructuredIdeActivity, cloneStatus: CloneStatus) { - activity.finished { listOf(EventPair(CLONE_STATUS_EVENT_FIELD, cloneStatus)) } + fun cloneFinished(activity: StructuredIdeActivity, cloneStatus: CloneStatus, cloneTaskInfo: CloneTaskInfo) { + activity.finished { + cloneTaskInfo.getActivityData() + CLONE_STATUS_EVENT_FIELD.with(cloneStatus) + } } } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java b/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java index 4d0b0a454cae..f0ef17d22287 100644 --- a/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java +++ b/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java @@ -3,6 +3,7 @@ package git4idea.checkout; import com.intellij.dvcs.DvcsUtil; import com.intellij.dvcs.ui.DvcsBundle; +import com.intellij.internal.statistic.eventLog.events.EventPair; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -24,6 +25,7 @@ import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneablePro import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService.CloneStatus; import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService.CloneTask; import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.CloneableProjectsService.CloneTaskInfo; +import com.intellij.openapi.wm.impl.welcomeScreen.cloneableProjects.VcsCloneCollector; import com.intellij.util.containers.ContainerUtil; import git4idea.GitUtil; import git4idea.GitVcs; @@ -37,6 +39,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static git4idea.GitNotificationIdsHolder.CLONE_FAILED; @@ -109,7 +112,14 @@ public final class GitCheckoutProvider extends CheckoutProviderEx { DvcsBundle.message("clone.repository.failed"), DvcsBundle.message("clone.repository.canceled"), DvcsBundle.message("clone.stop.message.title"), - DvcsBundle.message("clone.stop.message.description", sourceRepositoryURL)); + DvcsBundle.message("clone.stop.message.description", sourceRepositoryURL)) { + @Override + public @NotNull List<@NotNull EventPair> getActivityData() { + if (shallowCloneOptions == null || shallowCloneOptions.getDepth() == null) return Collections.emptyList(); + int depth = shallowCloneOptions.getDepth(); + return List.of(VcsCloneCollector.SHALLOW_CLONE_DEPTH.with(depth)); + } + }; } @Override