-
Notifications
You must be signed in to change notification settings - Fork 272
Add file extension type metrics #4859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
58cc77b
20a098a
47214c4
2bdf982
af2374e
483b14f
61026b4
aacbab5
be64a94
c686f1d
5b404c9
a589a04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.telemetry | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.fileEditor.FileEditorManagerListener | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.util.Alarm | ||
import org.jetbrains.annotations.TestOnly | ||
import software.aws.toolkits.telemetry.IdeTelemetry | ||
|
||
class OpenedFileTypesMetricsListener : FileEditorManagerListener { | ||
override fun fileOpened(source: FileEditorManager, file: VirtualFile) { | ||
val extension = file.extension ?: return | ||
source.project.service<OpenedFileTypesMetricsService>().addToExistingTelemetryBatch(extension) | ||
} | ||
} | ||
|
||
@Service(Service.Level.PROJECT) | ||
class OpenedFileTypesMetricsService : Disposable { | ||
private val currentOpenedFileTypes = mutableSetOf<String>() | ||
private val alarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, this) | ||
override fun dispose() {} | ||
|
||
init { | ||
scheduleNextMetricEvent() | ||
} | ||
|
||
private fun scheduleNextMetricEvent() { | ||
alarm.addRequest(this::emitFileTypeMetric, INTERVAL_BETWEEN_METRICS) | ||
} | ||
|
||
@Synchronized | ||
fun emitFileTypeMetric() { | ||
currentOpenedFileTypes.forEach { | ||
emitMetric(it) | ||
} | ||
currentOpenedFileTypes.clear() | ||
Check warning on line 43 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
if (!ApplicationManager.getApplication().isUnitTestMode) { | ||
scheduleNextMetricEvent() | ||
Check warning on line 45 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
} | ||
} | ||
Check warning on line 47 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
|
||
@TestOnly | ||
fun getOpenedFileTypes(): Set<String> = currentOpenedFileTypes | ||
|
||
@Synchronized | ||
fun addToExistingTelemetryBatch(fileExt: String) { | ||
if (fileExt in ALLOWED_CODE_EXTENSIONS) { | ||
currentOpenedFileTypes.add(fileExt) | ||
} | ||
} | ||
|
||
private fun emitMetric(openFileExtension: String) = | ||
IdeTelemetry.editCodeFile(project = null, filenameExt = openFileExtension) | ||
Check warning on line 60 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
|
||
companion object { | ||
private const val INTERVAL_BETWEEN_METRICS = 30 * 60 * 1000 | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.