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

feat(jetbrains): show workspace class in backend control center #12568

Merged
merged 1 commit into from
Sep 5, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,16 @@ class GitpodManager : Disposable {
}
}

var infoResponse: WorkspaceInfoResponse? = null
val pendingInfo = CompletableFuture<WorkspaceInfoResponse>()

private val infoJob = GlobalScope.launch {
if (application.isHeadlessEnvironment) {
return@launch
}
try {
// TODO(ak) replace retry with proper handling of grpc errors
val infoResponse = retry(3) {
infoResponse = retry(3) {
InfoServiceGrpc
.newFutureStub(supervisorChannel)
.workspaceInfo(Info.WorkspaceInfoRequest.newBuilder().build())
Expand Down Expand Up @@ -391,5 +393,4 @@ class GitpodManager : Disposable {
metricsJob.cancel()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
package io.gitpod.jetbrains.remote

import com.jetbrains.ide.model.uiautomation.BeControl
import com.jetbrains.rd.ui.bedsl.dsl.VerticalGridBuilder
import com.jetbrains.rd.ui.bedsl.dsl.verticalGrid
import com.jetbrains.rd.ui.bedsl.dsl.*
andreafalzetti marked this conversation as resolved.
Show resolved Hide resolved
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.reactive.Property
import com.jetbrains.rdserver.diagnostics.BackendDiagnosticsService
Expand All @@ -17,10 +16,60 @@ import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.perform
class GitpodMetricControlProvider : MetricControlProvider {
override val id: String = "gitpodMetricsControl"
override fun getControl(lifetime: Lifetime): BeControl {
val backendDiagnosticsService = BackendDiagnosticsService.Companion.getInstance()

return verticalGrid {
val backendDiagnosticsService = BackendDiagnosticsService.Companion.getInstance()
createCpuControl(this, backendDiagnosticsService, lifetime)
createMemoryControl(this, backendDiagnosticsService, lifetime)
row {
horizontalGrid {
column {
label("Workspace")
}
}
}
createWorkspaceHeaderRow(this, backendDiagnosticsService, lifetime)
row {
verticalGrid {
createCpuControl(this, backendDiagnosticsService, lifetime)
createMemoryControl(this, backendDiagnosticsService, lifetime)
}.withMargin { margin(0, 15, 0, 25) }
}
row {
horizontalGrid {
column {
label("Shared Node Resources")
}
}.withMargin { margin(0, 0, 0, 15) }.withHelpTooltip("Shared Node Resources", "The shared metrics represent the used and available resources of the cluster node on which your workspace is running")
}
}
}

private fun createWorkspaceHeaderRow(ctx: VerticalGridBuilder, backendDiagnosticsService: BackendDiagnosticsService, lifetime: Lifetime) {
val labelProperty = Property("")

val workspaceClassMetric = backendDiagnosticsService.getMetric("gitpod_workspace_class")
val workspaceClass = workspaceClassMetric.toString()

fun updateLabel() {
if (workspaceClass != "") {
labelProperty.set(workspaceClass)
}
}
updateLabel()

workspaceClassMetric.valueProperty.change.advise(lifetime) {
updateLabel()
}

if (workspaceClass == "") {
return
}

return ctx.row {
horizontalGrid {
column {
label(workspaceClass)
}
}.withMargin { margin(0, 15, 0, 0) }
}
}

Expand All @@ -29,7 +78,7 @@ class GitpodMetricControlProvider : MetricControlProvider {
val cpuTotal = backendDiagnosticsService.getMetric("gitpod_workspace_cpu_total")
val cpuPercentage = backendDiagnosticsService.getMetric("gitpod_workspace_cpu_percentage")
val cpuPercentageProperty = Property("$cpuPercentage %")
val label = "Workspace CPU"
val label = "CPU"
val progressBar = createProgressBar(lifetime, cpuPercentage.valueProperty, cpuPercentageProperty)
val labelProperty = Property("")

Expand All @@ -51,7 +100,7 @@ class GitpodMetricControlProvider : MetricControlProvider {
val memoryTotal = backendDiagnosticsService.getMetric("gitpod_workspace_memory_total")
val memoryPercentage = backendDiagnosticsService.getMetric("gitpod_workspace_memory_percentage")
val memoryPercentageProperty = Property("$memoryPercentage %")
val label = "Workspace Memory"
val label = "Memory"
val progressBar = createProgressBar(lifetime, memoryPercentage.valueProperty, memoryPercentageProperty)
val labelProperty = Property("")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.Metric
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricType
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricsStatus
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.providers.MetricProvider
import io.gitpod.jetbrains.remote.GitpodManager
import io.gitpod.supervisor.api.Info.WorkspaceInfoResponse.WorkspaceClass
import io.gitpod.supervisor.api.Status.ResourceStatusSeverity
import kotlin.math.roundToInt

Expand All @@ -19,6 +19,7 @@ class GitpodMetricProvider: MetricProvider {
override val id: String = "gitpodMetricsProvider"
override fun getMetrics(): Map<String, Metric> {
val resourceStatus = manager.resourceStatus
val info = manager.infoResponse

val cpuUsed = resourceStatus?.cpu?.used?.toDouble() ?: 0.0
val cpuTotal = resourceStatus?.cpu?.limit?.toDouble() ?: 0.0
Expand All @@ -28,17 +29,20 @@ class GitpodMetricProvider: MetricProvider {

val memoryUsed = convertBytesToGB(resourceStatus?.memory?.used ?: 0)
val memoryTotal = convertBytesToGB(resourceStatus?.memory?.limit ?: 0)
val memorySeverity = resourceStatus?.memory?.severity ?:ResourceStatusSeverity.normal
val memorySeverity = resourceStatus?.memory?.severity ?: ResourceStatusSeverity.normal
val memoryPercentage = (memoryUsed / memoryTotal) * 100
val memoryStatus = getSeverityStatus(memorySeverity)

val workspaceClass = formatWorkspaceClass(info?.workspaceClass)

return mapOf(
"gitpod_workspace_cpu_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuUsed, 0)),
"gitpod_workspace_cpu_total" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuTotal, 0)),
"gitpod_workspace_cpu_percentage" to Metric(MetricType.PERFORMANCE, cpuStatus, (cpuPercentage * 1000.0).roundToInt() / 1000.0),
"gitpod_workspace_memory_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(memoryUsed, 2)),
"gitpod_workspace_memory_total" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(memoryTotal, 2)),
"gitpod_workspace_memory_percentage" to Metric(MetricType.PERFORMANCE, memoryStatus, (memoryPercentage * 1000.0).roundToInt() / 1000.0)
"gitpod_workspace_memory_percentage" to Metric(MetricType.PERFORMANCE, memoryStatus, (memoryPercentage * 1000.0).roundToInt() / 1000.0),
"gitpod_workspace_class" to Metric(MetricType.OTHER, MetricsStatus.NORMAL, workspaceClass)
)
}

Expand All @@ -59,4 +63,16 @@ class GitpodMetricProvider: MetricProvider {
MetricsStatus.NORMAL
}
}

private fun formatWorkspaceClass(workspaceClass: WorkspaceClass?): String {
if (workspaceClass == null || workspaceClass.displayName == "") {
return ""
}

if (workspaceClass.description == "") {
return workspaceClass.displayName
}

return "${workspaceClass.displayName}: ${workspaceClass.description}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
</dependencies>

<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.services.HeartbeatService" preload="true"/>
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.services.HeartbeatService"
andreafalzetti marked this conversation as resolved.
Show resolved Hide resolved
preload="true"/>
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.GitpodManager" preload="true"/>
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.GitpodPortsService" preload="true"/>
<notificationGroup id="Gitpod Notifications" displayType="BALLOON" isLogByDefault="false" />
<notificationGroup id="Gitpod Notifications" displayType="BALLOON" isLogByDefault="false"/>
<httpRequestHandler implementation="io.gitpod.jetbrains.remote.GitpodCLIService"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodClientProjectSessionTracker" client="guest" preload="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodClientProjectSessionTracker"
client="guest" preload="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodProjectManager" preload="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodTerminalService" client="guest" preload="true"/>
<gateway.customization.name implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
<gateway.customization.performance id="gitpodMetricsControl" order="before cpuControl" implementation="io.gitpod.jetbrains.remote.GitpodMetricControlProvider"/>
<gateway.customization.metrics id="gitpodMetricsProvider" implementation="io.gitpod.jetbrains.remote.GitpodMetricProvider" />
<registryKey key="gitpod.autoJdk.disabled" defaultValue="false" description="Disable auto-detection of JDK for the project and its modules" restartRequired="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodTerminalService" client="guest"
preload="true"/>
<gateway.customization.name
implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
<gateway.customization.performance id="gitpodMetricsControl" order="before cpuControl"
implementation="io.gitpod.jetbrains.remote.GitpodMetricControlProvider"/>
<gateway.customization.metrics id="gitpodMetricsProvider"
implementation="io.gitpod.jetbrains.remote.GitpodMetricProvider"/>
<registryKey key="gitpod.autoJdk.disabled" defaultValue="false"
description="Disable auto-detection of JDK for the project and its modules"
restartRequired="true"/>
</extensions>

</idea-plugin>