Skip to content

Commit

Permalink
chore: streamline scan event initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Nov 10, 2023
1 parent 646e56c commit 3e6f14d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
39 changes: 12 additions & 27 deletions src/main/kotlin/io/snyk/plugin/analytics/AnalyticsScanListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import io.snyk.plugin.events.SnykScanListener
import io.snyk.plugin.getSnykTaskQueueService
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.snykcode.SnykCodeResults
import org.apache.commons.lang.SystemUtils
import snyk.common.SnykError
import snyk.common.lsp.commands.ScanDoneEvent
import snyk.container.ContainerResult
import snyk.iac.IacResult
import snyk.oss.OssResult
import snyk.pluginInfo

@Service(Service.Level.PROJECT)
class AnalyticsScanListener(val project: Project) {
Expand All @@ -21,19 +18,7 @@ class AnalyticsScanListener(val project: Project) {
): ScanDoneEvent {
return ScanDoneEvent(
ScanDoneEvent.Data(
type = "analytics",
attributes = ScanDoneEvent.Attributes(
deviceId = pluginSettings().userAnonymousId,
application = pluginInfo.integrationName,
applicationVersion = pluginInfo.integrationVersion,
os = SystemUtils.OS_NAME,
arch = SystemUtils.OS_ARCH,
integrationName = pluginInfo.integrationName,
integrationVersion = pluginInfo.integrationVersion,
integrationEnvironment = pluginInfo.integrationEnvironment,
integrationEnvironmentVersion = pluginInfo.integrationEnvironmentVersion,
eventType = "Scan done",
status = "Succeeded",
scanType = product,
uniqueIssueCount = ScanDoneEvent.UniqueIssueCount(
critical = critical,
Expand Down Expand Up @@ -92,18 +77,6 @@ class AnalyticsScanListener(val project: Project) {
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningOssError(snykError: SnykError) {
// do nothing
}

override fun scanningIacError(snykError: SnykError) {
// do nothing
}

override fun scanningSnykCodeError(snykError: SnykError) {
// do nothing
}

override fun scanningContainerFinished(containerResult: ContainerResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
Expand All @@ -116,6 +89,18 @@ class AnalyticsScanListener(val project: Project) {
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningOssError(snykError: SnykError) {
// do nothing
}

override fun scanningIacError(snykError: SnykError) {
// do nothing
}

override fun scanningSnykCodeError(snykError: SnykError) {
// do nothing
}

override fun scanningContainerError(snykError: SnykError) {
// do nothing
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/kotlin/snyk/common/lsp/commands/ScanDoneEvent.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package snyk.common.lsp.commands

import com.google.gson.annotations.SerializedName
import io.snyk.plugin.pluginSettings
import org.apache.commons.lang.SystemUtils
import snyk.pluginInfo
import java.time.ZonedDateTime

data class ScanDoneEvent(
@SerializedName("data") val data: Data
) {
data class Data(
@SerializedName("type") val type: String, @SerializedName("attributes") val attributes: Attributes
@SerializedName("type") val type: String = "analytics",
@SerializedName("attributes") val attributes: Attributes
)

data class Attributes(
@SerializedName("deviceId") val deviceId: String,
@SerializedName("deviceId") val deviceId: String = pluginSettings().userAnonymousId,
@SerializedName("application") val application: String = pluginInfo.integrationEnvironment,
@SerializedName("application_version")
val applicationVersion: String = pluginInfo.integrationEnvironmentVersion,
@SerializedName("os") val os: String,
@SerializedName("arch") val arch: String,
@SerializedName("os") val os: String = SystemUtils.OS_NAME,
@SerializedName("arch") val arch: String = SystemUtils.OS_ARCH,
@SerializedName("integration_name") val integrationName: String = pluginInfo.integrationName,
@SerializedName("integration_version") val integrationVersion: String = pluginInfo.integrationVersion,
@SerializedName("integration_environment")
val integrationEnvironment: String = pluginInfo.integrationEnvironment,
@SerializedName("integration_environment_version")
val integrationEnvironmentVersion: String = pluginInfo.integrationEnvironmentVersion,
@SerializedName("event_type") val eventType: String,
@SerializedName("status") val status: String,
@SerializedName("event_type") val eventType: String = "Scan done",
@SerializedName("status") val status: String = "Succeeded",
@SerializedName("scan_type") val scanType: String,
@SerializedName("unique_issue_count") val uniqueIssueCount: UniqueIssueCount,
@SerializedName("duration_ms") val durationMs: String,
Expand Down

0 comments on commit 3e6f14d

Please sign in to comment.