Skip to content

Commit 131aa35

Browse files
Andrea Falzettiroboquat
Andrea Falzetti
authored andcommitted
feat(supervisor): add resource status severity
1 parent 6ce6daa commit 131aa35

File tree

26 files changed

+975
-648
lines changed

26 files changed

+975
-648
lines changed

components/gitpod-cli/cmd/top.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
supervisor_helper "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
15+
"github.com/gitpod-io/gitpod/supervisor/api"
1516
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
1617

1718
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
@@ -35,8 +36,8 @@ func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) {
3536
colors := []tablewriter.Colors{}
3637

3738
if !noColor && utils.ColorsEnabled() {
38-
cpuColor := getColor(cpuFraction)
39-
memoryColor := getColor(memFraction)
39+
cpuColor := getColor(workspaceResources.Cpu.Severity)
40+
memoryColor := getColor(workspaceResources.Memory.Severity)
4041
colors = []tablewriter.Colors{{cpuColor}, {memoryColor}}
4142
}
4243

@@ -45,12 +46,11 @@ func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) {
4546
table.Render()
4647
}
4748

48-
// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
49-
func getColor(value int64) int {
50-
switch {
51-
case value >= 95:
49+
func getColor(severity api.ResourceStatusSeverity) int {
50+
switch severity {
51+
case api.ResourceStatusSeverity_danger:
5252
return tablewriter.FgRedColor
53-
case value >= 80:
53+
case api.ResourceStatusSeverity_warning:
5454
return tablewriter.FgYellowColor
5555
default:
5656
return tablewriter.FgHiGreenColor

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodMetricProvider.kt

+15-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricType
1010
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricsStatus
1111
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.providers.MetricProvider
1212
import io.gitpod.jetbrains.remote.GitpodManager
13+
import io.gitpod.supervisor.api.Status.ResourceStatusSeverity
1314
import kotlin.math.roundToInt
1415

1516
class GitpodMetricProvider: MetricProvider {
@@ -21,29 +22,15 @@ class GitpodMetricProvider: MetricProvider {
2122

2223
val cpuUsed = resourceStatus?.cpu?.used?.toDouble() ?: 0.0
2324
val cpuTotal = resourceStatus?.cpu?.limit?.toDouble() ?: 0.0
25+
val cpuSeverity = resourceStatus?.cpu?.severity ?: ResourceStatusSeverity.normal
2426
val cpuPercentage = (cpuUsed / cpuTotal) * 100
25-
26-
// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
27-
val cpuStatus = if (cpuPercentage >= 95) {
28-
MetricsStatus.DANGER
29-
} else if (cpuPercentage >= 80) {
30-
MetricsStatus.WARNING
31-
} else {
32-
MetricsStatus.NORMAL
33-
}
27+
val cpuStatus = getSeverityStatus(cpuSeverity)
3428

3529
val memoryUsed = convertBytesToGB(resourceStatus?.memory?.used ?: 0)
3630
val memoryTotal = convertBytesToGB(resourceStatus?.memory?.limit ?: 0)
31+
val memorySeverity = resourceStatus?.memory?.severity ?:ResourceStatusSeverity.normal
3732
val memoryPercentage = (memoryUsed / memoryTotal) * 100
38-
39-
// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
40-
val memoryStatus = if (memoryPercentage >= 95) {
41-
MetricsStatus.DANGER
42-
} else if (memoryPercentage >= 80) {
43-
MetricsStatus.WARNING
44-
} else {
45-
MetricsStatus.NORMAL
46-
}
33+
val memoryStatus = getSeverityStatus(memorySeverity)
4734

4835
return mapOf(
4936
"gitpod_workspace_cpu_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuUsed, 0)),
@@ -62,4 +49,14 @@ class GitpodMetricProvider: MetricProvider {
6249
private fun roundTo(number: Double, decimals: Int) : String {
6350
return String.format("%.${decimals}f", number)
6451
}
52+
53+
private fun getSeverityStatus(severity: ResourceStatusSeverity) : MetricsStatus {
54+
return if (severity == ResourceStatusSeverity.danger) {
55+
MetricsStatus.DANGER
56+
} else if (severity == ResourceStatusSeverity.warning) {
57+
MetricsStatus.WARNING
58+
} else {
59+
MetricsStatus.NORMAL
60+
}
61+
}
6562
}

components/supervisor-api/generate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ local_java_protoc() {
5353
--java_out=java/src/main/java \
5454
./*.proto
5555
# remove trailing spaces
56-
find components/supervisor-api/java/src/main/java/io/gitpod/supervisor/api -maxdepth 1 -name "*.java" -exec sed -i -e "s/[[:space:]]*$//" {} \;
56+
find "${COMPONENTS_DIR}"/supervisor-api/java/src/main/java/io/gitpod/supervisor/api -maxdepth 1 -name "*.java" -exec sed -i -e "s/[[:space:]]*$//" {} \;
5757
# revert Java reserved keywords
5858
sed -i 's/private_visibility = 0;/private = 0;/g' status.proto
5959
sed -i 's/public_visibility = 1;/public = 1;/g' status.proto

components/supervisor-api/go/control.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/control_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/info.pb.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/info_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/notification.pb.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/notification_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/port.pb.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/port_grpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)