Skip to content

Commit 86bdd98

Browse files
authored
Merge pull request #2255 from digma-ai/collect-docker-container-logs
collect-docker-container-logs Closes #2236
2 parents 146c999 + f71b429 commit 86bdd98

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/docker/DockerService.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.digma.intellij.plugin.docker
22

33
import com.intellij.execution.configurations.GeneralCommandLine
4+
import com.intellij.execution.process.ProcessOutput
45
import com.intellij.execution.util.ExecUtil
56
import com.intellij.openapi.application.ApplicationManager
67
import com.intellij.openapi.components.Service
@@ -92,6 +93,35 @@ class DockerService {
9293
}
9394

9495

96+
97+
fun collectDigmaContainerLog(): String {
98+
try {
99+
100+
if (!isInstalled(DOCKER_COMMAND)) {
101+
return "could not find docker command"
102+
}
103+
104+
val dockerCmd = getDockerCommand()
105+
106+
val getContainerIdCommand = GeneralCommandLine(dockerCmd, "ps", "--filter", "name=digma-compound", "--format", "{{.ID}}")
107+
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
108+
109+
val containerId = ExecUtil.execAndReadLine(getContainerIdCommand)
110+
111+
val getLogCommand = GeneralCommandLine(dockerCmd, "logs", "--tail", "1000", "$containerId")
112+
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
113+
114+
val processOutput: ProcessOutput = ExecUtil.execAndGetOutput(getLogCommand)
115+
return processOutput.toString()
116+
117+
} catch (ex: Exception) {
118+
Log.warnWithException(logger, ex, "Failed in collectDigmaContainerLog")
119+
ErrorReporter.getInstance().reportError("DockerService.collectDigmaContainerLog", ex)
120+
return "could not collect docker container log because: $ex"
121+
}
122+
}
123+
124+
95125
fun installEngine(project: Project, resultTask: Consumer<String>) {
96126
installationInProgress = true
97127

@@ -421,4 +451,6 @@ class DockerService {
421451
resultTask.accept(errorMsg)
422452
}
423453

454+
455+
424456
}

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/JCefComponent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private constructor(
9999
Backgroundable.executeOnPooledThread {
100100
try {
101101
sendUserInfoMessage(jbCefBrowser.cefBrowser, DigmaDefaultAccountHolder.getInstance().account?.userId, project)
102-
val status = service<DockerService>().getCurrentDigmaInstallationStatusOnConnectionLost()
102+
val status = service<DockerService>().getActualRunningEngine(project)
103103
updateDigmaEngineStatus(jbCefBrowser.cefBrowser, status)
104104
sendBackendAboutInfo(jbCefBrowser.cefBrowser, project)
105105
} catch (e: Throwable) {
@@ -199,7 +199,7 @@ private constructor(
199199
sendIsMicrometerProject(jbCefBrowser.cefBrowser, SpringBootMicrometerConfigureDepsService.isSpringBootWithMicrometer())
200200
sendIsJaegerButtonEnabledMessage(jbCefBrowser.cefBrowser)
201201
sendBackendAboutInfo(jbCefBrowser.cefBrowser, project)
202-
val status = service<DockerService>().getCurrentDigmaInstallationStatusOnConnectionLost()
202+
val status = service<DockerService>().getActualRunningEngine(project)
203203
updateDigmaEngineStatus(jbCefBrowser.cefBrowser, status)
204204
} catch (e: Throwable) {
205205
ErrorReporter.getInstance().reportError("JCefComponent.settingsChanged", e)

src/main/kotlin/org/digma/intellij/plugin/ui/wizard/InstallationWizardSidePanelWindowPanel.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,13 @@ fun createInstallationWizardSidePanelWindowPanel(project: Project, wizardSkipIns
286286
if (!connectionOk) {
287287
Log.log(logger::warn, "no connection after engine installation")
288288
if (success) {
289+
val log = DockerService.getInstance().collectDigmaContainerLog()
289290
ActivityMonitor.getInstance(project)
290-
.registerDigmaEngineEventError("installEngine", "No connection 2 minutes after successful engine install")
291+
.registerDigmaEngineEventError("installEngine", "No connection 2 minutes after successful engine install",
292+
mapOf(
293+
"docker log" to log
294+
)
295+
)
291296
}
292297
}
293298
val isEngineUp = connectionOk && success
@@ -409,8 +414,13 @@ fun createInstallationWizardSidePanelWindowPanel(project: Project, wizardSkipIns
409414
if (!connectionOk) {
410415
Log.log(logger::warn, "no connection after engine start")
411416
if (success) {
417+
val log = DockerService.getInstance().collectDigmaContainerLog()
412418
ActivityMonitor.getInstance(project)
413-
.registerDigmaEngineEventError("startEngine", "No connection after successful engine start")
419+
.registerDigmaEngineEventError("startEngine", "No connection 2 minutes after successful engine start",
420+
mapOf(
421+
"docker log" to log
422+
)
423+
)
414424
}
415425
}
416426

0 commit comments

Comments
 (0)