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

bump telemetry to 1.1.0.52 (#693) #694

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jetBrainsChannel=stable
intellijPluginVersion=1.16.1
kotlinJvmPluginVersion=1.8.0
intellijCommonVersion=1.9.3
telemetryPluginVersion=1.0.0.44
telemetryPluginVersion=1.1.0.52
kotlin.stdlib.default.dependency = false
kotlinVersionIdea221=1.6.21
kotlinVersionIdea211=1.4.32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ open class ResourceEditorFactory protected constructor(
private val createResourceEditor: (FileEditor, Project) -> ResourceEditor =
{ editor, project -> ResourceEditor(editor, IResourceModel.getInstance(), project) },
/* for mocking purposes */
private val reportTelemetry: (FileEditor, Project, TelemetryMessageBuilder.ActionMessage) -> Unit = { editor, project, telemetry ->
val resourceInfo = getKubernetesResourceInfo(editor.file, project)
TelemetryService.sendTelemetry(resourceInfo, telemetry)
},
/* for mocking purposes */
private val getProjectManager: () -> ProjectManager = { ProjectManager.getInstance() }

private val getProjectManager: () -> ProjectManager = { ProjectManager.getInstance() },
) {

companion object {
Expand Down Expand Up @@ -123,9 +117,9 @@ open class ResourceEditorFactory protected constructor(
) {
return null
}
val telemetry = TelemetryService.instance.action(TelemetryService.NAME_PREFIX_EDITOR + "open")
return try {
runAsync { reportTelemetry.invoke(editor, project, telemetry) }
val telemetry = getTelemetryMessageBuilder().action(TelemetryService.NAME_PREFIX_EDITOR + "open")
return try {
runAsync { TelemetryService.sendTelemetry(getKubernetesResourceInfo(editor.file, project), telemetry) }
val resourceEditor = createResourceEditor.invoke(editor, project)
resourceEditor.createToolbar()
getProjectManager.invoke().addProjectManagerListener(project, onProjectClosed(resourceEditor))
Expand Down Expand Up @@ -160,4 +154,9 @@ open class ResourceEditorFactory protected constructor(
ApplicationManager.getApplication().invokeLater(runnable)
}
}

/* for testing purposes */
protected open fun getTelemetryMessageBuilder(): TelemetryMessageBuilder {
return TelemetryService.instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.nhaarman.mockitokotlin2.whenever
import com.redhat.devtools.intellij.kubernetes.editor.ResourceEditor.Companion.KEY_RESOURCE_EDITOR
import com.redhat.devtools.intellij.kubernetes.model.util.createResource
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage
import io.fabric8.kubernetes.api.model.HasMetadata
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
Expand Down Expand Up @@ -64,7 +65,7 @@ class ResourceEditorFactoryTest {
valueFrom:
secretKeyRef:
name: postgres-secret
key: secret.password
key: secret.password
""".trimIndent()

private val resource = createResource<HasMetadata>(deployment)
Expand Down Expand Up @@ -125,15 +126,20 @@ class ResourceEditorFactoryTest {
on { editor } doReturn fileEditor
}

private val editorFactory =
private val actionMessage: ActionMessage = mock {
on { property(any(), any()) } doReturn mock
}

private val telemetryMessageBuilder: TelemetryMessageBuilder = mockTelemetryMessageBuilder()

private val editorFactory =
TestableResourceEditorFactory(
getFileEditorManager,
createResourceFile,
isValidType,
isTemporary,
hasKubernetesResource,
createResourceEditor,
reportTelemetry,
getProjectManager
)

Expand Down Expand Up @@ -285,14 +291,24 @@ class ResourceEditorFactoryTest {
verify(virtualFile).putUserData(KEY_RESOURCE_EDITOR, editor)
}

private open class TestableResourceEditorFactory(
private fun mockTelemetryMessageBuilder(): TelemetryMessageBuilder {
val actionMessage: ActionMessage = mock {
on { property(any(), any()) } doReturn mock
}

return mock {
on { action(any()) } doReturn actionMessage
}

}

private open inner class TestableResourceEditorFactory(
getFileEditorManager: (project: Project) -> FileEditorManager,
createResourceFile: (resource: HasMetadata) -> ResourceFile?,
isValidType: (file: VirtualFile?) -> Boolean,
isTemporary: (file: VirtualFile?) -> Boolean,
hasKubernetesResource: (FileEditor, Project) -> Boolean,
createResourceEditor: (FileEditor, Project) -> ResourceEditor,
reportTelemetry: (FileEditor, Project, TelemetryMessageBuilder.ActionMessage) -> Unit,
getProjectManager: () -> ProjectManager
) : ResourceEditorFactory(
getFileEditorManager,
Expand All @@ -301,7 +317,6 @@ class ResourceEditorFactoryTest {
isTemporary,
hasKubernetesResource,
createResourceEditor,
reportTelemetry,
getProjectManager
) {

Expand All @@ -314,5 +329,9 @@ class ResourceEditorFactoryTest {
// dont execute in UI thread
runnable.invoke()
}

override fun getTelemetryMessageBuilder(): TelemetryMessageBuilder {
return telemetryMessageBuilder
}
}
}
}
Loading