Skip to content

Commit

Permalink
add TestKeyDbMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Jun 10, 2022
1 parent 3e7d754 commit 3a74303
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contrib/docker-compose-for-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@ services:
image: redis:5
command: "redis-server --port 6383 --dbfilename dump5.rdb"
ports:
- "6383"
- "16383:6383"

redis6:
image: redis:6.2
command: "redis-server --protected-mode no --dbfilename dump6.rdb"
ports:
- "6379"
- "16379:6379"

redis7:
image: redis:7.0
command: "redis-server --protected-mode no --dbfilename dump7.rdb"
ports:
- "6384"
- "16384:6384"

pwd-redis5:
image: redis:5
command: "redis-server --port 6380 --requirepass redis-password --dbfilename dump5-pwd.rdb"
ports:
- "6380"
- "16380:6380"

pwd-redis6:
image: redis:6
command: "redis-server --port 6390 --requirepass dummy --user exporter on +CLIENT +INFO +SELECT +SLOWLOG +LATENCY '>exporter-password' --dbfilename dump6-pwd.rdb"
ports:
- "6390"
- "16390:6390"

redis-2-8:
image: redis:2.8
command: "redis-server --port 6381 --dbfilename dump2-8.rdb"
ports:
- "6381"
- "16381:6381"

keydb-01:
image: "eqalpha/keydb:x86_64_v6.3.1"
command: "keydb-server --protected-mode no --port 6401 --dbfilename dump-keydb-01.rdb"
ports:
- "6401"
- "16401:6401"

keydb-02:
image: "eqalpha/keydb:x86_64_v6.3.1"
command: "keydb-server --protected-mode no --port 6402 --active-replica yes --replicaof keydb-01 6401 --dbfilename dump-keydb-02.rdb"
ports:
- "6402"
- "16402:6402"

redis-cluster:
image: grokzen/redis-cluster
Expand All @@ -63,7 +63,7 @@ services:
tile38:
image: tile38/tile38:latest
ports:
- "9851"
- "19851:9851"


tests:
Expand Down
3 changes: 3 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ func NewRedisExporter(redisURI string, opts Options) (*Exporter, error) {
"io_threaded_reads_processed": "io_threaded_reads_processed",
"io_threaded_writes_processed": "io_threaded_writes_processed",
"dump_payload_sanitizations": "dump_payload_sanitizations",

"storage_provider_read_hits": "storage_provider_read_hits",
"storage_provider_read_misses": "storage_provider_read_misses",
},
}

Expand Down
22 changes: 22 additions & 0 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,28 @@ func TestConnectionDurations(t *testing.T) {
}
}

func TestKeyDbMetrics(t *testing.T) {
setupDBKeys(t, os.Getenv("TEST_KEYDB01_URI"))
defer deleteKeysFromDB(t, os.Getenv("TEST_KEYDB01_URI"))

for _, want := range []string{
`test_db_keys_cached`,
`test_storage_provider_read_hits`,
} {
r := prometheus.NewRegistry()
ts := httptest.NewServer(promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
e, _ := NewRedisExporter(os.Getenv("TEST_KEYDB01_URI"), Options{Namespace: "test"})
r.Register(e)

body := downloadURL(t, ts.URL+"/metrics")
if !strings.Contains(body, want) {
t.Errorf("want metrics to include %s, have:\n%s", want, body)
}

ts.Close()
}
}

func init() {
rand.Seed(time.Now().UnixNano())

Expand Down

0 comments on commit 3a74303

Please sign in to comment.