Files
T
bb44aef718 feat: Allow cache reading from replicas (#342)
* feat: Allow cache reading from replicas

* 🍱 fix logic

*  add testing for redis with mock

* 🍱 fix permission

* 📝 test(e2e/redis): fix swapped IP→verdict comments

The mock returns "f" (not banned) for 1.2.3.4 and "t" (banned) for
1.2.3.5, and the run.sh assertions match that. Both doc comments
described the opposite mapping; correct them to match the code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

*  test(e2e/redis): exercise read-from-replica path

The redis scenario only set redisCacheHost, so it validated the writer
but never the round-robin reader path this feature adds. Split the mock
into two roles: the primary (--redis-addr) now answers every GET with a
miss, while the replica (--redis-read-addr) serves the hardcoded
verdicts. The scenario points redisCacheReadHosts at the replica (twice,
to drive round-robin), so the banned-IP-blocked assertion only passes if
the plugin actually reads decisions from the replica rather than the
primary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* 📝 docs: note replicas don't fall back to primary on outage

When RedisCacheReadHosts is set, reads are not retried against the
primary if the replicas are unreachable. Document that this, combined
with the default RedisCacheUnreachableBlock=true, means a replica outage
can block traffic while the primary is healthy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* 🐛 fix(cache): avoid nil-pointer panic on empty redis read

redisCache.get fell through to `switch err.Error()` when Get returned a
nil error with an empty value, panicking on the nil error. simpleredis
never returns that combination today (a miss yields RedisMiss), so it
was unreachable in practice — but the read path is safer treating an
empty, error-free read as a cache miss, which also guarantees err is
non-nil before err.Error() is called.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* 🍱 add test for rotation

* 🐛 readd redis/run.sh

* 🐛 fix redis/run.sh

* 🐛 fix test label; remove log

* 🍱 add tests for roundRobin

* 🐛 fix test

---------

Co-authored-by: maxlerebourg <maxlerebourg@gmail.com>
Co-authored-by: mhx <mathieu@hanotaux.fr>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-26 13:51:22 +02:00

127 lines
3.5 KiB
Makefile

.PHONY: lint test vendor clean e2e_mock
export GO111MODULE=on
# Binary/mock suite (Traefik binary + mock LAPI). This is what CI runs.
# The local Docker suite (make e2e) lives in a separate PR/branch.
E2E_MOCK_SCENARIOS := $(notdir $(wildcard tests/e2e/mock/scenarios/*))
default: lint test
lint:
golangci-lint run
test:
go test -v -cover ./...
yaegi_test:
yaegi test -v .
e2e_mock: $(addprefix e2e_mock_,$(E2E_MOCK_SCENARIOS))
e2e_mock_%:
bash ./tests/e2e/mock/scenarios/$*/run.sh
vendor:
go mod vendor
clean:
rm -rf ./vendor
run_dev:
docker compose -f docker-compose.dev.yml up -d --remove-orphans
run_local:
docker compose -f docker-compose.local.yml up -d --remove-orphans
run_behindproxy:
docker compose -f examples/behind-proxy/docker-compose.yml up -d --remove-orphans
run_cacheredis:
docker compose -f examples/redis-cache/docker-compose.yml up -d --remove-orphans
run_trustedips:
docker compose -f examples/trusted-ips/docker-compose.yml up -d --remove-orphans
run_binaryvm:
cd examples/binary-vm/ && sudo vagrant up
run_tlsauth:
docker compose -f examples/tls-auth/docker-compose.yml up -d --remove-orphans
run_appsec:
docker compose -f examples/appsec-enabled/docker-compose.yml up -d --remove-orphans
run_custom_captcha:
docker compose -f examples/custom-captcha/docker-compose.yml up -d --remove-orphans
run_captcha:
docker compose -f examples/captcha/docker-compose.yml up -d --remove-orphans
run_custom_ban_page:
docker compose -f examples/custom-ban-page/docker-compose.yml up -d --remove-orphans
run:
docker compose -f docker-compose.yml up -d --remove-orphans
restart_dev:
docker compose -f docker-compose.dev.yml restart
restart_local:
docker compose -f docker-compose.local.yml restart
restart:
docker compose -f docker-compose.yml restart
restart_behindproxy:
docker compose -f examples/behind-proxy/docker-compose.yml restart
restart_cacheredis:
docker compose -f examples/redis-cache/docker-compose.yml restart
restart_trustedips:
docker compose -f examples/trusted-ips/docker-compose.yml restart
restart_tlsauth:
docker compose -f examples/tls-auth/docker-compose.yml
restart_appsec:
docker compose -f examples/tls-auth/docker-compose.yml
restart_captcha:
docker compose -f examples/captcha/docker-compose.yml
restart_custombanpage:
docker compose -f examples/custom-ban-page/docker-compose.yml
show_logs:
docker compose -f docker-compose.yml restart
show_local_logs:
docker compose -f docker-compose.local.yml logs -f
show_dev_logs:
docker compose -f docker-compose.dev.yml logs -f
clean_all_docker:
docker compose -f examples/behind-proxy/docker-compose.yml down --remove-orphans
docker compose -f examples/redis-cache/docker-compose.yml down --remove-orphans
docker compose -f examples/trusted-ips/docker-compose.yml down --remove-orphans
docker compose -f examples/tls-auth/docker-compose.yml down --remove-orphans
docker compose -f examples/appsec-enabled/docker-compose.yml down --remove-orphans
docker compose -f examples/captcha/docker-compose.yml down --remove-orphans
docker compose -f examples/custom-captcha/docker-compose.yml down --remove-orphans
docker compose -f examples/custom-ban-page/docker-compose.yml down --remove-orphans
docker compose -f docker-compose.local.yml down --remove-orphans
docker compose -f docker-compose.yml down --remove-orphans
clean_vagrant:
cd examples/binary-vm/ && sudo vagrant destroy -f
show_metrics:
docker exec crowdsec cscli metrics
show_decisions:
docker exec crowdsec cscli decisions list