AP-7325: added statistics logs

GitOrigin-RevId: 3d42a48d7626ba10e77d3e61c25a92c92ea00e59
This commit is contained in:
Liubov Afanaseva
2025-06-06 10:59:34 +02:00
committed by intellij-monorepo-bot
parent 6bd87eadcc
commit 0147105da1
3 changed files with 37 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.internal.statistic.eventLog.*
import com.intellij.internal.statistic.eventLog.LogSystemCollector.sendingForAllRecordersDisabledField
import com.intellij.internal.statistic.eventLog.connection.metadata.EventGroupsFilterRules
import com.intellij.internal.statistic.eventLog.uploader.EventLogUploadException.EventLogUploadErrorType.*
import com.intellij.internal.statistic.uploader.EventLogUploaderOptions
@@ -51,7 +52,7 @@ object EventLogExternalUploader {
tempDir.deleteRecursively()
}
catch (e: Exception) {
LOG.warn("Failed reading previous upload result: " + e.message)
LOG.warn("Statistics. External uploader. Failed reading previous upload result: " + e.message)
}
}
@@ -84,7 +85,8 @@ object EventLogExternalUploader {
fun startExternalUpload(recordersProviders: List<StatisticsEventLoggerProvider>, isTestConfig: Boolean, isTestSendEndpoint: Boolean) {
val enabledEventLoggerProviders = recordersProviders.filter { it.isSendEnabled() }
if (enabledEventLoggerProviders.isEmpty()) {
LOG.info("Don't start external process because sending logs is disabled for all recorders")
LOG.info("Statistics. Don't start external uploader because sending logs is disabled for all recorders")
LogSystemCollector.externalUploaderLaunched.log(sendingForAllRecordersDisabledField.with(true))
return
}
enabledEventLoggerProviders.forEach { it.eventLogSystemLogger.logExternalSendCommandCreationStarted() }
@@ -94,22 +96,22 @@ object EventLogExternalUploader {
enabledEventLoggerProviders.forEach { it.eventLogSystemLogger.logExternalSendCommandCreationFinished(null) }
if (LOG.isDebugEnabled) {
LOG.debug("Starting external process: '${command.joinToString(separator = " ")}'")
LOG.debug("Statistics. Starting external uploader: '${command.joinToString(separator = " ")}'")
}
Runtime.getRuntime().exec(command)
LOG.info("Started external process for uploading event log")
LOG.info("Statistics. Started external process for uploading event log")
}
catch (e: EventLogUploadException) {
enabledEventLoggerProviders.forEach { it.eventLogSystemLogger.logExternalSendCommandCreationFinished(e.errorType) }
LOG.info(e)
LOG.info("Statistics. External uploader error: $e")
}
}
private fun prepareUploadCommand(recorders: List<StatisticsEventLoggerProvider>, applicationInfo: EventLogApplicationInfo): Array<out String> {
val sendConfigs = recorders.map { EventLogInternalSendConfig.createByRecorder(it.recorderId, false) }
if (sendConfigs.isEmpty()) {
throw EventLogUploadException("No available logs to send", NO_LOGS)
throw EventLogUploadException("Statistics. External uploader. No available logs to send", NO_LOGS)
}
val tempDir = getOrCreateTempDir()
@@ -217,7 +219,7 @@ object EventLogExternalUploader {
}
if (uploader == null || !Files.isRegularFile(uploader)) {
throw EventLogUploadException("Cannot find uploader jar", NO_UPLOADER)
throw EventLogUploadException("Statistics. External uploader. Cannot find uploader jar", NO_UPLOADER)
}
return uploader
}
@@ -226,7 +228,7 @@ object EventLogExternalUploader {
val library = PathManager.getJarForClass(clazz)
if (library == null || !Files.isRegularFile(library)) {
throw EventLogUploadException("Cannot find jar for $clazz", NO_UPLOADER)
throw EventLogUploadException("Statistics. External uploader. Cannot find jar for $clazz", NO_UPLOADER)
}
return library.toString()
}
@@ -238,7 +240,7 @@ object EventLogExternalUploader {
private fun getOrCreateTempDir(): File {
val tempDir = getTempFile()
if (!(tempDir.exists() || tempDir.mkdirs())) {
throw EventLogUploadException("Cannot create temp directory: $tempDir", NO_TEMP_FOLDER)
throw EventLogUploadException("Statistics. External uploader. Cannot create temp directory: $tempDir", NO_TEMP_FOLDER)
}
return tempDir
}

View File

@@ -45,6 +45,8 @@ abstract class EventLogSettingsClient {
val result: Boolean? = logError {
configurationClient.isConfigurationReachable()
}
applicationInfo.logger.info("Statistics. Configuration url: ${configurationClient.configurationUrl}")
applicationInfo.logger.info("Statistics. Configuration is reachable: $result")
return result != null && result
}
@@ -58,6 +60,7 @@ abstract class EventLogSettingsClient {
val result: Boolean? = logError {
configurationClient.isSendEnabled()
}
applicationInfo.logger.info("Statistics. Send is enabled: $result")
return result != null && result
}
@@ -69,6 +72,7 @@ abstract class EventLogSettingsClient {
val result: Map<String, String>? = logError {
configurationClient.provideOptions()
}
applicationInfo.logger.info("Statistics. Configuration options: $result")
return result ?: emptyMap()
}
@@ -77,9 +81,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideEndpointValue(endpoint: String): String? {
return logError {
val result = logError {
configurationClient.provideEndpointValue(endpoint)
}
applicationInfo.logger.info("Statistics. Configuration endpoint: $result")
return result
}
/**
@@ -87,9 +93,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideServiceUrl(): String? {
return logError {
val result = logError {
configurationClient.provideSendEndpoint()
}
applicationInfo.logger.info("Statistics. Configuration service url: $result")
return result
}
/**
@@ -97,9 +105,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideDictionaryServiceUrl(): String? {
return logError {
val result = logError {
configurationClient.provideDictionaryEndpoint()
}
applicationInfo.logger.info("Statistics. Configuration dictionary service url: $result")
return result
}
/**
@@ -107,9 +117,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideMetadataEndpoint(): String? {
return logError {
val result = logError {
configurationClient.provideMetadataEndpoint()
}
applicationInfo.logger.info("Statistics. Configuration metadata endpoint: $result")
return result
}
/**
@@ -117,9 +129,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideMetadataProductUrl(): String? {
return logError {
val result = logError {
configurationClient.provideMetadataProductUrl()
}
applicationInfo.logger.info("Statistics. Configuration metadata product url: $result")
return result
}
/**
@@ -127,9 +141,11 @@ abstract class EventLogSettingsClient {
* null otherwise. Info/warn exception, log exception to 'recorderId.event.log' group.
*/
fun provideMetadataProductUrl(metadataVersion: Int): String? {
return logError {
val result = logError {
configurationClient.provideMetadataProductUrl(metadataVersion)
}
applicationInfo.logger.info("Statistics. Configuration metadata product url: $result")
return result
}
/**

View File

@@ -113,7 +113,7 @@ public class EventLogStatisticsService implements StatisticsService {
ValidationErrorInfo error = validate(recordRequest, file);
if (error != null) {
if (logger.isTraceEnabled()) {
logger.trace(file.getName() + "-> " + error.getMessage());
logger.trace("Statistics. " + file.getName() + "-> " + error.getMessage());
}
decorator.onFailed(recordRequest, error.getCode(), null);
toRemove.add(file);
@@ -121,6 +121,7 @@ public class EventLogStatisticsService implements StatisticsService {
}
try {
logger.info("Statistics. Starting sending " + file.getName() + " to " + serviceUrl);
StatsHttpRequests.post(serviceUrl, connectionSettings).
withBody(LogEventSerializer.INSTANCE.toString(recordRequest), "application/json", StandardCharsets.UTF_8).
succeed((r, code) -> {
@@ -136,7 +137,7 @@ public class EventLogStatisticsService implements StatisticsService {
}
catch (Exception e) {
if (logger.isTraceEnabled()) {
logger.trace(file.getName() + " -> " + e.getMessage());
logger.trace("Statistics. " + file.getName() + " -> " + e.getMessage());
}
//noinspection InstanceofCatchParameter
int errorCode = e instanceof StatsRequestBuilder.InvalidHttpRequest ? ((StatsRequestBuilder.InvalidHttpRequest)e).getCode() : 50;
@@ -150,7 +151,7 @@ public class EventLogStatisticsService implements StatisticsService {
catch (Exception e) {
final String message = e.getMessage();
logger.info(message != null ? message : "", e);
throw new StatServiceException("Error during data sending.", e);
throw new StatServiceException("Statistics. Error during data sending.", e);
}
}