- Notifications
You must be signed in to change notification settings - Fork1
impl: support for displaying network latency#108
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
22010e1
impl: configurable network info location
fioan8922d74a1
chore: remove dead code
fioan89b96a188
impl: download ssh network stats
fioan89129a0f5
impl: allow network info dir to be configurable
fioan8946a58bd
fix: update UTs to include the network metrics configuration
fioan89c5c1850
impl: identify the PID for the SSH command
fioan898c2271c
impl: network metrics poll job
fioan895e30b60
impl: load ssh metrics from json
fioan893f2ab4f
impl: show ssh network metrics in the Settings tab
fioan89100fb9d
impl: show ssh network metrics in the Settings tab (2)
fioan8932258eb
Merge branch 'main' into support-for-displaying-network-latency
fioan89File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsCHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
56 changes: 54 additions & 2 deletionssrc/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletionssrc/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/cli/SshCommandProcessHandle.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.coder.toolbox.cli | ||
import com.coder.toolbox.CoderToolboxContext | ||
import com.coder.toolbox.sdk.v2.models.Workspace | ||
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent | ||
import kotlin.jvm.optionals.getOrNull | ||
/** | ||
* Identifies the PID for the SSH Coder command spawned by Toolbox. | ||
*/ | ||
class SshCommandProcessHandle(private val ctx: CoderToolboxContext) { | ||
/** | ||
* Finds the PID of a Coder (not the proxy command) ssh cmd associated with the specified workspace and agent. | ||
* Null is returned when no ssh command process was found. | ||
* | ||
* Implementation Notes: | ||
* An iterative DFS approach where we start with Toolbox's direct children, grep the command | ||
* and if nothing is found we continue with the processes children. Toolbox spawns an ssh command | ||
* as a separate command which in turns spawns another child for the proxy command. | ||
*/ | ||
fun findByWorkspaceAndAgent(ws: Workspace, agent: WorkspaceAgent): Long? { | ||
val stack = ArrayDeque<ProcessHandle>(ProcessHandle.current().children().toList()) | ||
while (stack.isNotEmpty()) { | ||
val processHandle = stack.removeLast() | ||
val cmdLine = processHandle.info().commandLine().getOrNull() | ||
ctx.logger.debug("SSH command PID: ${processHandle.pid()} Command: $cmdLine") | ||
if (cmdLine != null && cmdLine.isSshCommandFor(ws, agent)) { | ||
ctx.logger.debug("SSH command with PID: ${processHandle.pid()} and Command: $cmdLine matches ${ws.name}.${agent.name}") | ||
return processHandle.pid() | ||
} else { | ||
stack.addAll(processHandle.children().toList()) | ||
} | ||
} | ||
return null | ||
} | ||
private fun String.isSshCommandFor(ws: Workspace, agent: WorkspaceAgent): Boolean { | ||
// usage-app is present only in the ProxyCommand | ||
return !this.contains("--usage-app=jetbrains") && this.contains("${ws.name}.${agent.name}") | ||
} | ||
} |
49 changes: 49 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/sdk/v2/models/NetworkMetrics.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.coder.toolbox.sdk.v2.models | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import java.text.DecimalFormat | ||
private val formatter = DecimalFormat("#.00") | ||
/** | ||
* Coder ssh network metrics. All properties are optional | ||
* because Coder Connect only populates `using_coder_connect` | ||
* while p2p doesn't populate this property. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class NetworkMetrics( | ||
@Json(name = "p2p") | ||
val p2p: Boolean?, | ||
@Json(name = "latency") | ||
val latency: Double?, | ||
@Json(name = "preferred_derp") | ||
val preferredDerp: String?, | ||
@Json(name = "derp_latency") | ||
val derpLatency: Map<String, Double>?, | ||
@Json(name = "upload_bytes_sec") | ||
val uploadBytesSec: Long?, | ||
@Json(name = "download_bytes_sec") | ||
val downloadBytesSec: Long?, | ||
@Json(name = "using_coder_connect") | ||
val usingCoderConnect: Boolean? | ||
) { | ||
fun toPretty(): String { | ||
if (usingCoderConnect == true) { | ||
return "You're connected using Coder Connect" | ||
} | ||
return if (p2p == true) { | ||
"Direct (${formatter.format(latency)}ms). You're connected peer-to-peer" | ||
} else { | ||
val derpLatency = derpLatency!![preferredDerp] | ||
val workspaceLatency = latency!!.minus(derpLatency!!) | ||
"You ↔ $preferredDerp (${formatter.format(derpLatency)}ms) ↔ Workspace (${formatter.format(workspaceLatency)}ms). You are connected through a relay" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/settings/ReadOnlyCoderSettings.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/store/CoderSettingsStore.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/store/StoreKeys.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/views/CoderSettingsPage.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionssrc/main/resources/localization/defaultMessages.po
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletionsrc/test/kotlin/com/coder/toolbox/cli/CoderCLIManagerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.