From 581ff68b0648fdb012d41e00aabc807b29945f7c Mon Sep 17 00:00:00 2001 From: Andrea Falzetti Date: Wed, 31 Aug 2022 23:25:54 +0000 Subject: [PATCH] feat(jetbrains): show workspace class in backend control center --- .../gitpod/jetbrains/remote/GitpodManager.kt | 5 +- .../remote/GitpodMetricControlProvider.kt | 63 ++++++++++++++++--- .../jetbrains/remote/GitpodMetricProvider.kt | 22 ++++++- .../src/main/resources/META-INF/plugin.xml | 24 ++++--- 4 files changed, 94 insertions(+), 20 deletions(-) diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodManager.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodManager.kt index 46a51be5706f17..4204ba401487ff 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodManager.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodManager.kt @@ -223,14 +223,16 @@ class GitpodManager : Disposable { } } + var infoResponse: WorkspaceInfoResponse? = null val pendingInfo = CompletableFuture() + 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()) @@ -391,5 +393,4 @@ class GitpodManager : Disposable { metricsJob.cancel() } } - } diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricControlProvider.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricControlProvider.kt index 59957e844276b1..8f03b51c0962eb 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricControlProvider.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricControlProvider.kt @@ -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.* import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.reactive.Property import com.jetbrains.rdserver.diagnostics.BackendDiagnosticsService @@ -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) } } } @@ -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("") @@ -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("") diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricProvider.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricProvider.kt index 6d0e48c93a6445..7381466cd681bb 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricProvider.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodMetricProvider.kt @@ -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 @@ -19,6 +19,7 @@ class GitpodMetricProvider: MetricProvider { override val id: String = "gitpodMetricsProvider" override fun getMetrics(): Map { val resourceStatus = manager.resourceStatus + val info = manager.infoResponse val cpuUsed = resourceStatus?.cpu?.used?.toDouble() ?: 0.0 val cpuTotal = resourceStatus?.cpu?.limit?.toDouble() ?: 0.0 @@ -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) ) } @@ -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}" + } } diff --git a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml index 89315499d0c00c..7b4cb9fd5cf5b8 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml +++ b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml @@ -22,18 +22,26 @@ - + - + - + - - - - - + + + + +