Skip to content

Commit

Permalink
fix couple places where incorrect TimeSpan method was used, intent wa…
Browse files Browse the repository at this point in the history
…s to get duration so we need the TotalXXX properties in these places (#439)

Co-authored-by: vazois <96085550+vazois@users.noreply.github.com>
  • Loading branch information
kevin-montrose and vazois committed Jun 4, 2024
1 parent a97097d commit 2dff684
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/cluster/Server/GarnetClusterConnectionStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public bool GetConnectionInfo(string nodeId, ref MetricsItem[] linkStatus)
{
var nowTicks = DateTimeOffset.UtcNow.Ticks;
var last_io_seconds = conn.GossipRecv == -1 ? -1 : nowTicks - conn.GossipSend;
last_io_seconds = last_io_seconds < 0 ? 0 : TimeSpan.FromTicks(last_io_seconds).Seconds;
last_io_seconds = last_io_seconds < 0 ? 0 : (int)TimeSpan.FromTicks(last_io_seconds).TotalSeconds;
var connection_status = conn.IsConnected ? "up" : "down";
linkStatus[0] = new("master_link_status", connection_status);
linkStatus[1] = new("master_last_io_seconds_ago", last_io_seconds.ToString());
Expand Down
2 changes: 1 addition & 1 deletion libs/cluster/Server/Gossip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<string> GetBanList()
var expiry = w.Value;
var diff = expiry - DateTimeOffset.UtcNow.Ticks;

var str = $"{nodeId} : {TimeSpan.FromTicks(diff).Seconds}";
var str = $"{nodeId} : {(int)TimeSpan.FromTicks(diff).TotalSeconds}";
banlist.Add(str);
}
return banlist;
Expand Down
4 changes: 2 additions & 2 deletions libs/server/Metrics/Info/GarnetInfoMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ private void PopulateServerInfo(StoreWrapper storeWrapper)
new("os", Environment.OSVersion.ToString()),
new("processor_count", Environment.ProcessorCount.ToString()),
new("arch_bits", Environment.Is64BitProcess ? "64" : "32"),
new("uptime_in_seconds", uptime.Seconds.ToString()),
new("uptime_in_days", uptime.Days.ToString()),
new("uptime_in_seconds", ((int)uptime.TotalSeconds).ToString()),
new("uptime_in_days", ((int)uptime.TotalDays).ToString()),
new("monitor_task", storeWrapper.serverOptions.MetricsSamplingFrequency > 0 ? "enabled" : "disabled"),
new("monitor_freq", storeWrapper.serverOptions.MetricsSamplingFrequency.ToString()),
new("latency_monitor", storeWrapper.serverOptions.LatencyMonitor ? "enabled" : "disabled"),
Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test/RespCustomCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void CustomCommandSetWhileKeyHasTtlTest()

db.KeyExpire(key, TimeSpan.FromSeconds(expire));
var time = db.KeyTimeToLive(key);
Assert.IsTrue(time.Value.Seconds > 0);
Assert.IsTrue(time.Value.TotalSeconds > 0);

// This conditional set should pass (new prefix is greater)
string newValue1 = "foovalue1";
Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test/RespTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public void PersistTest()

db.KeyExpire(keyA, TimeSpan.FromSeconds(expire));
var time = db.KeyTimeToLive(keyA);
Assert.IsTrue(time.Value.Seconds > 0);
Assert.IsTrue(time.Value.TotalSeconds > 0);

response = db.KeyPersist(keyA);
Assert.IsTrue(response);
Expand Down

0 comments on commit 2dff684

Please sign in to comment.