Skip to content
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

telemetry(amazonq): invalid zip event #5265

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("../")) {
ctlai95 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@
"reloaded"
],
"description": "Toolkit run state."
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be added to common?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can follow up with a separate PR after this

{
"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
}
]
}
]
}
Loading