Make INFO command variadic (#6891)

This is an enhancement for INFO command, previously INFO only support one argument
for different info section , if user want to get more categories information, either perform
INFO all / default or calling INFO for multiple times.

**Description of the feature**

The goal of adding this feature is to let the user retrieve multiple categories via the INFO
command, and still avoid emitting the same section twice.

A use case for this is like Redis Sentinel, which periodically calling INFO command to refresh
info from monitored Master/Slaves, only Server and Replication part categories are used for
parsing information. If the INFO command can return just enough categories that client side
needs, it can save a lot of time for client side parsing it as well as network bandwidth.

**Implementation**
To share code between redis, sentinel, and other users of INFO (DEBUG and modules),
we have a new `genInfoSectionDict` function that returns a dict and some boolean flags
(e.g. `all`) to the caller (built from user input).
Sentinel is later purging unwanted sections from that, and then it is forwarded to the info `genRedisInfoString`.

**Usage Examples**
INFO Server Replication   
INFO CPU Memory
INFO default commandstats

Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
Wen Hui
2022-02-08 13:14:42 +02:00
committed by GitHub
co-authored by Oran Agra
parent b76016a948
commit 2e1bc942aa
11 changed files with 342 additions and 81 deletions
+27 -2
View File
@@ -64,7 +64,7 @@ start_server {tags {"modules"}} {
}
test {module info one module} {
set info [r info INFOTEST]
set info [r info INFOtest] ;# test case insensitive compare
# info all does not contain modules
assert { [string match "*Spanish*" $info] }
assert { ![string match "*used_memory*" $info] }
@@ -72,7 +72,7 @@ start_server {tags {"modules"}} {
} {-2}
test {module info one section} {
set info [r info INFOTEST_SPANISH]
set info [r info INFOtest_SpanisH] ;# test case insensitive compare
assert { ![string match "*used_memory*" $info] }
assert { ![string match "*Italian*" $info] }
assert { ![string match "*infotest_global*" $info] }
@@ -90,6 +90,31 @@ start_server {tags {"modules"}} {
assert_match {*infotest_unsafe_field:value=1*} $info
}
test {module info multiply sections without all, everything, default keywords} {
set info [r info replication INFOTEST]
assert { [string match "*Spanish*" $info] }
assert { ![string match "*used_memory*" $info] }
assert { [string match "*repl_offset*" $info] }
}
test {module info multiply sections with all keyword and modules} {
set info [r info all modules]
assert { [string match "*cluster*" $info] }
assert { [string match "*cmdstat_info*" $info] }
assert { [string match "*infotest_global*" $info] }
}
test {module info multiply sections with everything keyword} {
set info [r info replication everything cpu]
assert { [string match "*client_recent*" $info] }
assert { [string match "*cmdstat_info*" $info] }
assert { [string match "*Italian*" $info] }
# check that we didn't get the same info twice
assert { ![string match "*used_cpu_user_children*used_cpu_user_children*" $info] }
assert { ![string match "*Italian*Italian*" $info] }
field $info infotest_dos
} {2}
test "Unload the module - infotest" {
assert_equal {OK} [r module unload infotest]
}