Skip to content

Commit 63ba6d0

Browse files
atduarteroboquat
authored andcommitted
Address heartbeat plugin issues
1 parent c3f4da4 commit 63ba6d0

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

components/ide/jetbrains/backend-plugin/build.gradle.kts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ repositories {
2929
}
3030

3131
dependencies {
32-
implementation(project(":supervisor-api"))
33-
implementation(project(":gitpod-protocol"))
32+
implementation(project(":supervisor-api")) {
33+
artifact {
34+
type = "jar"
35+
}
36+
}
37+
implementation(project(":gitpod-protocol")) {
38+
artifact {
39+
type = "jar"
40+
}
41+
}
3442
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
3543
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.2")
3644
implementation("io.ktor:ktor-client-core:1.6.3")
@@ -82,6 +90,10 @@ tasks {
8290
jvmTarget = "11"
8391
}
8492

93+
buildSearchableOptions {
94+
enabled = false
95+
}
96+
8597
test {
8698
useJUnitPlatform()
8799
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.ide.jetbrains.backend.listeners
6+
7+
import com.intellij.ide.ApplicationInitializedListener
8+
import com.intellij.openapi.application.ApplicationActivationListener
9+
import com.intellij.openapi.components.ServiceManager
10+
import io.gitpod.ide.jetbrains.backend.services.HeartbeatService
11+
import com.intellij.openapi.wm.IdeFrame
12+
import com.intellij.openapi.components.service
13+
14+
internal class MyApplicationActivationListener : ApplicationActivationListener {
15+
override fun applicationActivated(ideFrame: IdeFrame) {
16+
service<HeartbeatService>() // Services are not loaded if not referenced
17+
}
18+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.ktor.client.HttpClient
1010
import io.ktor.client.features.HttpTimeout
1111
import io.ktor.client.features.json.JsonFeature
1212
import io.ktor.client.request.get
13+
import io.ktor.client.features.json.JacksonSerializer
1314

1415
class ControllerStatusProvider {
1516
private val logger = logger<ControllerStatusProvider>()
@@ -19,7 +20,9 @@ class ControllerStatusProvider {
1920
@Suppress("MagicNumber")
2021
requestTimeoutMillis = 2000
2122
}
22-
install(JsonFeature)
23+
install(JsonFeature) {
24+
serializer = JacksonSerializer()
25+
}
2326
}
2427
private val cwmToken = System.getenv("CWM_HOST_STATUS_OVER_HTTP_TOKEN")
2528

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import java.util.concurrent.atomic.AtomicBoolean
1919
import java.util.concurrent.atomic.AtomicReference
2020
import kotlin.concurrent.thread
2121
import kotlin.random.Random.Default.nextInt
22+
import java.lang.Thread
2223

2324
@Service
24-
class HeartbeatService(
25-
private val fetchToken: suspend () -> String = { AuthTokenService.fetchToken() },
26-
private val controllerStatusProvider: ControllerStatusProvider = ControllerStatusProvider(),
27-
) : Disposable {
25+
class HeartbeatService() : Disposable {
2826
private val logger = logger<HeartbeatService>()
27+
private val fetchToken: suspend () -> String = { AuthTokenService.fetchToken() }
28+
private val controllerStatusProvider = ControllerStatusProvider()
2929

3030
@Suppress("MagicNumber")
3131
private val intervalInSeconds = 30
@@ -44,8 +44,10 @@ class HeartbeatService(
4444
private val closed = AtomicBoolean(false)
4545

4646
init {
47+
logger.info("Service initiated")
48+
4749
@Suppress("MagicNumber")
48-
thread(name = "gitpod-heartbeat") {
50+
thread(name = "gitpod-heartbeat", contextClassLoader = this.javaClass.classLoader) {
4951
runBlocking {
5052
while (!closed.get()) {
5153
checkActivity(intervalInSeconds + nextInt(5, 15))
@@ -56,7 +58,7 @@ class HeartbeatService(
5658
}
5759

5860
private suspend fun checkActivity(maxIntervalInSeconds: Int) {
59-
logger.debug("Checking activity")
61+
logger.info("Checking activity")
6062
val status = controllerStatusProvider.fetch()
6163
val previousStatus = this.status.getAndSet(status)
6264

@@ -85,7 +87,7 @@ class HeartbeatService(
8587
try {
8688
val s = server.get()!!
8789
s.sendHeartBeat(SendHeartBeatOptions(instanceId, wasClosed)).await()
88-
logger.debug("Heartbeat sent with wasClosed=$wasClosed")
90+
logger.info("Heartbeat sent with wasClosed=$wasClosed")
8991
} catch (e: Exception) {
9092
// If connection fails for some reason,
9193
// remove the reference to the existing server.
@@ -98,10 +100,10 @@ class HeartbeatService(
98100
/**
99101
* @throws DeploymentException
100102
* @throws IOException
101-
* @throw IllegalStateException
103+
* @throws IllegalStateException
102104
*/
103105
private suspend fun createServer(): GitpodServer {
104-
logger.debug("Creating GitpodServer")
106+
logger.info("Creating GitpodServer")
105107
val token = fetchToken()
106108
val server = ConnectionHelper().connect(uri, origin, token).server()
107109
return server

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
<!-- Product and plugin compatibility requirements -->
88
<!-- https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
99
<depends>com.intellij.modules.platform</depends>
10+
11+
<applicationListeners>
12+
<listener class="io.gitpod.ide.jetbrains.backend.listeners.MyApplicationActivationListener"
13+
topic="com.intellij.openapi.application.ApplicationActivationListener" />
14+
</applicationListeners>
1015
</idea-plugin>

0 commit comments

Comments
 (0)