-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add plugin installed event [IDE-736] (#632)
* feat: add plugin installed event * feat: automated-region-configuration (IDE-732) (#631) * feat: Automated Snyk region configuration (IDE-732) * tidy: remove legacy functionality for domain/V1 * chore: update changelog * feat: add plugin installed event * chore: don't log actual filesystem path * chore: add changelog, minor visibility change to private methods * fix: test and visibility --------- Co-authored-by: Knut Funkel <[email protected]>
- Loading branch information
1 parent
759936f
commit 49e2620
Showing
12 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
src/main/kotlin/io/snyk/plugin/analytics/AnalyticsSender.kt
This file contains 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,63 @@ | ||
package io.snyk.plugin.analytics | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.util.Disposer | ||
import io.snyk.plugin.ui.toolwindow.SnykPluginDisposable | ||
import org.jetbrains.concurrency.runAsync | ||
import snyk.common.lsp.LanguageServerWrapper | ||
import snyk.common.lsp.analytics.AbstractAnalyticsEvent | ||
import java.util.LinkedList | ||
import java.util.concurrent.ConcurrentLinkedQueue | ||
|
||
class AnalyticsSender : Disposable { | ||
private var disposed: Boolean = false | ||
|
||
// left = event, right = callback function | ||
private val eventQueue = ConcurrentLinkedQueue<Pair<AbstractAnalyticsEvent, () -> Unit>>() | ||
|
||
init { | ||
Disposer.register(SnykPluginDisposable.getInstance(), this) | ||
start() | ||
} | ||
|
||
private fun start() { | ||
runAsync { | ||
val lsw = LanguageServerWrapper.getInstance() | ||
while (!disposed) { | ||
if (eventQueue.isEmpty() || lsw.notAuthenticated()) { | ||
Thread.sleep(1000) | ||
continue | ||
} | ||
val copyForSending = LinkedList(eventQueue) | ||
for (event in copyForSending) { | ||
try { | ||
lsw.sendReportAnalyticsCommand(event.first) | ||
event.second() | ||
} catch (e: Exception) { | ||
lsw.logger.warn("unexpected exception while sending analytics") | ||
} finally { | ||
eventQueue.remove(event) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun logEvent(event: AbstractAnalyticsEvent, callback: () -> Unit = {}) = eventQueue.add(Pair(event, callback)) | ||
|
||
companion object { | ||
private var instance: AnalyticsSender? = null | ||
|
||
@JvmStatic | ||
fun getInstance(): AnalyticsSender { | ||
if (instance == null) { | ||
instance = AnalyticsSender() | ||
} | ||
return instance as AnalyticsSender | ||
} | ||
} | ||
|
||
override fun dispose() { | ||
this.disposed = true | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/snyk/common/lsp/analytics/AbstractAnalyticsEvent.kt
This file contains 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,3 @@ | ||
package snyk.common.lsp.analytics | ||
|
||
interface AbstractAnalyticsEvent |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/snyk/common/lsp/analytics/AnalyticsEvent.kt
This file contains 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,13 @@ | ||
package snyk.common.lsp.analytics | ||
|
||
data class AnalyticsEvent( | ||
val interactionType: String, | ||
val category: List<String>, | ||
val status: String = "success", | ||
val targetId: String = "pkg:filesystem/scrubbed", | ||
val timestampMs: Long = System.currentTimeMillis(), | ||
val durationMs: Long = 0, | ||
val results: Map<String, Any> = emptyMap(), | ||
val errors: List<Any> = emptyList(), | ||
val extension: Map<String, Any> = emptyMap(), | ||
) : AbstractAnalyticsEvent |
This file contains 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
This file contains 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
This file contains 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