Skip to content

Commit

Permalink
test valkey 8
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Oct 15, 2024
1 parent 4d260d8 commit f6ce5ff
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 51 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
jobs:
test-stuff:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -21,6 +20,12 @@ jobs:
- name: Set up Docker Compose
run: sudo apt-get install docker-compose

# need to do this before we start the services as they need the TLS creds
- name: Create test certs for TLS
run: |
make test-certs
chmod 777 ./contrib/tls/*
- name: Start services
run: docker-compose up -d
working-directory: ./
Expand All @@ -33,6 +38,12 @@ jobs:
- name: Install Dependencies
run: go mod tidy

- name: Docker logs
run: |
echo "${{ toJson(job) }}"
docker logs "redis_exporter_redis7-tls_1"
docker logs "redis_exporter_valkey8-tls_1"
- name: Run tests
env:
LOG_LEVEL: "info"
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ docker-test:
$(DOCKER_COMPOSE) -f docker-compose.yml run --rm tests bash -c 'make test'


.PHONY: test-certs
test-certs:
contrib/tls/gen-test-certs.sh


.PHONY: test
test:
contrib/tls/gen-test-certs.sh

TEST_VALKEY7_URI="valkey://localhost:16384" \
TEST_VALKEY8_URI="valkey://localhost:16382" \
TEST_VALKEY8_TLS_URI="valkeys://localhost:16386" \
TEST_REDIS7_TLS_URI="rediss://localhost:16386" \
TEST_REDIS7_TLS_URI="rediss://localhost:16387" \
TEST_REDIS_URI="redis://localhost:16385" \
TEST_REDIS7_URI="redis://localhost:16385" \
TEST_REDIS5_URI="redis://localhost:16383" \
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
services:

redis74:
redis7:
image: redis:7.4
command: "redis-server --enable-debug-command yes --protected-mode no"
ports:
- "16385:6379"
- "6379:6379"

redis74-tls:
redis7-tls:
image: redis:7.4
volumes:
- ./contrib/tls:/tls
command: |
valkey-server --enable-debug-command yes --protected-mode no
redis-server --enable-debug-command yes --protected-mode no
--tls-port 6379 --port 0
--tls-cert-file /tls/redis.crt
--tls-key-file /tls/redis.key
Expand Down
3 changes: 1 addition & 2 deletions exporter/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func TestHTTPScrapeMetricsEndpoints(t *testing.T) {

// labels and label values
`redis_mode`,
`standalone`,
`cmd="config`,
"maxmemory_policy",

Expand Down Expand Up @@ -230,8 +229,8 @@ func TestSimultaneousMetricsHttpRequests(t *testing.T) {
os.Getenv("TEST_REDIS_2_8_URI"),

os.Getenv("TEST_REDIS7_URI"),
os.Getenv("TEST_REDIS7_TLS_URI"),

os.Getenv("TEST_VALKEY7_URI"),
os.Getenv("TEST_VALKEY8_URI"),

os.Getenv("TEST_KEYDB01_URI"),
Expand Down
4 changes: 2 additions & 2 deletions exporter/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestStreamsGetStreamInfoUsingValKey7(t *testing.T) {
t.Skipf("TEST_VALKEY7_URI not set - skipping")
}

addr := os.Getenv("TEST_VALKEY7_URI")
addr := strings.Replace(os.Getenv("TEST_VALKEY7_URI"), "valkey://", "redis://", 1)
c, err := redis.DialURL(addr)
if err != nil {
t.Fatalf("Couldn't connect to %#v: %#v", addr, err)
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestStreamsScanStreamGroupsUsingValKey7(t *testing.T) {
if os.Getenv("TEST_VALKEY7_URI") == "" {
t.Skipf("TEST_VALKEY7_URI not set - skipping")
}
addr := os.Getenv("TEST_VALKEY7_URI")
addr := strings.Replace(os.Getenv("TEST_VALKEY7_URI"), "valkey://", "redis://", 1)
db := dbNumStr

c, err := redis.DialURL(addr)
Expand Down
82 changes: 42 additions & 40 deletions exporter/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,55 @@ func TestCreateClientTLSConfig(t *testing.T) {
}

func TestValkeyTLSScheme(t *testing.T) {

for _, host := range []string{
os.Getenv("TEST_REDIS7_TLS_URI"),
os.Getenv("TEST_VALKEY8_TLS_URI"),
} {
t.Run(host, func(t *testing.T) {

e, _ := NewRedisExporter(host,
Options{
SkipTLSVerification: true,
ClientCertFile: "../contrib/tls/redis.crt",
ClientKeyFile: "../contrib/tls/redis.key",
},
)
c, err := e.connectToRedis()
if err != nil {
t.Fatalf("connectToRedis() err: %s", err)
}

if _, err := c.Do("PING", ""); err != nil {
t.Errorf("PING err: %s", err)
}

e, _ := NewRedisExporter(host,
Options{
SkipTLSVerification: true,
ClientCertFile: "../contrib/tls/redis.crt",
ClientKeyFile: "../contrib/tls/redis.key",
},
)
c, err := e.connectToRedis()
if err != nil {
t.Fatalf("connectToRedis() err: %s", err)
}

if _, err := c.Do("PING", ""); err != nil {
t.Errorf("PING err: %s", err)
}

c.Close()

chM := make(chan prometheus.Metric)
go func() {
e.Collect(chM)
close(chM)
}()

tsts := []struct {
in string
found bool
}{
{in: "db_keys"},
{in: "commands_total"},
{in: "total_connections_received"},
{in: "used_memory"},
}
for m := range chM {
desc := m.Desc().String()
for i := range tsts {
if strings.Contains(desc, tsts[i].in) {
tsts[i].found = true
c.Close()

chM := make(chan prometheus.Metric)
go func() {
e.Collect(chM)
close(chM)
}()

tsts := []struct {
in string
found bool
}{
{in: "db_keys"},
{in: "commands_total"},
{in: "total_connections_received"},
{in: "used_memory"},
}
for m := range chM {
desc := m.Desc().String()
for i := range tsts {
if strings.Contains(desc, tsts[i].in) {
tsts[i].found = true
}
}
}
}

})
}
}

Expand Down

0 comments on commit f6ce5ff

Please sign in to comment.