Skip to content

Commit

Permalink
Misc cleanup (#956)
Browse files Browse the repository at this point in the history
* lint Dockerfile, test build both Alpine and Scratch

* Run tests - valkey
  • Loading branch information
oliver006 authored Oct 10, 2024
1 parent 6d86815 commit b879136
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
tags: "latest,latest-amd64,${DRONE_TAG},${DRONE_TAG}-amd64"
dockerfile: ./docker/Dockerfile
repo: oliver006/redis_exporter
target: scratch
target: scratch-release
no_cache: true
build_args:
- 'TAG=${DRONE_TAG}'
Expand Down Expand Up @@ -193,7 +193,7 @@ steps:
repo: "quay.io/oliver006/redis_exporter"
tags: "latest,latest-amd64,${DRONE_TAG},${DRONE_TAG}-amd64"
dockerfile: ./docker/Dockerfile
target: scratch
target: scratch-release
no_cache: true
build_args:
- 'TAG=${DRONE_TAG}'
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "v*"

jobs:
tests:
test-stuff:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -41,6 +41,16 @@ jobs:
make checks
make test
- name: Run tests - valkey 7
env:
LOG_LEVEL: "info"
TEST_REDIS_URI: "redis://localhost:16384"
TEST_PWD_REDIS_URI: "redis://:redis-password@localhost:16380"
run: |
go test -v -race -p 1 ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand All @@ -59,7 +69,7 @@ jobs:
working-directory: ./


golangci:
lint-stuff:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -104,10 +114,20 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Test Docker Build
- name: Test Docker Image Build - Alpine
uses: docker/build-push-action@v6
with:
push: false
target: alpine
tags: user/app:tst
file: docker/Dockerfile
build-args: "GOARCH=amd64"

- name: Test Docker Image Build - Scratch
uses: docker/build-push-action@v6
with:
push: false
target: scratch-release
tags: user/app:tst
file: docker/Dockerfile
build-args: "GOARCH=amd64"
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ docker-test:
.PHONY: test
test:
contrib/tls/gen-test-certs.sh
TEST_REDIS_URI="redis://localhost:16384" \

TEST_REDIS_URI="redis://localhost:16385" \
TEST_REDIS7_URI="redis://localhost:16385" \
TEST_REDIS5_URI="redis://localhost:16383" \
TEST_REDIS6_URI="redis://localhost:16379" \
TEST_REDIS74_URI="redis://localhost:16385" \
TEST_VALKEY7_URI="redis://localhost:16384" \
TEST_VALKEY8_URI="redis://localhost:16382" \
TEST_REDIS_2_8_URI="redis://localhost:16381" \
TEST_KEYDB01_URI="redis://localhost:16401" \
TEST_KEYDB02_URI="redis://localhost:16402" \
Expand Down
42 changes: 24 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,63 @@
services:

valkey7:
image: valkey/valkey:7.2
command: "redis-server --enable-debug-command yes --protected-mode no --dbfilename dump7.rdb"
redis74:
image: redis:7.4
command: "redis-server --enable-debug-command yes --protected-mode no"
ports:
- "16384:6379"
- "16385:6379"
- "6379:6379"

redis5:
image: redis:5
command: "redis-server --dbfilename dump5.rdb"
valkey8:
image: valkey/valkey:8
command: "valkey-server --enable-debug-command yes --protected-mode no"
ports:
- "16383:6379"
- "16382:6379"

valkey7:
image: valkey/valkey:7.2
command: "valkey-server --enable-debug-command yes --protected-mode no"
ports:
- "16384:6379"

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

redis74:
image: redis:7.4
command: "redis-server --protected-mode no --dbfilename dump74.rdb"
redis5:
image: redis:5
command: "redis-server"
ports:
- "16385:6379"
- "16383:6379"

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

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

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG GOARCH
#
# build container
#
FROM --platform=linux/amd64 golang:1.23-alpine as builder
FROM --platform=linux/amd64 golang:1.23-alpine AS builder

Check warning on line 5 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / build-stuff

FROM --platform flag should not use a constant value

FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" More info: https://docs.docker.com/go/dockerfile/rule/from-platform-flag-const-disallowed/

Check warning on line 5 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / build-stuff

FROM --platform flag should not use a constant value

FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" More info: https://docs.docker.com/go/dockerfile/rule/from-platform-flag-const-disallowed/
WORKDIR /go/src/github.com/oliver006/redis_exporter/

ADD . /go/src/github.com/oliver006/redis_exporter/
Expand All @@ -22,7 +22,7 @@ RUN [ "$GOARCH" = "amd64" ] && /redis_exporter -version || ls -la /redis_export
#
# scratch release container
#
FROM --platform=linux/$GOARCH scratch as scratch
FROM --platform=linux/$GOARCH scratch AS scratch-release

COPY --from=builder /redis_exporter /redis_exporter
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
Expand All @@ -38,7 +38,7 @@ ENTRYPOINT [ "/redis_exporter" ]
#
# Alpine release container
#
FROM --platform=linux/$GOARCH alpine:3.20 as alpine
FROM --platform=linux/$GOARCH alpine:3.20 AS alpine

COPY --from=builder /redis_exporter /redis_exporter
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
Expand Down
120 changes: 45 additions & 75 deletions exporter/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,19 @@ func TestExportClientList(t *testing.T) {
in string
found bool
}{
{
in: "connected_client_info",
}, {
in: "connected_client_output_buffer_memory_usage_bytes",
}, {
in: "connected_client_total_memory_consumed_bytes",
}, {
in: "connected_client_created_at_timestamp",
}, {
in: "connected_client_idle_since_timestamp",
}, {
in: "connected_client_channel_subscriptions_count",
}, {
in: "connected_client_pattern_matching_subscriptions_count",
}, {
in: "connected_client_query_buffer_length_bytes",
}, {
in: "connected_client_query_buffer_free_space_bytes",
}, {
in: "connected_client_output_buffer_length_bytes",
}, {
in: "connected_client_output_list_length",
},
{in: "connected_client_info"},
{in: "connected_client_output_buffer_memory_usage_bytes"},
{in: "connected_client_total_memory_consumed_bytes"},
{in: "connected_client_created_at_timestamp"},
{in: "connected_client_idle_since_timestamp"},
{in: "connected_client_channel_subscriptions_count"},
{in: "connected_client_pattern_matching_subscriptions_count"},
{in: "connected_client_query_buffer_length_bytes"},
{in: "connected_client_query_buffer_free_space_bytes"},
{in: "connected_client_output_buffer_length_bytes"},
{in: "connected_client_output_list_length"},
{in: "connected_client_shard_channel_subscriptions_count"},
{in: "connected_client_info"},
}
for m := range chM {
desc := m.Desc().String()
Expand All @@ -202,40 +192,16 @@ func TestExportClientList(t *testing.T) {
}
}

func TestExportClientListInclPort(t *testing.T) {
for _, inclPort := range []bool{true, false} {
e := getTestExporterWithOptions(Options{
Namespace: "test", Registry: prometheus.NewRegistry(),
ExportClientList: true,
ExportClientsInclPort: inclPort,
})

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

found := false
for m := range chM {
desc := m.Desc().String()
if strings.Contains(desc, "connected_client_info") {
if strings.Contains(desc, "port") {
found = true
}
}
}

if inclPort && !found {
t.Errorf(`connected_client_info did *not* include "port" in isExportClientList metrics but was expected`)
} else if !inclPort && found {
t.Errorf(`connected_client_info did *include* "port" in isExportClientList metrics but was *not* expected`)
}
/*
some metrics are only in redis 7 but not yet in valkey 7.2
like "connected_client_shard_channel_watched_keys"
*/
func TestExportClientListRedis7(t *testing.T) {
redisSevenAddr := os.Getenv("TEST_REDIS7_URI")
if redisSevenAddr == "" {
t.Skipf("Skipping TestExportClientListRedis7, env var TEST_REDIS7_URI not set")
}
}

func TestExportClientListRedis7(t *testing.T) {
redisSevenAddr := os.Getenv("TEST_REDIS74_URI")
e := getTestExporterWithAddrAndOptions(redisSevenAddr, Options{
Namespace: "test", Registry: prometheus.NewRegistry(),
ExportClientList: true,
Expand Down Expand Up @@ -273,30 +239,34 @@ func TestExportClientListRedis7(t *testing.T) {
}
}

func TestExportClientListResp(t *testing.T) {
redisSevenAddr := os.Getenv("TEST_VALKEY7_URI")
e := getTestExporterWithAddrAndOptions(redisSevenAddr, Options{
Namespace: "test", Registry: prometheus.NewRegistry(),
ExportClientList: true,
})
func TestExportClientListInclPort(t *testing.T) {
for _, inclPort := range []bool{true, false} {
e := getTestExporterWithOptions(Options{
Namespace: "test", Registry: prometheus.NewRegistry(),
ExportClientList: true,
ExportClientsInclPort: inclPort,
})

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

found := false
for m := range chM {
desc := m.Desc().String()
if strings.Contains(desc, "connected_client_info") {
if strings.Contains(desc, "resp") {
found = true
found := false
for m := range chM {
desc := m.Desc().String()
if strings.Contains(desc, "connected_client_info") {
if strings.Contains(desc, "port") {
found = true
}
}
}
}

if !found {
t.Errorf(`connected_client_info did *not* include "resp" in isExportClientList metrics but was expected`)
if inclPort && !found {
t.Errorf(`connected_client_info did *not* include "port" in isExportClientList metrics but was expected`)
} else if !inclPort && found {
t.Errorf(`connected_client_info did *include* "port" in isExportClientList metrics but was *not* expected`)
}
}
}
6 changes: 5 additions & 1 deletion exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
}
}

// setting to expire in 300 seconds, should be plenty for a test run
// set to expire in 300 seconds, should be plenty for a test run
for _, key := range keysExpiring {
if _, err := c.Do("SETEX", key, "300", TestValue); err != nil {
t.Errorf("couldn't setup redis, err: %s ", err)
Expand Down Expand Up @@ -416,6 +416,10 @@ func TestConnectionDurations(t *testing.T) {
}

func TestKeyDbMetrics(t *testing.T) {
if os.Getenv("TEST_KEYDB01_URI") == "" {
t.Skipf("Skipping due to missing TEST_KEYDB01_URI")
}

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

Expand Down
Loading

0 comments on commit b879136

Please sign in to comment.