Skip to content

Commit 419dcb2

Browse files
committed
PR fixes
1 parent b05f081 commit 419dcb2

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

App/ViewModels/AgentViewModel.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public AgentViewModel Create(IAgentExpanderHost expanderHost, Uuid id, string fu
4545
string? workspaceName, bool? didP2p, string? preferredDerp, TimeSpan? latency, TimeSpan? preferredDerpLatency,
4646
DateTime? lastHandshake)
4747
{
48-
System.Diagnostics.Debug.WriteLine($"Creating agent: {didP2p} {preferredDerp} {latency} {lastHandshake}");
4948
return new AgentViewModel(childLogger, coderApiClientFactory, credentialManager, agentAppViewModelFactory,
5049
expanderHost, id)
5150
{
@@ -88,6 +87,19 @@ public enum AgentConnectionStatus
8887
Offline,
8988
}
9089

90+
public static class AgentConnectionStatusExtensions
91+
{
92+
public static string ToDisplayString(this AgentConnectionStatus status) =>
93+
status switch
94+
{
95+
AgentConnectionStatus.Healthy => "Healthy",
96+
AgentConnectionStatus.Unhealthy => "High latency",
97+
AgentConnectionStatus.NoRecentHandshake => "No recent handshake",
98+
AgentConnectionStatus.Offline => "Offline",
99+
_ => status.ToString()
100+
};
101+
}
102+
91103
public partial class AgentViewModel : ObservableObject, IModelUpdateable<AgentViewModel>
92104
{
93105
private const string DefaultDashboardUrl = "https://coder.com";
@@ -169,6 +181,7 @@ public string FullyQualifiedDomainName
169181
[ObservableProperty]
170182
[NotifyPropertyChangedFor(nameof(ShowExpandAppsMessage))]
171183
[NotifyPropertyChangedFor(nameof(ExpandAppsMessage))]
184+
[NotifyPropertyChangedFor(nameof(ConnectionTooltip))]
172185
public required partial AgentConnectionStatus ConnectionStatus { get; set; }
173186

174187
[ObservableProperty]
@@ -214,11 +227,12 @@ public string FullyQualifiedDomainName
214227
public string ConnectionTooltip { get
215228
{
216229
var description = new StringBuilder();
230+
var highLatencyWarning = ConnectionStatus == AgentConnectionStatus.Unhealthy ? $"({AgentConnectionStatus.Unhealthy.ToDisplayString()})" : "";
217231

218232
if (DidP2p != null && DidP2p.Value && Latency != null)
219233
{
220234
description.Append($"""
221-
You're connected peer-to-peer.
235+
You're connected peer-to-peer. {highLatencyWarning}
222236
223237
You ↔ {Latency.Value.Milliseconds} ms ↔ {WorkspaceName}
224238
"""
@@ -227,7 +241,7 @@ public string ConnectionTooltip { get
227241
else if (PreferredDerpLatency != null)
228242
{
229243
description.Append($"""
230-
You're connected through a DERP relay.
244+
You're connected through a DERP relay. {highLatencyWarning}
231245
We'll switch over to peer-to-peer when available.
232246
233247
Total latency: {PreferredDerpLatency.Value.Milliseconds} ms
@@ -247,15 +261,14 @@ public string ConnectionTooltip { get
247261
}
248262
}
249263
}
264+
else
265+
{
266+
description.Append(ConnectionStatus.ToDisplayString());
267+
}
250268
if (LastHandshake != null)
251-
description.Append($"\n\nLast handshake: {LastHandshake?.ToString() ?? "Unknown"}");
252-
253-
var tooltip = description.ToString().TrimEnd('\n', ' ');
254-
255-
if (string.IsNullOrEmpty(tooltip))
256-
return "No connection information available.";
269+
description.Append($"\n\nLast handshake: {LastHandshake?.ToString()}");
257270

258-
return tooltip;
271+
return description.ToString().TrimEnd('\n', ' '); ;
259272
}
260273
}
261274

App/ViewModels/TrayWindowViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
224224
if (string.IsNullOrWhiteSpace(fqdn))
225225
continue;
226226

227-
227+
#pragma warning disable CS8602 // Protobuf will always set this value, so we can safely dereference them.
228228
var lastHandshakeAgo = DateTime.UtcNow.Subtract(agent.LastHandshake.ToDateTime());
229+
#pragma warning restore CS8602
229230

230231
// For compatibility with older deployments, we assume that if the
231232
// last ping is null, the agent is healthy.
232-
var isLatencyAcceptable = agent.LastPing != null ? agent.LastPing.Latency.ToTimeSpan() < HealthyPingThreshold : true;
233+
var isLatencyAcceptable = agent.LastPing == null || agent.LastPing.Latency.ToTimeSpan() < HealthyPingThreshold;
233234
var connectionStatus = AgentConnectionStatus.Healthy;
234235
if (lastHandshakeAgo > TimeSpan.FromMinutes(5))
235236
{
@@ -243,7 +244,6 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
243244

244245
workspacesWithAgents.Add(agent.WorkspaceId);
245246
var workspace = rpcModel.Workspaces.FirstOrDefault(w => w.Id == agent.WorkspaceId);
246-
System.Diagnostics.Debug.WriteLine($"Agent {uuid} LastHandshakeAgo: {lastHandshakeAgo} ConnectionStatus: {connectionStatus} FQDN: {fqdn} Last ping: {agent.LastPing} Last handshake: {agent.LastHandshake}");
247247

248248
agents.Add(_agentViewModelFactory.Create(
249249
this,

0 commit comments

Comments
 (0)