mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FUS: update file name for cached statistics metadata (IDEA-243753)
GitOrigin-RevId: 4f012be048c1c67e4cb2b196ca79b2b7e67440ec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1ab76a3b95
commit
456949b71e
+1
-1
@@ -52,7 +52,7 @@ class TestWhitelistStorage(
|
||||
}
|
||||
|
||||
private class TestEventLogWhitelistPersistence(recorderId: String, private var content: String?, private var modified: Long) : EventLogWhitelistPersistence(recorderId) {
|
||||
override fun getCachedWhitelist(): String? = content
|
||||
override fun getCachedMetadata(): String? = content
|
||||
|
||||
override fun cacheWhiteList(gsonWhiteListContent: String, lastModified: Long) {
|
||||
content = gsonWhiteListContent
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ internal class TestSensitiveDataValidator(storage: WhitelistStorage) : Sensitive
|
||||
}
|
||||
|
||||
class TestEventLogWhitelistPersistence(private val myContent: String) : EventLogWhitelistPersistence("TEST") {
|
||||
override fun getCachedWhitelist(): String? {
|
||||
override fun getCachedMetadata(): String? {
|
||||
return myContent
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,6 +8,7 @@ import com.intellij.internal.statistic.StatisticsDevKitUtil
|
||||
import com.intellij.internal.statistic.StatisticsDevKitUtil.showNotification
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.BaseEventLogWhitelistPersistence
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence.EVENTS_SCHEME_FILE
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistSettingsPersistence
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
@@ -29,7 +30,7 @@ class OpenWhitelistFileAction(private val myRecorderId: String = StatisticsDevKi
|
||||
File(settings.customPath)
|
||||
}
|
||||
else {
|
||||
BaseEventLogWhitelistPersistence.getDefaultWhitelistFile(myRecorderId, EventLogWhitelistPersistence.WHITE_LIST_DATA_FILE)
|
||||
BaseEventLogWhitelistPersistence.getDefaultMetadataFile(myRecorderId, EVENTS_SCHEME_FILE, null)
|
||||
}
|
||||
|
||||
openFileInEditor(file, project)
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
package com.intellij.internal.statistic.actions
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.getEventLogProviders
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.BaseEventLogWhitelistPersistence.getDefaultWhitelistFile
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence.WHITE_LIST_DATA_FILE
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.BaseEventLogWhitelistPersistence.getDefaultMetadataFile
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence.EVENTS_SCHEME_FILE
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistSettingsPersistence
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
|
||||
import com.intellij.openapi.ui.ComboBox
|
||||
@@ -112,7 +112,7 @@ class WhitelistConfigurationModel {
|
||||
}
|
||||
|
||||
class WhitelistPathSettings(recorderId: String) {
|
||||
private val defaultPath: String = getDefaultWhitelistFile(recorderId, WHITE_LIST_DATA_FILE).absolutePath
|
||||
private val defaultPath: String = getDefaultMetadataFile(recorderId, EVENTS_SCHEME_FILE, null).absolutePath
|
||||
var customPath: String? = null
|
||||
var useCustomPath = false
|
||||
|
||||
|
||||
+9
@@ -2,6 +2,7 @@
|
||||
package com.intellij.internal.statistic.eventLog;
|
||||
|
||||
import com.intellij.concurrency.JobScheduler;
|
||||
import com.intellij.internal.statistic.eventLog.validator.persistence.BaseEventLogWhitelistPersistence;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUStatisticsPersistence;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -19,10 +20,18 @@ public final class StatisticsEventLogMigration {
|
||||
JobScheduler.getScheduler().schedule(() -> {
|
||||
moveLogsToNewFolder();
|
||||
|
||||
clearDeprecatedMetadataFolder();
|
||||
FUStatisticsPersistence.clearLegacyStates();
|
||||
}, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private static void clearDeprecatedMetadataFolder() {
|
||||
Path deprecated = BaseEventLogWhitelistPersistence.getDeprecatedMetadataDir();
|
||||
if (Files.exists(deprecated)) {
|
||||
deleteDir(deprecated);
|
||||
}
|
||||
}
|
||||
|
||||
private static void moveLogsToNewFolder() {
|
||||
Path newEventLogDir = EventLogConfiguration.INSTANCE.getEventLogDataPath().resolve("logs");
|
||||
|
||||
|
||||
+47
-9
@@ -2,6 +2,8 @@
|
||||
package com.intellij.internal.statistic.eventLog.validator.persistence;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -11,19 +13,55 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
abstract public class BaseEventLogWhitelistPersistence {
|
||||
public static final String FUS_WHITELIST_PATH = "event-log-whitelist";
|
||||
private static final Logger LOG = Logger.getInstance(BaseEventLogWhitelistPersistence.class);
|
||||
|
||||
public static final String DEPRECATED_FUS_METADATA_DIR = "event-log-whitelist";
|
||||
public static final String FUS_METADATA_DIR = "event-log-metadata";
|
||||
|
||||
@Nullable
|
||||
public abstract String getCachedWhitelist();
|
||||
public abstract String getCachedMetadata();
|
||||
|
||||
public static File getDefaultMetadataFile(@NotNull String recorderId,
|
||||
@NotNull String fileName,
|
||||
@Nullable String deprecatedFileName) throws IOException {
|
||||
File file = getMetadataByDir(FUS_METADATA_DIR, recorderId, fileName);
|
||||
if (!file.exists() && StringUtil.isNotEmpty(deprecatedFileName)) {
|
||||
File deprecated = getMetadataByDir(DEPRECATED_FUS_METADATA_DIR, recorderId, deprecatedFileName);
|
||||
if (deprecated.exists()) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Moving deprecated metadata file to new directory: " + fileName);
|
||||
}
|
||||
|
||||
if (!FileUtil.createParentDirs(file)) {
|
||||
LOG.info("Cannot create directories for event log metadata");
|
||||
return file;
|
||||
}
|
||||
|
||||
FileUtil.copy(deprecated, file);
|
||||
if (!FileUtil.delete(deprecated)) {
|
||||
LOG.info("Failed deleting deprecated metadata file");
|
||||
}
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File getDefaultWhitelistFile(@NotNull String recorderId, @NotNull String whitelistFileName) throws IOException {
|
||||
Path configPath = PathManager.getConfigDir();
|
||||
Path whitelistDir = configPath
|
||||
.resolve(FUS_WHITELIST_PATH)
|
||||
.resolve(StringUtil.toLowerCase(recorderId));
|
||||
return whitelistDir.
|
||||
resolve(whitelistFileName).
|
||||
public static Path getDeprecatedMetadataDir() {
|
||||
return getMetadataConfigRoot(DEPRECATED_FUS_METADATA_DIR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File getMetadataByDir(@NotNull String dir, @NotNull String recorderId, @NotNull String fileName) throws IOException {
|
||||
Path metadataDir = getMetadataConfigRoot(dir);
|
||||
return metadataDir.
|
||||
resolve(StringUtil.toLowerCase(recorderId)).
|
||||
resolve(fileName).
|
||||
toFile().getCanonicalFile();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Path getMetadataConfigRoot(@NotNull String dir) {
|
||||
return PathManager.getConfigDir().resolve(dir);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -26,7 +26,10 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi
|
||||
Logger.getInstance(EventLogTestWhitelistPersistence.class);
|
||||
|
||||
public static final String TEST_RULE = "{util#fus_test_mode}";
|
||||
public static final String TEST_WHITE_LIST_DATA_FILE = "test-white-list.json";
|
||||
|
||||
private static final String DEPRECATED_TEST_EVENTS_SCHEME_FILE = "test-white-list.json";
|
||||
private static final String TEST_EVENTS_SCHEME_FILE = "test-events-scheme.json";
|
||||
|
||||
@NotNull
|
||||
private final String myRecorderId;
|
||||
|
||||
@@ -36,7 +39,7 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCachedWhitelist() {
|
||||
public String getCachedMetadata() {
|
||||
try {
|
||||
final File file = getWhitelistFile();
|
||||
if (file.exists()) {
|
||||
@@ -96,7 +99,7 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi
|
||||
|
||||
@NotNull
|
||||
public static WLGroups loadTestWhitelist(@NotNull BaseEventLogWhitelistPersistence persistence) {
|
||||
final String existing = persistence.getCachedWhitelist();
|
||||
final String existing = persistence.getCachedMetadata();
|
||||
if (StringUtil.isNotEmpty(existing)) {
|
||||
try {
|
||||
return FUStatisticsWhiteListGroupsService.parseWhiteListContent(existing);
|
||||
@@ -130,7 +133,7 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi
|
||||
|
||||
@NotNull
|
||||
public File getWhitelistFile() throws IOException {
|
||||
return getDefaultWhitelistFile(myRecorderId, TEST_WHITE_LIST_DATA_FILE);
|
||||
return getDefaultMetadataFile(myRecorderId, TEST_EVENTS_SCHEME_FILE, DEPRECATED_TEST_EVENTS_SCHEME_FILE);
|
||||
}
|
||||
|
||||
public void updateTestGroups(@NotNull List<LocalWhitelistGroup> groups) throws IOException {
|
||||
|
||||
+12
-9
@@ -13,9 +13,10 @@ import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersistence {
|
||||
public static final String WHITE_LIST_DATA_FILE = "white-list.json";
|
||||
private static final Logger LOG =
|
||||
Logger.getInstance(EventLogWhitelistPersistence.class);
|
||||
private static final String DEPRECATED_EVENTS_SCHEME_FILE = "white-list.json";
|
||||
public static final String EVENTS_SCHEME_FILE = "events-scheme.json";
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(EventLogWhitelistPersistence.class);
|
||||
@NotNull
|
||||
private final String myRecorderId;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersisten
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCachedWhitelist() {
|
||||
public String getCachedMetadata() {
|
||||
try {
|
||||
File file = getWhitelistFile();
|
||||
if (file.exists()) return FileUtil.loadFile(file);
|
||||
@@ -44,7 +45,9 @@ public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersisten
|
||||
}
|
||||
else {
|
||||
File file = getDefaultFile();
|
||||
if (!file.exists()) initBuiltinWhiteList(file);
|
||||
if (!file.exists()) {
|
||||
initBuiltinMetadata(file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
@@ -60,7 +63,7 @@ public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersisten
|
||||
}
|
||||
}
|
||||
|
||||
private void initBuiltinWhiteList(File file) throws IOException {
|
||||
private void initBuiltinMetadata(File file) throws IOException {
|
||||
try (InputStream stream = getClass().getClassLoader().getResourceAsStream(builtinWhiteListPath())) {
|
||||
if (stream == null) return;
|
||||
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
|
||||
@@ -71,7 +74,7 @@ public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersisten
|
||||
}
|
||||
|
||||
private String builtinWhiteListPath() {
|
||||
return "resources/" + FUS_WHITELIST_PATH + "/" + myRecorderId + "/" + WHITE_LIST_DATA_FILE;
|
||||
return "resources/" + DEPRECATED_FUS_METADATA_DIR + "/" + myRecorderId + "/" + DEPRECATED_EVENTS_SCHEME_FILE;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
@@ -79,7 +82,7 @@ public class EventLogWhitelistPersistence extends BaseEventLogWhitelistPersisten
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private File getDefaultFile() throws IOException {
|
||||
return getDefaultWhitelistFile(myRecorderId, WHITE_LIST_DATA_FILE);
|
||||
public File getDefaultFile() throws IOException {
|
||||
return getDefaultMetadataFile(myRecorderId, EVENTS_SCHEME_FILE, DEPRECATED_EVENTS_SCHEME_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class WhitelistStorage extends BaseWhitelistStorage {
|
||||
}
|
||||
|
||||
private @Nullable String loadValidatorsFromLocalCache(@NotNull String recorderId) {
|
||||
String whiteListContent = myWhitelistPersistence.getCachedWhitelist();
|
||||
String whiteListContent = myWhitelistPersistence.getCachedMetadata();
|
||||
if (whiteListContent != null) {
|
||||
try {
|
||||
String newVersion = updateValidators(whiteListContent);
|
||||
|
||||
Reference in New Issue
Block a user