-
Notifications
You must be signed in to change notification settings - Fork 5
chore: added latency tooltips on workspaces #134
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
+187
−35
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c77369b
chore: added latency tooltips on workspaces
ibetitsmike b05f081
Merge branch 'main' of github.com:coder/coder-desktop-windows into mi…
ibetitsmike 419dcb2
PR fixes
ibetitsmike d1b2c7d
added connecting state and improved the logic on tooltip generation
ibetitsmike 8fbbff0
PR review
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Security.Principal; | ||
using System.Threading.Tasks; | ||
using Coder.Desktop.App.Models; | ||
using Coder.Desktop.App.Services; | ||
|
@@ -29,6 +30,7 @@ public partial class TrayWindowViewModel : ObservableObject, IAgentExpanderHost | |
{ | ||
private const int MaxAgents = 5; | ||
private const string DefaultDashboardUrl = "https://coder.com"; | ||
private readonly TimeSpan HealthyPingThreshold = TimeSpan.FromMilliseconds(150); | ||
|
||
private readonly IServiceProvider _services; | ||
private readonly IRpcController _rpcController; | ||
|
@@ -222,10 +224,28 @@ private void UpdateFromRpcModel(RpcModel rpcModel) | |
if (string.IsNullOrWhiteSpace(fqdn)) | ||
continue; | ||
|
||
var lastHandshakeAgo = DateTime.UtcNow.Subtract(agent.LastHandshake.ToDateTime()); | ||
var connectionStatus = lastHandshakeAgo < TimeSpan.FromMinutes(5) | ||
? AgentConnectionStatus.Green | ||
: AgentConnectionStatus.Yellow; | ||
var connectionStatus = AgentConnectionStatus.Healthy; | ||
|
||
if (agent.LastHandshake != null && agent.LastHandshake.ToDateTime() != default && agent.LastHandshake.ToDateTime() < DateTime.UtcNow) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{ | ||
// For compatibility with older deployments, we assume that if the | ||
// last ping is null, the agent is healthy. | ||
var isLatencyAcceptable = agent.LastPing == null || agent.LastPing.Latency.ToTimeSpan() < HealthyPingThreshold; | ||
|
||
var lastHandshakeAgo = DateTime.UtcNow.Subtract(agent.LastHandshake.ToDateTime()); | ||
|
||
if (lastHandshakeAgo > TimeSpan.FromMinutes(5)) | ||
connectionStatus = AgentConnectionStatus.NoRecentHandshake; | ||
else if (!isLatencyAcceptable) | ||
connectionStatus = AgentConnectionStatus.Unhealthy; | ||
} | ||
else | ||
{ | ||
// If the last handshake is not correct (null, default or in the future), | ||
// we assume the agent is connecting (yellow status icon). | ||
connectionStatus = AgentConnectionStatus.Connecting; | ||
} | ||
|
||
workspacesWithAgents.Add(agent.WorkspaceId); | ||
var workspace = rpcModel.Workspaces.FirstOrDefault(w => w.Id == agent.WorkspaceId); | ||
|
||
|
@@ -236,7 +256,12 @@ private void UpdateFromRpcModel(RpcModel rpcModel) | |
_hostnameSuffixGetter.GetCachedSuffix(), | ||
connectionStatus, | ||
credentialModel.CoderUrl, | ||
workspace?.Name)); | ||
workspace?.Name, | ||
agent.LastPing?.DidP2P, | ||
agent.LastPing?.PreferredDerp, | ||
agent.LastPing?.Latency?.ToTimeSpan(), | ||
agent.LastPing?.PreferredDerpLatency?.ToTimeSpan(), | ||
agent.LastHandshake != null && agent.LastHandshake.ToDateTime() != default ? agent.LastHandshake?.ToDateTime() : null)); | ||
} | ||
|
||
// For every stopped workspace that doesn't have any agents, add a | ||
|
@@ -253,7 +278,7 @@ private void UpdateFromRpcModel(RpcModel rpcModel) | |
// conflict with any agent IDs. | ||
uuid, | ||
_hostnameSuffixGetter.GetCachedSuffix(), | ||
AgentConnectionStatus.Gray, | ||
AgentConnectionStatus.Offline, | ||
credentialModel.CoderUrl, | ||
workspace.Name)); | ||
} | ||
|
@@ -268,7 +293,7 @@ private void UpdateFromRpcModel(RpcModel rpcModel) | |
|
||
if (Agents.Count < MaxAgents) ShowAllAgents = false; | ||
|
||
var firstOnlineAgent = agents.FirstOrDefault(a => a.ConnectionStatus != AgentConnectionStatus.Gray); | ||
var firstOnlineAgent = agents.FirstOrDefault(a => a.ConnectionStatus != AgentConnectionStatus.Offline); | ||
if (firstOnlineAgent is null) | ||
_hasExpandedAgent = false; | ||
if (!_hasExpandedAgent && firstOnlineAgent is not null) | ||
|
@@ -433,7 +458,7 @@ private static bool ShouldShowDummy(Workspace workspace) | |
case Workspace.Types.Status.Stopping: | ||
case Workspace.Types.Status.Stopped: | ||
return true; | ||
// TODO: should we include and show a different color than Gray for workspaces that are | ||
// TODO: should we include and show a different color than Offline for workspaces that are | ||
// failed, canceled or deleting? | ||
default: | ||
return false; | ||
|
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a relative timestamp (i.e.
5 seconds ago
) here but I actually gotta get rid of it, so this is fine.( Have to get rid of it cause it only gets rendered once, and doesn't update on tooltip re-hovers 😦 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I check for Default and set to null in the viewmodel cause showing a made up handshake just felt wrong.