From a209cdf062787f68215f447730ec02b4515fcfb8 Mon Sep 17 00:00:00 2001 From: Anastasia Ivanova Date: Mon, 15 Jun 2020 20:36:42 +0700 Subject: [PATCH] FUS-726 Add unique id in `settings` group events GitOrigin-RevId: 4efe3c7713d0a754e9d7139794c2103c31f06980 --- .../eventLog/FeatureUsageSettingsEvents.kt | 16 +++++----- .../FeatureUsageSettingsEventsTest.kt | 29 ++++++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/platform/configuration-store-impl/src/statistic/eventLog/FeatureUsageSettingsEvents.kt b/platform/configuration-store-impl/src/statistic/eventLog/FeatureUsageSettingsEvents.kt index 9f5c58d9a811..07b8fa6905c5 100644 --- a/platform/configuration-store-impl/src/statistic/eventLog/FeatureUsageSettingsEvents.kt +++ b/platform/configuration-store-impl/src/statistic/eventLog/FeatureUsageSettingsEvents.kt @@ -20,8 +20,9 @@ import org.jdom.Element import java.util.concurrent.atomic.AtomicInteger private val LOG = Logger.getInstance("com.intellij.configurationStore.statistic.eventLog.FeatureUsageSettingsEventPrinter") -private val GROUP = EventLogGroup("settings", 7) +private val GROUP = EventLogGroup("settings", 8) private const val CHANGES_GROUP = "settings.changes" +private const val ID_FIELD = "id" private val recordedComponents: MutableSet = ContainerUtil.newConcurrentSet() private val recordedOptionNames: MutableSet = ContainerUtil.newConcurrentSet() @@ -75,7 +76,7 @@ open class FeatureUsageSettingsEventPrinter(private val recordDefault: Boolean) val pluginInfo = getPluginInfo(clazz) if (pluginInfo.isDevelopedByJetBrains()) { recordedComponents.add(componentName) - logConfig(GROUP, "invoked", createComponentData(project, componentName, pluginInfo)) + logConfig(GROUP, "invoked", createComponentData(project, componentName, pluginInfo), counter.incrementAndGet()) } } } @@ -99,21 +100,22 @@ open class FeatureUsageSettingsEventPrinter(private val recordDefault: Boolean) fun logConfigurationState(componentName: String, state: Any?, project: Project?) { val (optionsValues, pluginInfo) = valuesExtractor.extract(project, componentName, state) ?: return val eventId = if (recordDefault) "option" else "not.default" + val id = counter.incrementAndGet() for (data in optionsValues) { - logConfig(GROUP, eventId, data) + logConfig(GROUP, eventId, data, id) } if (!recordDefault) { - logConfig(GROUP, "invoked", createComponentData(project, componentName, pluginInfo)) + logConfig(GROUP, "invoked", createComponentData(project, componentName, pluginInfo), id) } } - protected open fun logConfig(group: EventLogGroup, eventId: String, data: FeatureUsageData) { - FeatureUsageLogger.logState(group, eventId, data.build()) + protected open fun logConfig(group: EventLogGroup, eventId: String, data: FeatureUsageData, id: Int) { + FeatureUsageLogger.logState(group, eventId, data.addData(ID_FIELD, id).build()) } protected open fun logSettingsChanged(eventId: String, data: FeatureUsageData, id: Int) { - FUCounterUsageLogger.getInstance().logEvent(CHANGES_GROUP, eventId, data.addData("id", id)) + FUCounterUsageLogger.getInstance().logEvent(CHANGES_GROUP, eventId, data.addData(ID_FIELD, id)) } companion object { diff --git a/platform/configuration-store-impl/testSrc/statistics/eventLog/FeatureUsageSettingsEventsTest.kt b/platform/configuration-store-impl/testSrc/statistics/eventLog/FeatureUsageSettingsEventsTest.kt index adcbdbc53a26..7e5bb5350d51 100644 --- a/platform/configuration-store-impl/testSrc/statistics/eventLog/FeatureUsageSettingsEventsTest.kt +++ b/platform/configuration-store-impl/testSrc/statistics/eventLog/FeatureUsageSettingsEventsTest.kt @@ -501,6 +501,18 @@ class FeatureUsageSettingsEventsTest { Assert.assertEquals(1, printer.result.size) } + @Test + fun `report invoked and options events with the same id`() { + val component = TestComponent() + component.loadState(ComponentState(bool = true)) + val printer = TestFeatureUsageSettingsEventsPrinter(recordDefault = false) + printer.logConfigurationState(getStateSpec(component).name, component.state, null) + + val invokedEvent = printer.getInvokedEvent() + val optionEvent = printer.getOptionByName("boolOption") + Assert.assertEquals(invokedEvent.id, optionEvent.id) + } + private fun assertDefaultWithoutDefaultRecording(printer: TestFeatureUsageSettingsEventsPrinter, withProject: Boolean, defaultProject: Boolean) { @@ -526,7 +538,8 @@ class FeatureUsageSettingsEventsTest { defaultProject: Boolean) { assertThat(event.group.id).isEqualTo("settings") assertThat(event.group.version > 0).isTrue() - assertThat(event.id).isEqualTo(if (withDefaultRecorded) "option" else "not.default") + assertThat(event.eventId).isEqualTo(if (withDefaultRecorded) "option" else "not.default") + assertThat(event.id).isNotNull() var size = 3 if (value != null) size++ @@ -569,7 +582,8 @@ class FeatureUsageSettingsEventsTest { defaultProject: Boolean) { assertThat(event.group.id).isEqualTo("settings") assertThat(event.group.version).isGreaterThan(0) - assertThat(event.id).isEqualTo("option") + assertThat(event.eventId).isEqualTo("option") + assertThat(event.id).isNotNull() var size = 5 if (withProject) size++ @@ -596,7 +610,8 @@ class FeatureUsageSettingsEventsTest { private fun assertInvokedRecorded(event: LoggedComponentStateEvents, withProject: Boolean, defaultProject: Boolean) { assertThat(event.group.id).isEqualTo("settings") assertThat(event.group.version).isGreaterThan(0) - assertThat(event.id).isEqualTo("invoked") + assertThat(event.eventId).isEqualTo("invoked") + assertThat(event.id).isNotNull() var size = 1 if (withProject) size++ @@ -619,8 +634,8 @@ class FeatureUsageSettingsEventsTest { private class TestFeatureUsageSettingsEventsPrinter(recordDefault: Boolean) : FeatureUsageSettingsEventPrinter(recordDefault) { val result: MutableList = ArrayList() - override fun logConfig(group: EventLogGroup, eventId: String, data: FeatureUsageData) { - result.add(LoggedComponentStateEvents(group, eventId, data.build())) + override fun logConfig(group: EventLogGroup, eventId: String, data: FeatureUsageData, id: Int) { + result.add(LoggedComponentStateEvents(group, eventId, data.build(), id)) } fun getOptionByName(name: String): LoggedComponentStateEvents { @@ -634,7 +649,7 @@ class FeatureUsageSettingsEventsTest { fun getInvokedEvent(): LoggedComponentStateEvents { for (event in result) { - if (event.id == "invoked") { + if (event.eventId == "invoked") { return event } } @@ -650,7 +665,7 @@ class FeatureUsageSettingsEventsTest { } } - private class LoggedComponentStateEvents(val group: EventLogGroup, val id: String, val data: Map) + private class LoggedComponentStateEvents(val group: EventLogGroup, val eventId: String, val data: Map, val id: Int) @State(name = "MyTestComponent", reportStatistic = true) private class TestComponent : PersistentStateComponent {