Skip to content

jb: java perf monitoring #9796

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 3 commits into from
May 18, 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
1 change: 1 addition & 0 deletions components/ide/jetbrains/backend-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
type = "jar"
}
}
implementation("io.prometheus:simpleclient_pushgateway:0.15.0")
compileOnly("javax.websocket:javax.websocket-api:1.1")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.18.1")
testImplementation(kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import io.grpc.stub.ClientCallStreamObserver
import io.grpc.stub.ClientResponseObserver
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.Gauge
import io.prometheus.client.exporter.PushGateway
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.future.await
Expand All @@ -52,13 +55,48 @@ class GitpodManager : Disposable {
}

val devMode = System.getenv("JB_DEV").toBoolean()
private val backendKind = System.getenv("JETBRAINS_GITPOD_BACKEND_KIND") ?: "unknown"
private val backendQualifier = System.getenv("JETBRAINS_BACKEND_QUALIFIER") ?: "unknown"

private val lifetime = Lifetime.Eternal.createNested()

override fun dispose() {
lifetime.terminate()
}

init {
val monitoringJob = GlobalScope.launch {
if (application.isHeadlessEnvironment) {
return@launch
}
val pg = PushGateway("localhost:22999")
val registry = CollectorRegistry()
val allocatedGauge = Gauge.build()
.name("gitpod_jb_backend_memory_max_bytes")
.help("Total allocated memory of JB backend in bytes.")
.labelNames("product", "qualifier")
.register(registry)
val usedGauge = Gauge.build()
.name("gitpod_jb_backend_memory_used_bytes")
.help("Used memory of JB backend in bytes.")
.labelNames("product", "qualifier")
.register(registry)
while(isActive) {
val totalMemory = Runtime.getRuntime().totalMemory()
allocatedGauge.labels(backendKind, backendQualifier).set(totalMemory.toDouble())
val usedMemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
usedGauge.labels(backendKind, backendQualifier).set(usedMemory.toDouble())
try {
pg.push(registry, "jb_backend")
} catch (t: Throwable) {
thisLogger().error("gitpod: failed to push monitoring metrics:", t)
}
delay(5000)
}
}
lifetime.onTerminationOrNow { monitoringJob.cancel() }
}

init {
GlobalScope.launch {
if (application.isHeadlessEnvironment) {
Expand Down Expand Up @@ -269,4 +307,4 @@ class GitpodManager : Disposable {
serverJob.cancel()
}
}
}
}
24 changes: 22 additions & 2 deletions components/ide/jetbrains/image/status/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ func main() {
}
}

go run(wsInfo)
err = configureXmx(alias)
if err != nil {
log.WithError(err).Error("failed to configure backend Xmx")
}
go run(wsInfo, alias)

http.HandleFunc("/joinLink", func(w http.ResponseWriter, r *http.Request) {
backendPort := r.URL.Query().Get("backendPort")
Expand Down Expand Up @@ -220,11 +224,12 @@ func resolveWorkspaceInfo(ctx context.Context) (*supervisor.ContentStatusRespons
return nil, nil, errors.New("failed with attempt 10 times")
}

func run(wsInfo *supervisor.WorkspaceInfoResponse) {
func run(wsInfo *supervisor.WorkspaceInfoResponse, alias string) {
var args []string
args = append(args, "run")
args = append(args, wsInfo.GetCheckoutLocation())
cmd := remoteDevServerCmd(args)
cmd.Env = append(cmd.Env, "JETBRAINS_GITPOD_BACKEND_KIND="+alias)
workspaceUrl, err := url.Parse(wsInfo.WorkspaceUrl)
if err == nil {
cmd.Env = append(cmd.Env, "JETBRAINS_GITPOD_WORKSPACE_HOST="+workspaceUrl.Hostname())
Expand Down Expand Up @@ -258,6 +263,21 @@ func remoteDevServerCmd(args []string) *exec.Cmd {
return cmd
}

func configureXmx(alias string) error {
xmx := os.Getenv(strings.ToUpper(alias) + "_XMX")
if xmx == "" {
return nil
}
launcherPath := "/ide-desktop/backend/plugins/remote-dev-server/bin/launcher.sh"
content, err := ioutil.ReadFile(launcherPath)
if err != nil {
return err
}
// by default remote dev already set -Xmx2048m, see /ide-desktop/backend/plugins/remote-dev-server/bin/launcher.sh
newContent := strings.Replace(string(content), "-Xmx2048m", "-Xmx"+xmx, 1)
return ioutil.WriteFile(launcherPath, []byte(newContent), 0)
}

/**
{
"buildNumber" : "221.4994.44",
Expand Down
2 changes: 2 additions & 0 deletions components/supervisor-api/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/gitpod-io/generated_code_dependencies

go 1.18

require google.golang.org/protobuf v1.28.0 // indirect
6 changes: 6 additions & 0 deletions components/supervisor-api/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Loading