Skip to content

Commit

Permalink
fix: send telemetry for describe resource (#791)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Oct 8, 2024
1 parent 9c69e50 commit 8a91c04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ package com.redhat.devtools.intellij.kubernetes.actions

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.Progressive
import com.redhat.devtools.intellij.common.actions.StructureTreeAction
import com.redhat.devtools.intellij.kubernetes.editor.describe.DescriptionViewerFactory
import com.redhat.devtools.intellij.kubernetes.model.Notification
import com.redhat.devtools.intellij.kubernetes.model.util.toMessage
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_RESOURCE_KIND
import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.api.model.Pod
import javax.swing.tree.TreePath
Expand All @@ -29,15 +33,23 @@ class DescribeResourceAction: StructureTreeAction() {
val descriptor = selected?.get(0)?.getDescriptor() ?: return
val project = descriptor.project ?: return
val toDescribe: HasMetadata = descriptor.element as? HasMetadata? ?: return
try {
DescriptionViewerFactory.instance.openEditor(toDescribe, project)
} catch (e: RuntimeException) {
logger<DescribeResourceAction>().warn("Error opening editor ${toDescribe.metadata.name}", e)
Notification().error(
"Error opening editor ${toDescribe.metadata.name}",
"Could not open editor for ${toDescribe.kind} '${toDescribe.metadata.name}'."
)
}
run("Describe ${toMessage(toDescribe, 30)}...", true,
Progressive {
val telemetry = TelemetryService.instance.action("describe resource")
.property(PROP_RESOURCE_KIND, toDescribe.kind)
try {
DescriptionViewerFactory.instance.openEditor(toDescribe, project)
telemetry.success().send()
} catch (e: RuntimeException) {
logger<DescribeResourceAction>().warn("Error opening editor ${toDescribe.metadata.name}", e)
Notification().error(
"Error opening editor ${toDescribe.metadata.name}",
"Could not open editor for ${toDescribe.kind} '${toDescribe.metadata.name}'."
)
telemetry.error(e).send()
}
}
)
}

override fun isVisible(selected: Array<out Any>?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.LightVirtualFile
import com.redhat.devtools.intellij.kubernetes.editor.describe.describer.PodDescriber
import com.redhat.devtools.intellij.kubernetes.model.util.isSameResource
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder
import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.api.model.Pod
import org.jetbrains.yaml.YAMLFileType
Expand Down Expand Up @@ -122,23 +120,4 @@ open class DescriptionViewerFactory protected constructor() {
}
}
}

/** for testing purposes */
protected open fun runAsync(runnable: () -> Unit) {
ApplicationManager.getApplication().executeOnPooledThread(runnable)
}

/** for testing purposes */
protected open fun runInUI(runnable: () -> Unit) {
if (ApplicationManager.getApplication().isDispatchThread) {
runnable.invoke()
} else {
ApplicationManager.getApplication().invokeLater(runnable)
}
}

/* for testing purposes */
protected open fun getTelemetryMessageBuilder(): TelemetryMessageBuilder {
return TelemetryService.instance;
}
}

0 comments on commit 8a91c04

Please sign in to comment.