-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add redis search module metrics (#953)
* Feature: Add redis search module metrics
- Loading branch information
1 parent
3ae7e68
commit 1f06f2f
Showing
8 changed files
with
158 additions
and
1 deletion.
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
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, ":") | ||
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], ",") | ||
if len(module) != 7 { | ||
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