Skip to content

Commit

Permalink
feat(jetbrains): show workspace class in backend control center
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Falzetti committed Sep 1, 2022
1 parent 74a9b97 commit 3395a05
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
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 @@ -7,20 +7,69 @@ 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.*
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.reactive.Property
import com.jetbrains.rdserver.diagnostics.BackendDiagnosticsService
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.MetricControlProvider
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.createProgressBar
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.createProgressRow
import com.jetbrains.rd.util.reactive.Property

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")
}
}.withMargin { margin(0, 0, 0, 10) }
}
createWorkspaceClassControlRow(this, backendDiagnosticsService, lifetime)
row {
verticalGrid {
createCpuControl(this, backendDiagnosticsService, lifetime)
createMemoryControl(this, backendDiagnosticsService, lifetime)
}.withMargin { margin(0, 0, 0, 10) }
}
row {
horizontalGrid {
column {
label("Node")
}
}.withMargin { margin(0, 0, 0, 10) }
}
}
}

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

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

if (workspaceClass == "") {
return
}

fun updateLabel() {
labelProperty.set(workspaceClass)
}
updateLabel()

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

return ctx.row {
horizontalGrid {
column {
label("Class: $workspaceClass")
}
}.withMargin { margin(0, 0, 0, 10) }
}
}

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}"
}
}

0 comments on commit 3395a05

Please sign in to comment.