Skip to content
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

Add support for slowlog #971

Merged
merged 38 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
428432c
SLOWLOG command skeleton
badrishc Jan 29, 2025
ed6db0c
add configs
badrishc Jan 29, 2025
b6dfa1f
update docs
badrishc Jan 29, 2025
f3ae36e
increase slowlog minimum threshold
badrishc Jan 29, 2025
ebbe337
updates
badrishc Jan 29, 2025
2a99cd2
fix
badrishc Jan 29, 2025
d275049
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 29, 2025
2d18538
update json
badrishc Jan 29, 2025
309f6b4
Revert "update json"
badrishc Jan 29, 2025
0a972eb
add json
badrishc Jan 29, 2025
8e894d6
update ACL tests
badrishc Jan 29, 2025
5906651
Fix AofIndependentCommandsTest
badrishc Jan 29, 2025
a29cfee
updates
badrishc Jan 29, 2025
9de1a28
more cleanup
badrishc Jan 29, 2025
4af5cd5
more updates and cleanup
badrishc Jan 29, 2025
92d248f
nits
badrishc Jan 29, 2025
b452e5f
fix format
badrishc Jan 29, 2025
d19e598
nit
badrishc Jan 29, 2025
a934b8d
nit
badrishc Jan 29, 2025
78648ce
updates + tests
badrishc Jan 29, 2025
97cce40
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 29, 2025
14a903c
cleanup
badrishc Jan 29, 2025
a2cb78f
Merge branch 'badrishc/slowlog-v1' of github.com:microsoft/garnet int…
badrishc Jan 29, 2025
a34ec1f
Merge from main
badrishc Jan 29, 2025
569bf83
update docs
badrishc Jan 29, 2025
16690ec
add a better test with added entry to slow log
badrishc Jan 29, 2025
60f3499
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 29, 2025
2dbe776
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 30, 2025
75c21ff
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 30, 2025
c135001
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 31, 2025
fbd5cbf
Merge branch 'main' into badrishc/slowlog-v1
badrishc Jan 31, 2025
c6d40bb
Merge remote-tracking branch 'origin/main' into badrishc/slowlog-v1
badrishc Feb 3, 2025
7744799
update redis.conf compat
badrishc Feb 3, 2025
7fb7afb
use AbortWithWrongNumberOfArguments
badrishc Feb 3, 2025
43775f6
nits
badrishc Feb 3, 2025
cd97415
Merge remote-tracking branch 'origin/main' into badrishc/slowlog-v1
badrishc Feb 3, 2025
3c40e49
Merge
badrishc Feb 4, 2025
fc61d68
Fix warning in LightClient
badrishc Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/common/LightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private async Task<bool> TryConnectSocketAsync(Socket socket, EndPoint endpoint,
if (socket.Connected)
return true;
}
catch (Exception ex)
catch
{
socket.Dispose();
return false;
Expand Down
15 changes: 15 additions & 0 deletions libs/host/Configuration/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ internal sealed class Options
[Option("latency-monitor", Required = false, HelpText = "Track latency of various events.")]
public bool? LatencyMonitor { get; set; }

[IntRangeValidation(0, int.MaxValue)]
badrishc marked this conversation as resolved.
Show resolved Hide resolved
[Option("slowlog-log-slower-than", Required = false, HelpText = "Threshold (microseconds) for logging command in the slow log. 0 to disable.")]
public int SlowLogThreshold { get; set; }

[IntRangeValidation(0, int.MaxValue)]
[Option("slowlog-max-len", Required = false, HelpText = "Maximum number of slow log entries to keep.")]
public int SlowLogMaxEntries { get; set; }

[IntRangeValidation(0, int.MaxValue)]
[Option("metrics-sampling-freq", Required = false, HelpText = "Metrics sampling frequency in seconds. Value of 0 disables metrics monitor task.")]
public int MetricsSamplingFrequency { get; set; }
Expand Down Expand Up @@ -654,6 +662,11 @@ public GarnetServerOptions GetServerOptions(ILogger logger = null)
CompactionForceDelete = true;
}

if (SlowLogThreshold > 0)
{
if (SlowLogThreshold < 100)
badrishc marked this conversation as resolved.
Show resolved Hide resolved
throw new Exception("SlowLogThreshold must be at least 100 microseconds.");
}
return new GarnetServerOptions(logger)
{
EndPoint = endpoint,
Expand Down Expand Up @@ -723,6 +736,8 @@ public GarnetServerOptions GetServerOptions(ILogger logger = null)
ServerCertificateRequired.GetValueOrDefault(),
logger: logger) : null,
LatencyMonitor = LatencyMonitor.GetValueOrDefault(),
SlowLogThreshold = SlowLogThreshold,
SlowLogMaxEntries = SlowLogMaxEntries,
MetricsSamplingFrequency = MetricsSamplingFrequency,
LogLevel = LogLevel,
LoggingFrequency = LoggingFrequency,
Expand Down
6 changes: 6 additions & 0 deletions libs/host/Configuration/Redis/RedisOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ internal class RedisOptions

[RedisOption("unixsocketperm", nameof(Options.UnixSocketPermission))]
public Option<int> UnixSocketPermission { get; set; }

[RedisOption("slowlog-log-slower-than", nameof(Options.SlowLogThreshold))]
public Option<int> SlowLogLogSlowerThan { get; set; }

[RedisOption("slowlog-max-len", nameof(Options.SlowLogMaxEntries))]
public Option<int> SlowLogMaxLen { get; set; }
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions libs/host/defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@
/* Track latency of various events. */
"LatencyMonitor" : false,

/* Threshold (microseconds) for logging command in the slow log. 0 to disable. */
"SlowLogThreshold": 0,

/* Maximum number of slow log entries to keep. */
"SlowLogMaxEntries": 128,

/* Metrics sampling frequency in seconds. Value of 0 disables metrics monitor task. */
"MetricsSamplingFrequency" : 0,

Expand Down
46 changes: 46 additions & 0 deletions libs/resources/RespCommandsDocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6414,6 +6414,52 @@
}
]
},
{
"Command": "SLOWLOG",
"Name": "SLOWLOG",
"Summary": "A container for slow log commands.",
"Group": "Server",
"Complexity": "Depends on subcommand.",
"SubCommands": [
{
"Command": "SLOWLOG_GET",
"Name": "SLOWLOG|GET",
"Summary": "Returns the slow log\u0027s entries.",
"Group": "Server",
"Complexity": "O(N) where N is the number of entries returned",
"Arguments": [
{
"TypeDiscriminator": "RespCommandBasicArgument",
"Name": "COUNT",
"DisplayText": "count",
"Type": "Integer",
"ArgumentFlags": "Optional"
}
]
},
{
"Command": "SLOWLOG_HELP",
"Name": "SLOWLOG|HELP",
"Summary": "Show helpful text about the different subcommands",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "SLOWLOG_LEN",
"Name": "SLOWLOG|LEN",
"Summary": "Returns the number of entries in the slow log.",
"Group": "Server",
"Complexity": "O(1)"
},
{
"Command": "SLOWLOG_RESET",
"Name": "SLOWLOG|RESET",
"Summary": "Clears all entries from the slow log.",
"Group": "Server",
"Complexity": "O(N) where N is the number of entries in the slowlog"
}
]
},
{
"Command": "SMEMBERS",
"Name": "SMEMBERS",
Expand Down
51 changes: 50 additions & 1 deletion libs/resources/RespCommandsInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@
"FirstKey": 1,
"LastKey": 1,
"Step": 1,
"AclCategories": "Hash, Write, Admin, Garnet",
"AclCategories": "Admin, Hash, Write, Garnet",
"KeySpecifications": [
{
"BeginSearch": {
Expand Down Expand Up @@ -4152,6 +4152,55 @@
"Flags": "Admin, NoAsyncLoading, NoScript, Stale",
"AclCategories": "Admin, Dangerous, Slow"
},
{
"Command": "SLOWLOG",
"Name": "SLOWLOG",
"Arity": -2,
"AclCategories": "Slow",
"SubCommands": [
{
"Command": "SLOWLOG_GET",
"Name": "SLOWLOG|GET",
"Arity": -2,
"Flags": "Admin, Loading, Stale",
"AclCategories": "Admin, Dangerous, Slow",
"Tips": [
"request_policy:all_nodes",
"nondeterministic_output"
]
},
{
"Command": "SLOWLOG_HELP",
"Name": "SLOWLOG|HELP",
"Arity": 2,
"Flags": "Loading, Stale",
"AclCategories": "Slow"
},
{
"Command": "SLOWLOG_LEN",
"Name": "SLOWLOG|LEN",
"Arity": 2,
"Flags": "Admin, Loading, Stale",
"AclCategories": "Admin, Dangerous, Slow",
"Tips": [
"request_policy:all_nodes",
"response_policy:agg_sum",
"nondeterministic_output"
]
},
{
"Command": "SLOWLOG_RESET",
"Name": "SLOWLOG|RESET",
"Arity": 2,
"Flags": "Admin, Loading, Stale",
"AclCategories": "Admin, Dangerous, Slow",
"Tips": [
"request_policy:all_nodes",
"response_policy:all_succeeded"
]
}
]
},
{
"Command": "SMEMBERS",
"Name": "SMEMBERS",
Expand Down
7 changes: 7 additions & 0 deletions libs/server/Metrics/Latency/GarnetLatencyMetricsSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void Start(LatencyMetricsType cmd)
metrics[idx].Start();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Get(LatencyMetricsType cmd)
{
int idx = (int)cmd;
return metrics[idx].startTimestamp;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StopAndSwitch(LatencyMetricsType oldCmd, LatencyMetricsType newCmd)
{
Expand Down
8 changes: 4 additions & 4 deletions libs/server/Metrics/Latency/RespLatencyHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public static List<string> GetLatencyCommands()
{
return new List<string>()
{
"LATENCY<subcommand>[< arg > [value][opt]...]. Subcommands are:",
"LATENCY <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
"HISTOGRAM [EVENT [EVENT...]]",
"\t Return latency histogram of or more <event> classes.",
"\tReturn latency histogram of one or more <event> classes.",
"\tIf no commands are specified then all histograms are replied",
"RESET [EVENT [EVENT...]]" +
"\tReset latency data of one or more <event> classes." +
"RESET [EVENT [EVENT...]]",
"\tReset latency data of one or more <event> classes.",
"\t(default: reset all data for all event classes).",
"HELP",
"\tPrints this help"
Expand Down
Loading