FUS: load global enums and regexps in test whitelist

GitOrigin-RevId: 4e8a18189804dac180beedda28a28c1b8268f2b4
This commit is contained in:
Svetlana.Zemlyanskaya
2019-08-01 20:05:37 +03:00
committed by intellij-monorepo-bot
parent 6d45865b27
commit d38e148155
2 changed files with 49 additions and 5 deletions
@@ -86,7 +86,7 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi
}
@NotNull
public static WLGroups loadTestWhitelist(@NotNull EventLogTestWhitelistPersistence persistence) {
public static WLGroups loadTestWhitelist(@NotNull BaseEventLogWhitelistPersistence persistence) {
final String existing = persistence.getCachedWhitelist();
if (StringUtil.isNotEmpty(existing)) {
final WLGroups loaded = FUStatisticsWhiteListGroupsService.parseWhiteListContent(existing);
@@ -1,9 +1,13 @@
// Copyright 2000-2019 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.eventLog.whitelist;
import com.intellij.internal.statistic.eventLog.EventLogConfiguration;
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogTestWhitelistPersistence;
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence;
import com.intellij.internal.statistic.eventLog.validator.rules.beans.WhiteListGroupRules;
import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService;
import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService.WLGroups;
import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService.WLRule;
import com.intellij.openapi.util.BuildNumber;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,6 +15,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
public class WhitelistTestGroupStorage extends BaseWhitelistStorage {
private static final ConcurrentMap<String, WhitelistTestGroupStorage> ourTestInstances = ContainerUtil.newConcurrentMap();
@@ -20,6 +25,8 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage {
@NotNull
private final EventLogTestWhitelistPersistence myTestWhitelistPersistence;
@NotNull
private final EventLogWhitelistPersistence myWhitelistPersistence;
@NotNull
private final String myRecorderId;
public static WhitelistTestGroupStorage getInstance(@NotNull String recorderId) {
@@ -31,6 +38,7 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage {
private WhitelistTestGroupStorage(@NotNull String recorderId) {
myTestWhitelistPersistence = new EventLogTestWhitelistPersistence(recorderId);
myWhitelistPersistence = new EventLogWhitelistPersistence(recorderId);
updateValidators();
myRecorderId = recorderId;
}
@@ -49,15 +57,51 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage {
synchronized (myLock) {
eventsValidators.clear();
isWhiteListInitialized.set(false);
FUStatisticsWhiteListGroupsService.WLGroups groups =
EventLogTestWhitelistPersistence.loadTestWhitelist(myTestWhitelistPersistence);
final Map<String, WhiteListGroupRules> result = createValidators(groups);
final WLGroups productionGroups = EventLogTestWhitelistPersistence.loadTestWhitelist(myWhitelistPersistence);
final WLGroups testGroups = EventLogTestWhitelistPersistence.loadTestWhitelist(myTestWhitelistPersistence);
final Map<String, WhiteListGroupRules> result = createValidators(testGroups, productionGroups);
eventsValidators.putAll(result);
isWhiteListInitialized.set(true);
}
}
@NotNull
protected Map<String, WhiteListGroupRules> createValidators(@NotNull WLGroups groups, @NotNull WLGroups productionGroups) {
final WLRule rules = merge(groups.rules, productionGroups.rules);
final BuildNumber buildNumber = BuildNumber.fromString(EventLogConfiguration.INSTANCE.getBuild());
return groups.groups.stream().
filter(group -> group.accepts(buildNumber)).
collect(Collectors.toMap(group -> group.id, group -> createRules(group, rules)));
}
@Nullable
private static WLRule merge(@Nullable WLRule testRules, @Nullable WLRule productionTestRules) {
if (testRules == null) return productionTestRules;
if (productionTestRules == null) return testRules;
final WLRule rule = new WLRule();
copyRules(rule, productionTestRules);
copyRules(rule, testRules);
return rule;
}
private static void copyRules(@NotNull WLRule to, @NotNull WLRule from) {
if (to.enums == null) {
to.enums = ContainerUtil.newHashMap();
}
if (to.regexps == null) {
to.regexps = ContainerUtil.newHashMap();
}
if (from.enums != null) {
to.enums.putAll(from.enums);
}
if (from.regexps != null) {
to.regexps.putAll(from.regexps);
}
}
public void addGroupWithCustomRules(@NotNull String groupId, @NotNull String rules) throws IOException {
EventLogTestWhitelistPersistence.addGroupWithCustomRules(myRecorderId, groupId, rules);
updateValidators();