Skip to content

feat(supervisor): add resource status severity #12157

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

Merged
merged 1 commit into from
Aug 17, 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
14 changes: 7 additions & 7 deletions components/gitpod-cli/cmd/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

supervisor_helper "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
"github.com/gitpod-io/gitpod/supervisor/api"
supervisor "github.com/gitpod-io/gitpod/supervisor/api"

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

if !noColor && utils.ColorsEnabled() {
cpuColor := getColor(cpuFraction)
memoryColor := getColor(memFraction)
cpuColor := getColor(workspaceResources.Cpu.Severity)
memoryColor := getColor(workspaceResources.Memory.Severity)
colors = []tablewriter.Colors{{cpuColor}, {memoryColor}}
}

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

// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
func getColor(value int64) int {
switch {
case value >= 95:
func getColor(severity api.ResourceStatusSeverity) int {
switch severity {
case api.ResourceStatusSeverity_danger:
return tablewriter.FgRedColor
case value >= 80:
case api.ResourceStatusSeverity_warning:
return tablewriter.FgYellowColor
default:
return tablewriter.FgHiGreenColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.Status.ResourceStatusSeverity
import kotlin.math.roundToInt

class GitpodMetricProvider: MetricProvider {
Expand All @@ -21,29 +22,15 @@ class GitpodMetricProvider: MetricProvider {

val cpuUsed = resourceStatus?.cpu?.used?.toDouble() ?: 0.0
val cpuTotal = resourceStatus?.cpu?.limit?.toDouble() ?: 0.0
val cpuSeverity = resourceStatus?.cpu?.severity ?: ResourceStatusSeverity.normal
val cpuPercentage = (cpuUsed / cpuTotal) * 100

// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
val cpuStatus = if (cpuPercentage >= 95) {
MetricsStatus.DANGER
} else if (cpuPercentage >= 80) {
MetricsStatus.WARNING
} else {
MetricsStatus.NORMAL
}
val cpuStatus = getSeverityStatus(cpuSeverity)

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

// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075
val memoryStatus = if (memoryPercentage >= 95) {
MetricsStatus.DANGER
} else if (memoryPercentage >= 80) {
MetricsStatus.WARNING
} else {
MetricsStatus.NORMAL
}
val memoryStatus = getSeverityStatus(memorySeverity)

return mapOf(
"gitpod_workspace_cpu_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuUsed, 0)),
Expand All @@ -62,4 +49,14 @@ class GitpodMetricProvider: MetricProvider {
private fun roundTo(number: Double, decimals: Int) : String {
return String.format("%.${decimals}f", number)
}

private fun getSeverityStatus(severity: ResourceStatusSeverity) : MetricsStatus {
return if (severity == ResourceStatusSeverity.danger) {
MetricsStatus.DANGER
} else if (severity == ResourceStatusSeverity.warning) {
MetricsStatus.WARNING
} else {
MetricsStatus.NORMAL
}
}
}
2 changes: 1 addition & 1 deletion components/supervisor-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local_java_protoc() {
--java_out=java/src/main/java \
./*.proto
# remove trailing spaces
find components/supervisor-api/java/src/main/java/io/gitpod/supervisor/api -maxdepth 1 -name "*.java" -exec sed -i -e "s/[[:space:]]*$//" {} \;
find "${COMPONENTS_DIR}"/supervisor-api/java/src/main/java/io/gitpod/supervisor/api -maxdepth 1 -name "*.java" -exec sed -i -e "s/[[:space:]]*$//" {} \;
# revert Java reserved keywords
sed -i 's/private_visibility = 0;/private = 0;/g' status.proto
sed -i 's/public_visibility = 1;/public = 1;/g' status.proto
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor-api/go/control.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/supervisor-api/go/control_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/supervisor-api/go/info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/supervisor-api/go/info_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/supervisor-api/go/notification.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/supervisor-api/go/notification_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/supervisor-api/go/port.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/supervisor-api/go/port_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading