Skip to content

Commit

Permalink
telemetry(amazonq): invalid zip event (#5265)
Browse files Browse the repository at this point in the history
* telemetry(amazonq): invalid zip event

* check windows path
  • Loading branch information
ctlai95 authored Jan 15, 2025
1 parent f06bab3 commit 809538a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.Ama
import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererUnknownLanguage
import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererTelemetryService
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CODE_SCAN_CREATE_PAYLOAD_TIMEOUT_IN_SECONDS
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CodeAnalysisScope
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.DEFAULT_CODE_SCAN_TIMEOUT_IN_SECONDS
Expand Down Expand Up @@ -195,6 +196,9 @@ class CodeScanSessionConfig(
files.forEach { file ->
try {
val relativePath = "${project.name}/${file.relativeTo(projectRoot.toNioPath())}"
if (relativePath.contains("../") || relativePath.contains("..\\")) {
CodeWhispererTelemetryService.getInstance().sendInvalidZipEvent(file, projectRoot.toNioPath(), relativePath)
}
LOG.debug { "Selected file for truncation: $file" }
it.putNextEntry(relativePath.toString(), file)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ import software.aws.toolkits.telemetry.Component
import software.aws.toolkits.telemetry.CredentialSourceId
import software.aws.toolkits.telemetry.MetricResult
import software.aws.toolkits.telemetry.Result
import java.nio.file.Path
import java.time.Duration
import java.time.Instant
import java.util.Queue
import kotlin.io.path.pathString

@Service
class CodeWhispererTelemetryService {
Expand Down Expand Up @@ -609,6 +611,14 @@ class CodeWhispererTelemetryService {
assert(ApplicationManager.getApplication().isUnitTestMode)
return this.previousUserTriggerDecisions
}

fun sendInvalidZipEvent(filePath: Path, projectRoot: Path, relativePath: String) {
CodewhispererTelemetry.invalidZip(
filePath = filePath.pathString,
workspaceRoot = projectRoot.pathString,
relativePath = relativePath
)
}
}

fun isTelemetryEnabled(): Boolean = AwsSettings.getInstance().isTelemetryEnabled
33 changes: 33 additions & 0 deletions plugins/core/jetbrains-community/resources/telemetryOverride.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@
"reloaded"
],
"description": "Toolkit run state."
},
{
"name": "filePath",
"type": "string",
"description": "The path of the file"
},
{
"name": "workspaceRoot",
"type": "string",
"description": "The path of the project root"
},
{
"name": "relativePath",
"type": "string",
"description": "The relative path of the file"
}
],
"metrics": [
Expand Down Expand Up @@ -530,6 +545,24 @@
}
],
"passive": true
},
{
"name": "codewhisperer_invalidZip",
"description": "Invalid zip file",
"metadata": [
{
"type": "filePath",
"required": true
},
{
"type": "workspaceRoot",
"required": true
},
{
"type": "relativePath",
"required": true
}
]
}
]
}

0 comments on commit 809538a

Please sign in to comment.