Skip to content

Commit 3f2ab4f

Browse files
committed
impl: show ssh network metrics in the Settings tab
Under the "Additional environment information". Unfortunately it was not possible any other way. The description property is modifiable however Toolbox renders the description label only as long as the SSH connection is not established. As soon as an ssh connection is running the description label is used as mechanism to notify users about available IDE updates. It also appears that we can't have any other extra tab, other than "Tools", "Projects" and "Settings". There is a secondary information attribute API, but it is not usable to show recurring metrics info because it can only be configured once, it is not a mutable field. The best effort was to add the information in the Settings page, and it is worth highlighting that the metrics are only refreshed when user either: - switches between tabs - expands/collapses teh "Additional environment information" section. There is no programmatic mechanism to notify the information in the Settings page changed
1 parent 5e30b60 commit 3f2ab4f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.coder.toolbox.util.waitForFalseWithTimeout
1313
import com.coder.toolbox.util.withPath
1414
import com.coder.toolbox.views.Action
1515
import com.coder.toolbox.views.EnvironmentView
16+
import com.jetbrains.toolbox.api.localization.LocalizableString
1617
import com.jetbrains.toolbox.api.remoteDev.AfterDisconnectHook
1718
import com.jetbrains.toolbox.api.remoteDev.BeforeConnectionHook
1819
import com.jetbrains.toolbox.api.remoteDev.DeleteEnvironmentConfirmationParams
@@ -52,15 +53,14 @@ class CoderRemoteEnvironment(
5253
private var wsRawStatus = WorkspaceAndAgentStatus.from(workspace, agent)
5354

5455
override var name: String = "${workspace.name}.${agent.name}"
55-
5656
private var isConnected: MutableStateFlow<Boolean> = MutableStateFlow(false)
5757
override val connectionRequest: MutableStateFlow<Boolean> = MutableStateFlow(false)
5858

5959
override val state: MutableStateFlow<RemoteEnvironmentState> =
6060
MutableStateFlow(wsRawStatus.toRemoteEnvironmentState(context))
6161
override val description: MutableStateFlow<EnvironmentDescription> =
6262
MutableStateFlow(EnvironmentDescription.General(context.i18n.pnotr(workspace.templateDisplayName)))
63-
63+
override val additionalEnvironmentInformation: MutableMap<LocalizableString, String> = mutableMapOf()
6464
override val actionsList: MutableStateFlow<List<ActionDescription>> = MutableStateFlow(getAvailableActions())
6565

6666
private val networkMetricsMarshaller = Moshi.Builder().build().adapter(NetworkMetrics::class.java)
@@ -175,7 +175,12 @@ class CoderRemoteEnvironment(
175175
}
176176
context.logger.debug("Loading metrics from ${metricsFile.absolutePath} for $id")
177177
try {
178-
context.logger.debug("$id metrics: ${networkMetricsMarshaller.fromJson(metricsFile.readText())}")
178+
val metrics = networkMetricsMarshaller.fromJson(metricsFile.readText())
179+
if (metrics == null) {
180+
return@launch
181+
}
182+
context.logger.debug("$id metrics: $metrics")
183+
additionalEnvironmentInformation.put(context.i18n.ptrl("Network Metrics"), metrics.toPretty())
179184
} catch (e: Exception) {
180185
context.logger.error(
181186
e,

src/main/kotlin/com/coder/toolbox/sdk/v2/models/NetworkMetrics.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ data class NetworkMetrics(
3030

3131
@Json(name = "using_coder_connect")
3232
val usingCoderConnect: Boolean?
33-
)
33+
) {
34+
fun toPretty(): String {
35+
return if (p2p == true) {
36+
"Direct (${latency}ms) \u00B7 Download \u2193 $downloadBytesSec b/s \u00B7 Upload \u2191 $uploadBytesSec b/s"
37+
} else {
38+
"$preferredDerp (${latency}ms) \u00B7 Download \u2193 $downloadBytesSec b/s \u00B7 Upload \u2191 $uploadBytesSec b/s"
39+
}
40+
}
41+
}

src/main/resources/localization/defaultMessages.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,7 @@ msgid "SSH proxy log directory"
131131
msgstr ""
132132

133133
msgid "SSH network metrics directory"
134+
msgstr ""
135+
136+
msgid "Network Metrics"
134137
msgstr ""

0 commit comments

Comments
 (0)