Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version: '1.24'

- name: Build binaries
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version: '1.24'

- name: Install Dependencies
run: go mod tidy
Expand Down Expand Up @@ -91,15 +91,15 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version: '1.24'

- name: Install Dependencies
run: go mod tidy

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
version: v1.64
args: "--tests=false"


Expand All @@ -112,7 +112,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version: '1.24'

- name: Install Dependencies
run: go mod tidy
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG TARGETPLATFORM
#
# build container
#
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
WORKDIR /go/src/github.com/oliver006/redis_exporter/

ADD . /go/src/github.com/oliver006/redis_exporter/
Expand Down Expand Up @@ -40,7 +40,7 @@ ENTRYPOINT [ "/redis_exporter" ]
#
# Alpine release container
#
FROM alpine:3.20 AS alpine
FROM alpine:3.21 AS alpine

COPY --from=builder /redis_exporter /redis_exporter
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
- "16380:6379"

pwd-redis6:
image: redis:6
image: redis:6.2
command: "redis-server --requirepass dummy --user exporter on +CLIENT +INFO +SELECT +SLOWLOG +LATENCY '>exporter-password'"
ports:
- "16390:6379"
Expand All @@ -76,7 +76,7 @@ services:
- "16381:6379"

keydb-01:
image: "eqalpha/keydb:x86_64_v6.3.1"
image: "eqalpha/keydb:x86_64_v6.3.4"
command: "keydb-server --protected-mode no"
ports:
- "16401:6379"
Expand All @@ -100,7 +100,7 @@ services:
- "17005:7005"

redis-cluster-password:
image: bitnami/redis-cluster
image: bitnami/redis-cluster:7.4
environment:
- REDIS_PORT_NUMBER=7006
- REDIS_PASSWORD=redis-password
Expand Down
30 changes: 11 additions & 19 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
c.Do("XREADGROUP", "GROUP", "test_group_1", "test_consumer_2", "COUNT", "1", "STREAMS", TestKeysStreamName, ">")
c.Do("XREADGROUP", "GROUP", "test_group_2", "test_consumer_1", "COUNT", "1", "STREAMS", TestKeysStreamName, "0")

time.Sleep(time.Millisecond * 100)
return nil
}

Expand Down Expand Up @@ -160,42 +161,33 @@ func deleteKeys(c redis.Conn, dbNumStr string) {
c.Do("DEL", singleStringKey)
}

func setupDBKeys(t *testing.T, uri string) error {
func setupDBKeys(t *testing.T, uri string) {
c, err := redis.DialURL(uri)
if err != nil {
t.Errorf("couldn't setup redis for uri %s, err: %s ", uri, err)
return err
t.Fatalf("couldn't setup redis for uri %s, err: %s ", uri, err)
return
}
defer c.Close()

err = setupKeys(t, c, dbNumStr)
if err != nil {
t.Errorf("couldn't setup redis, err: %s ", err)
return err
if err = setupKeys(t, c, dbNumStr); err != nil {
t.Fatalf("couldn't setup redis, err: %s ", err)
}

time.Sleep(time.Millisecond * 50)

return nil
}

func setupDBKeysCluster(t *testing.T, uri string) error {
func setupDBKeysCluster(t *testing.T, uri string) {
e, _ := NewRedisExporter(uri, Options{})
c, err := e.connectToRedisCluster()
if err != nil {
return err
t.Fatalf("connectToRedisCluster() err: %s ", err)
return
}

defer c.Close()

if err = setupKeys(t, c, "0"); err != nil {
t.Errorf("couldn't setup redis, err: %s ", err)
return err
t.Fatalf("couldn't setup redis, err: %s ", err)
return
}

time.Sleep(time.Millisecond * 50)

return nil
}

func deleteKeysFromDB(t *testing.T, addr string) error {
Expand Down
2 changes: 1 addition & 1 deletion exporter/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (e *Exporter) extractCheckKeyMetrics(ch chan<- prometheus.Metric, c redis.C
for _, k := range allKeys {
if e.options.IsCluster {
// Cluster mode only has one db
// no need to run `SELECT" but got to set it to "0" here cause it's used further down as a label
// no need to run `SELECT" but got to set it to "0" here because it's used further down as a label
k.db = "0"
} else {
if k.db != lastDb {
Expand Down
24 changes: 9 additions & 15 deletions exporter/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func TestKeyValuesAndSizes(t *testing.T) {
}

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

for _, exc := range []bool{true, false} {
e, _ := NewRedisExporter(
os.Getenv("TEST_REDIS_URI"),
Expand All @@ -65,10 +68,6 @@ func TestKeyValuesAsLabel(t *testing.T) {
Registry: prometheus.NewRegistry()},
)
ts := httptest.NewServer(e)
defer ts.Close()

setupDBKeys(t, os.Getenv("TEST_REDIS_URI"))
defer deleteKeysFromDB(t, os.Getenv("TEST_REDIS_URI"))

chM := make(chan prometheus.Metric, 10000)
go func() {
Expand All @@ -87,6 +86,7 @@ func TestKeyValuesAsLabel(t *testing.T) {
t.Fatalf("didn't find %s with DisableExportingKeyValues disabled, body: %s", match, body)
}
}
ts.Close()
}
}

Expand All @@ -95,9 +95,10 @@ func TestClusterKeyValuesAndSizes(t *testing.T) {
if clusterUri == "" {
t.Skipf("Skipping TestClusterKeyValuesAndSizes, don't have env var TEST_REDIS_CLUSTER_MASTER_URI")
}
setupDBKeysCluster(t, clusterUri)
defer deleteKeysFromDBCluster(clusterUri)

for _, exc := range []bool{true, false} {

e, _ := NewRedisExporter(
clusterUri,
Options{
Expand All @@ -111,11 +112,6 @@ func TestClusterKeyValuesAndSizes(t *testing.T) {
},
)

if err := setupDBKeysCluster(t, clusterUri); err != nil {
t.Fatalf("setupDBKeysCluster() err: %s", err)
}
defer deleteKeysFromDBCluster(clusterUri)

chM := make(chan prometheus.Metric)
go func() {
e.Collect(chM)
Expand Down Expand Up @@ -531,13 +527,13 @@ func TestGetKeyInfo(t *testing.T) {
for _, f := range fixtures {
info, err := getKeyInfo(c, f.key, false)
if err != nil {
t.Errorf("Error getting key info for %#v.", f.key)
t.Fatalf("Error getting key info for %#v.", f.key)
}

expected := expectedSizes[f.key]
if info.size != expected {
t.Logf("%#v", info)
t.Errorf("Wrong size for key: %#v. Expected: %#v; Actual: %#v", f.key, expected, info.size)
t.Logf("info: %#v", info)
}
}

Expand Down Expand Up @@ -672,9 +668,7 @@ func TestClusterGetKeyInfo(t *testing.T) {
ts := httptest.NewServer(e)
defer ts.Close()

if err := setupDBKeysCluster(t, clusterUri); err != nil {
t.Fatalf("setupDBKeysCluster() err: %s", err)
}
setupDBKeysCluster(t, clusterUri)
defer deleteKeysFromDBCluster(clusterUri)

chM := make(chan prometheus.Metric, 10000)
Expand Down
4 changes: 2 additions & 2 deletions exporter/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (e *Exporter) extractLatencyLatestMetrics(outChan chan<- prometheus.Metric,
for _, l := range reply {
if latencyResult, err := redis.Values(l, nil); err == nil {
var eventName string
var spikeLast, spikeDuration, max int64
if _, err := redis.Scan(latencyResult, &eventName, &spikeLast, &spikeDuration, &max); err == nil {
var spikeLast, spikeDuration, maxLatency int64
if _, err := redis.Scan(latencyResult, &eventName, &spikeLast, &spikeDuration, &maxLatency); err == nil {
spikeDurationSeconds := float64(spikeDuration) / 1e3
e.registerConstMetricGauge(outChan, "latency_spike_last", float64(spikeLast), eventName)
e.registerConstMetricGauge(outChan, "latency_spike_duration_seconds", spikeDurationSeconds, eventName)
Expand Down
12 changes: 6 additions & 6 deletions exporter/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func TestPasswordInvalid(t *testing.T) {
}

func TestConnectToClusterUsingPasswordFile(t *testing.T) {
cluster_host := os.Getenv("TEST_REDIS_CLUSTER_PASSWORD_URI")
if cluster_host == "" {
clusterUri := os.Getenv("TEST_REDIS_CLUSTER_PASSWORD_URI")
if clusterUri == "" {
t.Skipf("TEST_REDIS_CLUSTER_PASSWORD_URI is not set")
}
passMap := map[string]string{cluster_host: "redis-password"}
passMap := map[string]string{clusterUri: "redis-password"}
wrongPassMap := map[string]string{"redis://redis-cluster-password-wrong:7006": "redis-password"}

tsts := []struct {
Expand All @@ -147,13 +147,13 @@ func TestConnectToClusterUsingPasswordFile(t *testing.T) {
passMap map[string]string
refreshError bool
}{
{name: "ConnectToCluster using passord file witch cluster mode", isCluster: true, passMap: passMap, refreshError: false},
{name: "ConnectToCluster using password file with cluster mode", isCluster: true, passMap: passMap, refreshError: false},
{name: "ConnectToCluster using password file without cluster mode", isCluster: false, passMap: passMap, refreshError: false},
{name: "ConnectToCluster using password file witch cluster mode failed", isCluster: false, passMap: wrongPassMap, refreshError: true},
{name: "ConnectToCluster using password file with cluster mode failed", isCluster: false, passMap: wrongPassMap, refreshError: true},
}
for _, tst := range tsts {
t.Run(tst.name, func(t *testing.T) {
e, _ := NewRedisExporter(cluster_host, Options{
e, _ := NewRedisExporter(clusterUri, Options{
SkipTLSVerification: true,
PasswordMap: tst.passMap,
IsCluster: tst.isCluster,
Expand Down
8 changes: 4 additions & 4 deletions exporter/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestStreamsExtractStreamMetricsExcludeConsumer(t *testing.T) {
"stream_group_lag": false,
}

dont_want := map[string]bool{
dontWant := map[string]bool{
"stream_group_consumer_messages_pending": false,
"stream_group_consumer_idle_seconds": false,
}
Expand All @@ -599,12 +599,12 @@ func TestStreamsExtractStreamMetricsExcludeConsumer(t *testing.T) {
want[k] = true
}
}
for k := range dont_want {
for k := range dontWant {
log.Debugf("metric: %s", m.Desc().String())
log.Debugf("don't want: %s", k)

if strings.Contains(m.Desc().String(), k) {
dont_want[k] = true
dontWant[k] = true
}
}
}
Expand All @@ -614,7 +614,7 @@ func TestStreamsExtractStreamMetricsExcludeConsumer(t *testing.T) {
t.Errorf("didn't find %s metric, which should be collected", k)
}
}
for k, found := range dont_want {
for k, found := range dontWant {
if found {
t.Errorf("found %s metric, which shouldn't be collected", k)
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module github.com/oliver006/redis_exporter

go 1.20
go 1.21

require (
github.com/gomodule/redigo v1.9.2
github.com/mna/redisc v1.4.0
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_golang v1.21.1
github.com/prometheus/client_model v0.6.1
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
golang.org/x/sys v0.22.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/sys v0.28.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
)
26 changes: 15 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,39 @@ github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUz
github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s=
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mna/redisc v1.4.0 h1:rBKXyGO/39SGmYoRKCyzXcBpoMMKqkikg8E1G8YIfSA=
github.com/mna/redisc v1.4.0/go.mod h1:CplIoaSTDi5h9icnj4FLbRgHoNKCHDNJDVRztWDGeSQ=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk=
github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading