Skip to content

Commit 82ea164

Browse files
authored
Add file extension type metrics (#4859)
* Add file extension type metrics * addressed feedback 1 * added tests * Feedback 2 * feedback * fixed runtime disposer exception * removed extra code * feedback 3 * feedback 4
1 parent a9e0aec commit 82ea164

File tree

6 files changed

+308
-202
lines changed

6 files changed

+308
-202
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import software.aws.toolkits.core.utils.outputStream
2020
import software.aws.toolkits.core.utils.putNextEntry
2121
import software.aws.toolkits.jetbrains.core.coroutines.EDT
2222
import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
23+
import software.aws.toolkits.jetbrains.services.telemetry.ALLOWED_CODE_EXTENSIONS
2324
import software.aws.toolkits.resources.AwsCoreBundle
2425
import software.aws.toolkits.telemetry.AmazonqTelemetry
2526
import java.io.File
@@ -94,7 +95,7 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
9495
if (file.isDirectory) return true
9596

9697
val extension = file.extension ?: return false
97-
return FeatureDevBundleConfig.ALLOWED_CODE_EXTENSIONS.contains(extension)
98+
return ALLOWED_CODE_EXTENSIONS.contains(extension)
9899
}
99100

100101
private fun ignoreFileByExtension(file: VirtualFile) =

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QConstants.kt

Lines changed: 0 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -7,204 +7,3 @@ object QConstants {
77
const val Q_MARKETPLACE_URI = "https://aws.amazon.com/q/developer/"
88
const val CODEWHISPERER_LOGIN_HELP_URI = "https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/auth-access.html"
99
}
10-
11-
// List from Stack Overflow 2023 survey: https://survey.stackoverflow.co/2023/#technology
12-
object FeatureDevBundleConfig {
13-
val ALLOWED_CODE_EXTENSIONS = setOf(
14-
"abap",
15-
"ada",
16-
"adb",
17-
"ads",
18-
"apl",
19-
"asm",
20-
"awk",
21-
"b",
22-
"bas",
23-
"bash",
24-
"bat",
25-
"boo",
26-
"c",
27-
"cbl",
28-
"cc",
29-
"cfc",
30-
"cfm",
31-
"cjs",
32-
"clj",
33-
"cljc",
34-
"cljs",
35-
"cls",
36-
"cmake",
37-
"cob",
38-
"cobra",
39-
"coffee",
40-
"cpp",
41-
"cpy",
42-
"cr",
43-
"cs",
44-
"css",
45-
"csx",
46-
"cxx",
47-
"d",
48-
"dart",
49-
"dfm",
50-
"dpr",
51-
"e",
52-
"el",
53-
"elm",
54-
"erl",
55-
"ex",
56-
"exs",
57-
"f",
58-
"f03",
59-
"f08",
60-
"f77",
61-
"f90",
62-
"f95",
63-
"flow",
64-
"for",
65-
"fs",
66-
"fsi",
67-
"fsx",
68-
"gd",
69-
"go",
70-
"gql",
71-
"graphql",
72-
"groovy",
73-
"gs",
74-
"gsp",
75-
"gst",
76-
"gsx",
77-
"gvy",
78-
"h",
79-
"hack",
80-
"hh",
81-
"hpp",
82-
"hrl",
83-
"hs",
84-
"htm",
85-
"html",
86-
"hy",
87-
"idl",
88-
"io",
89-
"jar",
90-
"java",
91-
"jl",
92-
"js",
93-
"json",
94-
"jsx",
95-
"kt",
96-
"kts",
97-
"lean",
98-
"lgt",
99-
"lhs",
100-
"lisp",
101-
"logtalk",
102-
"lsp",
103-
"lua",
104-
"m",
105-
"ma",
106-
"mak",
107-
"makefile",
108-
"md",
109-
"mjs",
110-
"ml",
111-
"mli",
112-
"mpl",
113-
"ms",
114-
"mu",
115-
"mv",
116-
"n",
117-
"nb",
118-
"nim",
119-
"nix",
120-
"oot",
121-
"oz",
122-
"pas",
123-
"pasm",
124-
"perl",
125-
"php",
126-
"phtml",
127-
"pike",
128-
"pir",
129-
"pl",
130-
"pm",
131-
"pmod",
132-
"pp",
133-
"pro",
134-
"prolog",
135-
"ps1",
136-
"psd1",
137-
"psm1",
138-
"purs",
139-
"py",
140-
"pyw",
141-
"qs",
142-
"r",
143-
"raku",
144-
"rakumod",
145-
"rakutest",
146-
"rb",
147-
"rbw",
148-
"rdata",
149-
"re",
150-
"red",
151-
"reds",
152-
"res",
153-
"rex",
154-
"rexx",
155-
"ring",
156-
"rkt",
157-
"rktl",
158-
"rlib",
159-
"rm",
160-
"rmd",
161-
"roff",
162-
"ron",
163-
"rs",
164-
"ruby",
165-
"s",
166-
"sas",
167-
"sb",
168-
"sb2",
169-
"sb3",
170-
"sc",
171-
"scala",
172-
"scd",
173-
"scm",
174-
"scss",
175-
"sass",
176-
"sh",
177-
"shen",
178-
"sig",
179-
"sml",
180-
"sol",
181-
"sql",
182-
"ss",
183-
"st",
184-
"sv",
185-
"swift",
186-
"t",
187-
"tcl",
188-
"tf",
189-
"trigger",
190-
"ts",
191-
"tsx",
192-
"tu",
193-
"v",
194-
"vala",
195-
"vapi",
196-
"vb",
197-
"vba",
198-
"vbx",
199-
"vhd",
200-
"vhdl",
201-
"vue",
202-
"x",
203-
"xc",
204-
"xi",
205-
"xml",
206-
"yaml",
207-
"yml",
208-
"zig"
209-
)
210-
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.telemetry
5+
6+
import com.intellij.openapi.Disposable
7+
import com.intellij.openapi.application.ApplicationManager
8+
import com.intellij.openapi.components.Service
9+
import com.intellij.openapi.components.service
10+
import com.intellij.openapi.fileEditor.FileEditorManager
11+
import com.intellij.openapi.fileEditor.FileEditorManagerListener
12+
import com.intellij.openapi.vfs.VirtualFile
13+
import com.intellij.util.Alarm
14+
import org.jetbrains.annotations.TestOnly
15+
import software.aws.toolkits.telemetry.IdeTelemetry
16+
17+
class OpenedFileTypesMetricsListener : FileEditorManagerListener {
18+
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
19+
val extension = file.extension ?: return
20+
source.project.service<OpenedFileTypesMetricsService>().addToExistingTelemetryBatch(extension)
21+
}
22+
}
23+
24+
@Service(Service.Level.PROJECT)
25+
class OpenedFileTypesMetricsService : Disposable {
26+
private val currentOpenedFileTypes = mutableSetOf<String>()
27+
private val alarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, this)
28+
override fun dispose() {}
29+
30+
init {
31+
scheduleNextMetricEvent()
32+
}
33+
34+
private fun scheduleNextMetricEvent() {
35+
alarm.addRequest(this::emitFileTypeMetric, INTERVAL_BETWEEN_METRICS)
36+
}
37+
38+
@Synchronized
39+
fun emitFileTypeMetric() {
40+
currentOpenedFileTypes.forEach {
41+
emitMetric(it)
42+
}
43+
currentOpenedFileTypes.clear()
44+
if (!ApplicationManager.getApplication().isUnitTestMode) {
45+
scheduleNextMetricEvent()
46+
}
47+
}
48+
49+
@TestOnly
50+
fun getOpenedFileTypes(): Set<String> = currentOpenedFileTypes
51+
52+
@Synchronized
53+
fun addToExistingTelemetryBatch(fileExt: String) {
54+
if (fileExt in ALLOWED_CODE_EXTENSIONS) {
55+
currentOpenedFileTypes.add(fileExt)
56+
}
57+
}
58+
59+
private fun emitMetric(openFileExtension: String) =
60+
IdeTelemetry.editCodeFile(project = null, filenameExt = openFileExtension)
61+
62+
companion object {
63+
private const val INTERVAL_BETWEEN_METRICS = 30 * 60 * 1000
64+
}
65+
}

0 commit comments

Comments
 (0)