-
Notifications
You must be signed in to change notification settings - Fork 875
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
Feature: Add redis search module metrics #953
Merged
oliver006
merged 11 commits into
oliver006:master
from
nantiferov:Feature--Add-redis-search-module-metrics
Oct 5, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
113340b
Feature: Add redis search module metrics
nantiferov 31ff648
Fix redis-search port for tests
nantiferov 4dffe83
Switch to universal data collection for modules
nantiferov 9ff9169
Add more module metrics collection
nantiferov d271734
Add continue after registerConstMetricGauge in module switch
nantiferov d97d711
Add _bytes suffix to search_used_memory_indexes
nantiferov d4bd8dd
Merge branch 'master' into Feature--Add-redis-search-module-metrics
nantiferov 8d36dd5
Remove search_version metric
nantiferov d125fa4
Add checks for correctlness of data after split
nantiferov 7baa35f
Set units for 3 more metrics
nantiferov 9e7822e
Clarify comment about module format
nantiferov 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 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 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 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 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 |
---|---|---|
|
@@ -65,6 +65,7 @@ type Options struct { | |
ClientKeyFile string | ||
CaCertFile string | ||
InclConfigMetrics bool | ||
InclModulesMetrics bool | ||
DisableExportingKeyValues bool | ||
ExcludeLatencyHistogramMetrics bool | ||
RedactConfigMetrics bool | ||
|
@@ -267,6 +268,21 @@ func NewRedisExporter(redisURI string, opts Options) (*Exporter, error) { | |
"server_threads": "server_threads_total", | ||
"long_lock_waits": "long_lock_waits_total", | ||
"current_client_thread": "current_client_thread", | ||
|
||
// Redis Modules metrics | ||
// RediSearch module | ||
"search_number_of_indexes": "search_number_of_indexes", | ||
"search_used_memory_indexes": "search_used_memory_indexes_bytes", | ||
oliver006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"search_total_indexing_time": "search_total_indexing_time_ms", | ||
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.
|
||
"search_global_idle": "search_global_idle", | ||
"search_global_total": "search_global_total", | ||
"search_bytes_collected": "search_collected_bytes", | ||
"search_total_cycles": "search_total_cycles", | ||
"search_total_ms_run": "search_total_run_ms", | ||
"search_dialect_1": "search_dialect_1", | ||
"search_dialect_2": "search_dialect_2", | ||
"search_dialect_3": "search_dialect_3", | ||
"search_dialect_4": "search_dialect_4", | ||
oliver006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
|
||
metricMapCounters: map[string]string{ | ||
|
@@ -421,6 +437,7 @@ func NewRedisExporter(redisURI string, opts Options) (*Exporter, error) { | |
"stream_radix_tree_keys": {txt: `Radix tree keys count"`, lbls: []string{"db", "stream"}}, | ||
"stream_radix_tree_nodes": {txt: `Radix tree nodes count`, lbls: []string{"db", "stream"}}, | ||
"up": {txt: "Information about the Redis instance"}, | ||
"module_info": {txt: "Information about loaded Redis module", lbls: []string{"name", "ver", "api", "filters", "usedby", "using"}}, | ||
} { | ||
e.metricDescriptions[k] = newMetricDescr(opts.Namespace, k, desc.txt, desc.lbls) | ||
} | ||
|
@@ -698,6 +715,10 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error { | |
e.extractTile38Metrics(ch, c) | ||
} | ||
|
||
if e.options.InclModulesMetrics { | ||
e.extractModulesMetrics(ch, c) | ||
} | ||
|
||
if len(e.options.LuaScript) > 0 { | ||
for filename, script := range e.options.LuaScript { | ||
if err := e.extractLuaScriptMetrics(ch, c, filename, script); err != nil { | ||
|
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package exporter | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gomodule/redigo/redis" | ||
"github.com/prometheus/client_golang/prometheus" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (e *Exporter) extractModulesMetrics(ch chan<- prometheus.Metric, c redis.Conn) { | ||
info, err := redis.String(doRedisCmd(c, "INFO", "MODULES")) | ||
if err != nil { | ||
log.Errorf("extractSearchMetrics() err: %s", err) | ||
return | ||
} | ||
|
||
lines := strings.Split(info, "\r\n") | ||
for _, line := range lines { | ||
log.Debugf("info: %s", line) | ||
|
||
split := strings.Split(line, ":") | ||
oliver006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(split) != 2 { | ||
continue | ||
} | ||
|
||
if split[0] == "module" { | ||
// module format: 'module:name=<module-name>,ver=21005,api=1,filters=0,usedby=[],using=[],options=[]' | ||
module := strings.Split(split[1], ",") | ||
oliver006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(module) != 7 { | ||
oliver006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
e.registerConstMetricGauge(ch, "module_info", 1, | ||
strings.Split(module[0], "=")[1], | ||
strings.Split(module[1], "=")[1], | ||
strings.Split(module[2], "=")[1], | ||
strings.Split(module[3], "=")[1], | ||
strings.Split(module[4], "=")[1], | ||
strings.Split(module[5], "=")[1], | ||
) | ||
continue | ||
} | ||
|
||
fieldKey := split[0] | ||
fieldValue := split[1] | ||
|
||
if !e.includeMetric(fieldKey) { | ||
continue | ||
} | ||
e.parseAndRegisterConstMetric(ch, fieldKey, fieldValue) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package exporter | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func TestModules(t *testing.T) { | ||
if os.Getenv("TEST_REDIS_MODULES_URI") == "" { | ||
t.Skipf("TEST_REDIS_MODULES_URI not set - skipping") | ||
} | ||
|
||
tsts := []struct { | ||
addr string | ||
inclModulesMetrics bool | ||
wantModulesMetrics bool | ||
}{ | ||
{addr: os.Getenv("TEST_REDIS_MODULES_URI"), inclModulesMetrics: true, wantModulesMetrics: true}, | ||
{addr: os.Getenv("TEST_REDIS_MODULES_URI"), inclModulesMetrics: false, wantModulesMetrics: false}, | ||
{addr: os.Getenv("TEST_REDIS_URI"), inclModulesMetrics: true, wantModulesMetrics: false}, | ||
{addr: os.Getenv("TEST_REDIS_URI"), inclModulesMetrics: false, wantModulesMetrics: false}, | ||
} | ||
|
||
for _, tst := range tsts { | ||
e, _ := NewRedisExporter(tst.addr, Options{Namespace: "test", InclModulesMetrics: tst.inclModulesMetrics}) | ||
|
||
chM := make(chan prometheus.Metric) | ||
go func() { | ||
e.Collect(chM) | ||
close(chM) | ||
}() | ||
|
||
wantedMetrics := map[string]bool{ | ||
"module_info": false, | ||
"search_number_of_indexes": false, | ||
"search_used_memory_indexes_bytes": false, | ||
"search_total_indexing_time_ms": false, | ||
"search_global_idle": false, | ||
"search_global_total": false, | ||
"search_collected_bytes": false, | ||
"search_total_cycles": false, | ||
"search_total_run_ms": false, | ||
"search_dialect_1": false, | ||
"search_dialect_2": false, | ||
"search_dialect_3": false, | ||
"search_dialect_4": false, | ||
} | ||
|
||
for m := range chM { | ||
for want := range wantedMetrics { | ||
if strings.Contains(m.Desc().String(), want) { | ||
wantedMetrics[want] = true | ||
} | ||
} | ||
} | ||
|
||
if tst.wantModulesMetrics { | ||
for want, found := range wantedMetrics { | ||
if !found { | ||
t.Errorf("%s was *not* found in Redis Modules metrics but expected", want) | ||
} | ||
} | ||
} else if !tst.wantModulesMetrics { | ||
for want, found := range wantedMetrics { | ||
if found { | ||
t.Errorf("%s was *found* in Redis Modules metrics but *not* expected", want) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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.
For context,
7.4.0-v0
is current version ofredis-stack-server
and it includes redis 7.4 + modules with recent versions.