FUS: send project id together with project collectors

This commit is contained in:
Svetlana.Zemlyanskaya
2018-09-27 16:38:54 +02:00
parent d5fb87d805
commit 27113381f4
6 changed files with 53 additions and 16 deletions
@@ -13,7 +13,7 @@ class FeatureUsageFileEventLoggerProvider : FeatureUsageEventLoggerProvider {
override fun createLogger(): FeatureUsageEventLogger {
val sessionId = UUID.randomUUID().toString().shortedUUID()
val build = ApplicationInfo.getInstance().build.asBuildNumber()
val logger = FeatureUsageFileEventLogger(sessionId, build, "-1", "4", FeatureUsageLogEventWriter())
val logger = FeatureUsageFileEventLogger(sessionId, build, "-1", "5", FeatureUsageLogEventWriter())
ApplicationManager.getApplication().addApplicationListener(object : ApplicationAdapter() {
override fun applicationExiting() {
@@ -41,10 +41,12 @@ public abstract class AbstractUsageTrigger<T extends FeatureUsagesCollector> imp
protected abstract FeatureUsagesCollector findCollector(@NotNull Class<? extends T> fusClass);
protected abstract Map<String, Object> createEventLogData(@Nullable FUSUsageContext context);
protected void doTrigger(@NotNull String usageCollectorId,
@NotNull String feature,
@Nullable FUSUsageContext context) {
FeatureUsageLogger.INSTANCE.log(usageCollectorId, feature, context != null ? context.getData() : Collections.emptyMap());
FeatureUsageLogger.INSTANCE.log(usageCollectorId, feature, createEventLogData(context));
SessionInfo sessionInfo = getOrCreateSessionInfo();
UsagesCollectorInfo collectorInfo = sessionInfo.getUsageCollectorInfo(usageCollectorId);
@@ -2,8 +2,12 @@
package com.intellij.internal.statistic.service.fus.collectors;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
import com.intellij.openapi.components.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@State(name = "FUSApplicationUsageTrigger",
storages = @Storage(value = UsageStatisticsPersistenceComponent.USAGE_STATISTICS_XML, roamingType = RoamingType.DISABLED))
@@ -20,6 +24,11 @@ final public class FUSApplicationUsageTrigger extends AbstractUsageTrigger<Appli
return null;
}
@Override
protected Map<String, Object> createEventLogData(@Nullable FUSUsageContext context) {
return StatisticsUtilKt.createData(null, context);
}
@Override
protected FUSession getFUSession() {
return FUSession.APPLICATION_SESSION;
@@ -1,9 +1,13 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.statistic.service.fus.collectors;
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@State(name = "FUSProjectUsageTrigger", storages = {
@Storage(value = StoragePathMacros.CACHE_FILE),
@@ -30,6 +34,11 @@ final public class FUSProjectUsageTrigger extends AbstractUsageTrigger<ProjectUs
return null;
}
@Override
protected Map<String, Object> createEventLogData(@Nullable FUSUsageContext context) {
return StatisticsUtilKt.createData(myProject, context);
}
@Override
protected FUSession getFUSession() {
return FUSession.create(getProject());
@@ -7,6 +7,7 @@ import com.intellij.internal.statistic.service.fus.beans.CollectorGroupDescripto
import com.intellij.internal.statistic.service.fus.beans.FSContent;
import com.intellij.internal.statistic.service.fus.beans.FSGroup;
import com.intellij.internal.statistic.service.fus.beans.FSSession;
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
@@ -15,7 +16,6 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -70,26 +70,27 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer {
synchronized (LOCK) {
Map<CollectorGroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new LinkedHashMap<>();
for (ApplicationUsagesCollector usagesCollector : ApplicationUsagesCollector.getExtensions(this)) {
collectUsages(usageDescriptors, usagesCollector, usagesCollector.getContext(), usagesCollector::getUsages, approvedGroups,
isStateCollector(usagesCollector));
collectUsages(null, usageDescriptors, usagesCollector, usagesCollector.getContext(), usagesCollector::getUsages,
approvedGroups, isStateCollector(usagesCollector));
}
return usageDescriptors;
}
}
private static void collectUsages(@NotNull Map<CollectorGroupDescriptor, Set<UsageDescriptor>> usageDescriptors,
private static void collectUsages(@Nullable Project project,
@NotNull Map<CollectorGroupDescriptor, Set<UsageDescriptor>> usageDescriptors,
@NotNull FeatureUsagesCollector usagesCollector,
@Nullable FUSUsageContext context,
@NotNull Factory<Set<UsageDescriptor>> usagesProducer,
@NotNull Set<String> approvedGroups, boolean isStateCollector) {
@NotNull Set<String> approvedGroups,
boolean isStateCollector) {
if (!usagesCollector.isValid()) return;
if (approvedGroups.contains(usagesCollector.getGroupId())) {
addUsageDescriptors(usagesCollector.getGroupId(), context, usageDescriptors, usagesProducer, isStateCollector);
addUsageDescriptors(project, usagesCollector.getGroupId(), context, usageDescriptors, usagesProducer, isStateCollector);
}
else if (ApplicationManagerEx.getApplicationEx().isInternal()) {
addUsageDescriptors(createDebugModeId(usagesCollector.getGroupId()), context, usageDescriptors, usagesProducer, isStateCollector);
addUsageDescriptors(project, createDebugModeId(usagesCollector.getGroupId()), context, usageDescriptors, usagesProducer, isStateCollector);
}
}
@@ -98,7 +99,7 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer {
return "internal." + groupId;
}
private static void addUsageDescriptors(@NotNull String groupDescriptor,
private static void addUsageDescriptors(@Nullable Project project, @NotNull String groupDescriptor,
@Nullable FUSUsageContext context,
@NotNull Map<CollectorGroupDescriptor, Set<UsageDescriptor>> allUsageDescriptors,
@NotNull Factory<Set<UsageDescriptor>> usagesProducer, boolean isStateCollector) {
@@ -106,7 +107,7 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer {
usages = usages.stream().filter(descriptor -> descriptor.getValue() > 0).collect(Collectors.toSet());
if (!usages.isEmpty()) {
if (isStateCollector) {
logUsagesAsStateEvents(groupDescriptor, context, usages);
logUsagesAsStateEvents(project, groupDescriptor, context, usages);
}
CollectorGroupDescriptor collectorGroupDescriptor = CollectorGroupDescriptor.create(groupDescriptor, context);
allUsageDescriptors.merge(collectorGroupDescriptor, usages, ContainerUtil::union);
@@ -117,11 +118,11 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer {
return !(usagesCollector instanceof FUStatisticsDifferenceSender);
}
private static void logUsagesAsStateEvents(@NotNull String groupDescriptor,
private static void logUsagesAsStateEvents(@Nullable Project project, @NotNull String groupDescriptor,
@Nullable FUSUsageContext context,
@NotNull Set<UsageDescriptor> usages) {
final FeatureUsageLogger logger = FeatureUsageLogger.INSTANCE;
final Map<String, ?> data = context != null ? context.getData() : Collections.emptyMap();
final Map<String, ?> data = StatisticsUtilKt.createData(project, context);
for (UsageDescriptor usage : usages) {
logger.logState(groupDescriptor, usage.getKey(), data);
}
@@ -132,8 +133,8 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer {
synchronized (LOCK) {
Map<CollectorGroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new LinkedHashMap<>();
for (ProjectUsagesCollector usagesCollector : ProjectUsagesCollector.getExtensions(this)) {
collectUsages(usageDescriptors, usagesCollector, usagesCollector.getContext(project), () -> usagesCollector.getUsages(project),
approvedGroups, isStateCollector(usagesCollector));
collectUsages(project, usageDescriptors, usagesCollector, usagesCollector.getContext(project),
() -> usagesCollector.getUsages(project), approvedGroups, isStateCollector(usagesCollector));
}
return usageDescriptors;
}
@@ -18,9 +18,11 @@ package com.intellij.internal.statistic.utils
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerMain
import com.intellij.internal.statistic.beans.UsageDescriptor
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.getProjectCacheFileName
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.ObjectIntHashMap
import gnu.trove.THashSet
import java.util.*
@@ -29,6 +31,20 @@ fun getProjectId(project: Project): String {
return project.getProjectCacheFileName(false, ".").hashCode().toString()
}
fun createData(project: Project?, context: FUSUsageContext?): Map<String, Any> {
if (project == null && context == null) return Collections.emptyMap()
val data = ContainerUtil.newHashMap<String, Any>()
if (context != null) {
data.putAll(context.data)
}
if (project != null) {
data["project"] = getProjectId(project)
}
return data
}
fun isDevelopedByJetBrains(pluginId: PluginId?): Boolean {
val plugin = PluginManager.getPlugin(pluginId)
return plugin == null || plugin.isBundled || PluginManagerMain.isDevelopedByJetBrains(plugin.vendor)