-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
58cc77b
Add file extension type metrics
manodnyab 20a098a
addressed feedback 1
manodnyab 47214c4
added tests
manodnyab 2bdf982
Feedback 2
manodnyab af2374e
Merge remote-tracking branch 'origin/main' into manodnyb/addeditcodem…
manodnyab 483b14f
feedback
manodnyab 61026b4
fixed runtime disposer exception
manodnyab aacbab5
removed extra code
manodnyab be64a94
feedback 3
manodnyab c686f1d
feedback 4
manodnyab 5b404c9
Merge branch 'main' into manodnyb/addeditcodemetrics
manodnyab a589a04
Merge branch 'main' into manodnyb/addeditcodemetrics
manodnyab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...ommunity/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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.fileEditor.FileEditorManager | ||
import com.intellij.openapi.fileEditor.FileEditorManagerListener | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.util.Alarm | ||
import software.aws.toolkits.telemetry.IdeTelemetry | ||
|
||
class OpenedFileTypesMetrics : ProjectActivity, Disposable { | ||
Check warning on line 16 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
private val currentOpenedFileTypes = mutableSetOf<String>() | ||
private val alarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, this) | ||
override suspend fun execute(project: Project) { | ||
// add already open file extensions | ||
FileEditorManager.getInstance(project).openFiles.forEach { | ||
val extension = it.extension ?: return@forEach | ||
addToExistingTelemetryBatch(extension) | ||
} | ||
|
||
// add newly opened file extensions | ||
project.messageBus.connect(this).subscribe( | ||
FileEditorManagerListener.FILE_EDITOR_MANAGER, | ||
object : FileEditorManagerListener { | ||
override fun fileOpened(source: FileEditorManager, file: VirtualFile) { | ||
val extension = file.extension ?: return | ||
addToExistingTelemetryBatch(extension) | ||
} | ||
} | ||
) | ||
scheduleNextMetricEvent() | ||
} | ||
|
||
private fun addToExistingTelemetryBatch(fileExt: String) { | ||
val extension = ".$fileExt" | ||
if (extension in codeFileTypes) { | ||
currentOpenedFileTypes.add(extension) | ||
} | ||
} | ||
|
||
fun scheduleNextMetricEvent() { | ||
alarm.addRequest(this::emitFileTypeMetric, INTERVAL_BETWEEN_METRICS) | ||
} | ||
|
||
override fun dispose() {} | ||
|
||
fun emitFileTypeMetric() { | ||
ApplicationManager.getApplication().executeOnPooledThread { | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
currentOpenedFileTypes.forEach { | ||
emitMetric(it) | ||
} | ||
currentOpenedFileTypes.clear() | ||
if (!ApplicationManager.getApplication().isUnitTestMode) { | ||
scheduleNextMetricEvent() | ||
} | ||
} | ||
} | ||
|
||
fun emitMetric(openFileExtension: String) { | ||
IdeTelemetry.editCodeFile(project = null, filenameExt = openFileExtension) | ||
} | ||
|
||
companion object { | ||
const val INTERVAL_BETWEEN_METRICS = 30 * 60 * 1000 | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
204 changes: 204 additions & 0 deletions
204
...brains-community/src/software/aws/toolkits/jetbrains/services/telemetry/TelemetryUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.telemetry | ||
|
||
val codeFileTypes = setOf( | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
".abap", | ||
".ada", | ||
".adb", | ||
".ads", | ||
".apl", | ||
".asm", | ||
".awk", | ||
".b", | ||
".bas", | ||
".bash", | ||
".bat", | ||
".boo", | ||
".c", | ||
".cbl", | ||
".cc", | ||
".cfc", | ||
".cfm", | ||
".cjs", | ||
".class", | ||
".clj", | ||
".cljc", | ||
".cljs", | ||
".cls", | ||
".cmake", | ||
".cob", | ||
".cobra", | ||
".coffee", | ||
".cpp", | ||
".cpy", | ||
".cr", | ||
".cs", | ||
".css", | ||
".csx", | ||
".cxx", | ||
".d", | ||
".dart", | ||
".dfm", | ||
".dpr", | ||
".e", | ||
".el", | ||
".elc", | ||
".elm", | ||
".erl", | ||
".ex", | ||
".exs", | ||
".f", | ||
".f03", | ||
".f08", | ||
".f77", | ||
".f90", | ||
".f95", | ||
".flow", | ||
".for", | ||
".fs", | ||
".fsi", | ||
".fsx", | ||
".gd", | ||
".go", | ||
".gql", | ||
".graphql", | ||
".groovy", | ||
".gs", | ||
".gsp", | ||
".gst", | ||
".gsx", | ||
".gvy", | ||
".h", | ||
".hack", | ||
".hh", | ||
".hpp", | ||
".hrl", | ||
".hs", | ||
".htm", | ||
".html", | ||
".hy", | ||
".idl", | ||
".io", | ||
".jar", | ||
".java", | ||
".jl", | ||
".js", | ||
".json", | ||
".jsx", | ||
".kt", | ||
".kts", | ||
".lean", | ||
".lgt", | ||
".lhs", | ||
".lisp", | ||
".logtalk", | ||
".lsp", | ||
".lua", | ||
".m", | ||
".ma", | ||
".mak", | ||
".makefile", | ||
".md", | ||
".mjs", | ||
".ml", | ||
".mli", | ||
".mpl", | ||
".ms", | ||
".mu", | ||
".mv", | ||
".n", | ||
".nb", | ||
".nim", | ||
".nix", | ||
".oot", | ||
".oz", | ||
".pas", | ||
".pasm", | ||
".perl", | ||
".php", | ||
".phtml", | ||
".pike", | ||
".pir", | ||
".pl", | ||
".pm", | ||
".pmod", | ||
".pp", | ||
".pro", | ||
".prolog", | ||
".ps1", | ||
".psd1", | ||
".psm1", | ||
".purs", | ||
".py", | ||
".pyc", | ||
".pyo", | ||
".pyw", | ||
".qs", | ||
".r", | ||
".raku", | ||
".rakumod", | ||
".rakutest", | ||
".rb", | ||
".rbw", | ||
".rdata", | ||
".re", | ||
".red", | ||
".reds", | ||
".res", | ||
".rex", | ||
".rexx", | ||
".ring", | ||
".rkt", | ||
".rktl", | ||
".rlib", | ||
".rm", | ||
".rmd", | ||
".roff", | ||
".ron", | ||
".rs", | ||
".ruby", | ||
".s", | ||
".sas", | ||
".sb", | ||
".sb2", | ||
".sb3", | ||
".sc", | ||
".scala", | ||
".scd", | ||
".scm", | ||
".scss", | ||
".sh", | ||
".shen", | ||
".sig", | ||
".sml", | ||
".sol", | ||
".sql", | ||
".ss", | ||
".st", | ||
".sv", | ||
".swift", | ||
".t", | ||
".tcl", | ||
".tf", | ||
".trigger", | ||
".ts", | ||
".tsx", | ||
".tu", | ||
".v", | ||
".vala", | ||
".vapi", | ||
".vb", | ||
".vba", | ||
".vbx", | ||
".vhd", | ||
".vhdl", | ||
".vue", | ||
".x", | ||
".xc", | ||
".xi", | ||
".xml", | ||
".yaml", | ||
".zig", | ||
) |
65 changes: 65 additions & 0 deletions
65
...unity/tst/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypeMetricsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.fileEditor.FileEditorManager | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.intellij.testFramework.ProjectRule | ||
import com.intellij.testFramework.runInEdtAndWait | ||
import kotlinx.coroutines.runBlocking | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.doAnswer | ||
import org.mockito.kotlin.spy | ||
import org.mockito.kotlin.stub | ||
import org.mockito.kotlin.verify | ||
|
||
class OpenedFileTypeMetricsTest { | ||
|
||
@Rule | ||
@JvmField | ||
val projectRule = ProjectRule() | ||
|
||
@Test | ||
fun `metrics are recorded for already opened file types`() { | ||
val dummyFile = LightVirtualFile("dummy.kt") | ||
runInEdtAndWait { | ||
FileEditorManager.getInstance(projectRule.project).openFile(dummyFile) | ||
} | ||
|
||
val openedFileTypeMetrics = spy(OpenedFileTypesMetrics()) | ||
openedFileTypeMetrics.stub { | ||
on { openedFileTypeMetrics.scheduleNextMetricEvent() }.doAnswer { | ||
openedFileTypeMetrics.emitFileTypeMetric() | ||
} | ||
} | ||
|
||
runBlocking { | ||
openedFileTypeMetrics.execute(projectRule.project) | ||
} | ||
verify(openedFileTypeMetrics).emitMetric(".kt") | ||
} | ||
|
||
@Test | ||
fun `duplicate metrics are not emitted`() { | ||
val testFile = LightVirtualFile("test1.kt") | ||
val testFile2 = LightVirtualFile("test2.kt") | ||
runInEdtAndWait { | ||
FileEditorManager.getInstance(projectRule.project).openFile(testFile) | ||
FileEditorManager.getInstance(projectRule.project).openFile(testFile2) | ||
} | ||
val openedFileTypeMetrics = spy(OpenedFileTypesMetrics()) | ||
openedFileTypeMetrics.stub { | ||
on { openedFileTypeMetrics.scheduleNextMetricEvent() }.doAnswer { | ||
openedFileTypeMetrics.emitFileTypeMetric() | ||
} | ||
} | ||
|
||
runBlocking { | ||
openedFileTypeMetrics.execute(projectRule.project) | ||
} | ||
verify(openedFileTypeMetrics).emitMetric(any()) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.