-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat: add plugin installed event [IDE-736] #632
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e193c8
feat: add plugin installed event
bastiandoetsch ccde93e
chore: don't log actual filesystem path
bastiandoetsch 1600592
chore: add changelog, minor visibility change to private methods
bastiandoetsch 40b9c02
fix: test and visibility
bastiandoetsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will plugin developers working towards prod send a plugin installed event every time we start debug sessions? Will this be an issue for reporting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be an issue, as these versions would have a snapshot version of the integrationName. Any report would of cause need to filter snapshot or dev versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue would only occur in our org anyways.