1. Output of caddy version
: v2.6.1
2. How I run Caddy: docker container.
a. System environment: VM: Linux sles 15, Docker Server Version: 20.10.17-ce
c. Service/unit/compose file:
version: "3.7"
services:
caddy:
container_name: caddy
image: caddy:2.6.1
restart: always
build:
context: .
dockerfile: Dockerfile
volumes:
- "/opt/docker/monitoring/caddy/Caddyfile:/etc/caddy/Caddyfile"
- "/opt/docker/monitoring/caddy/data/caddy:/data"
- "/opt/docker/monitoring/caddy/config:/config"
- "/opt/docker/monitoring/caddy/log/:/var/log/"
ports:
- "80:80"
- "443:443"
labels:
logging: "promtail"
logging_jobname: "containerlogs"
networks:
- monitoring
networks:
monitoring:
external: true
d. My complete Caddy config:
{ [43/1095]
email ci@example.com
acme_ca https://acme.example.com:9001/acme/acme/directory
# ca_root /usr/local/share/ca-certificates/ca_bundle.crt
debug
}
#(logfile) {
#
#log {
# level info
# output file /var/log/mimir.log {
# roll_size 10MiB
# roll_keep 5
# roll_keep_for 120h
# }
# format json {
# time_format iso8601
#}
#}
#}
(logconsole) {
log {
output stdout
format json {
time_format iso8601
}
}
}
grafana.example.com {
reverse_proxy grafana:3000
}
prometheus.example.com {
reverse_proxy prometheus:9090
basicauth /* {
admin JDJhJDE0JEs3YWdTQm52cllTcnFPU2JVZĂ–LAJSDFĂ–ASO"WNASByc3JpV0JVbHZmMnkuMkpQT1MzeXJSWnhT
}
}
promtail.example.com {
reverse_proxy promtail:9080
basicauth /* {
admin JDJhJDE0JEs3YWdTQm52cllTcnFPU2JVZĂ–LAJSDFĂ–ASO"WNASByc3JpV0JVbHZmMnkuMkpQT1MzeXJSWnhT
}
}
telegraf.example.com {
reverse_proxy telegraf:9274
basicauth /* {
admin JDJhJDE0JEs3YWdTQm52cllTcnFPU2JVZĂ–LAJSDFĂ–ASO"WNASByc3JpV0JVbHZmMnkuMkpQT1MzeXJSWnhT
}
}
loki.example.com {
reverse_proxy loki:3100
basicauth /* {
admin JDJhJDE0JEs3YWdTQm52cllTcnFPU2JVZĂ–LAJSDFĂ–ASO"WNASByc3JpV0JVbHZmMnkuMkpQT1MzeXJSWnhT
}
}
mimir.example.com {
import logconsole
reverse_proxy * {
to mimir-1:8080
to mimir-2:8080
to mimir-3:8080
lb_policy round_robin
lb_try_duration 1s
lb_try_interval 250s
max_fails 1
}
}
3. The problem I’m having:
I have replicated Grafana Mimir, as load balancer I have used Caddy. When the Mimir containers are running everything works fine, as soon as one of the Mimir instances is killed, none of the containers are reachable.
I tested this with ngix to isolate the problem and to know if the problem is with the Mimir. With ngix, it works beautifully. I have tested all the “lb_policy”. Without success.
4. Error messages and/or full log output:
2023-01-17T11:15:20+01:00 {"level":"info","ts":"2023-01-17T10:15:20.038Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"Content-Length":["58949"],"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.008772353,"size":0,"status":200,"resp_headers":{"Date":["Tue, 17 Jan 2023 10:15:20 GMT"],"Content-Length":["0"],"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"]}}
2023-01-17T11:15:20+01:00 {"level":"debug","ts":1673950520.038858,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-1:8080","duration":0.008609509,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Encoding":["snappy"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Proto":["https"],"X-Scope-Orgid":["mimir"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Forwarded-Host":["mimir.example.com"],"Content-Length":["58949"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Content-Length":["0"],"Date":["Tue, 17 Jan 2023 10:15:20 GMT"]},"status":200}
2023-01-17T11:15:20+01:00 {"level":"debug","ts":1673950520.0301821,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-1:8080","total_upstreams":3}
2023-01-17T11:15:15+01:00 {"level":"debug","ts":1673950515.04695,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-2:8080","duration":0.030221084,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["mimir.example.com"],"Content-Type":["application/x-protobuf"],"Content-Encoding":["snappy"],"Content-Length":["19069"],"X-Forwarded-For":["172.18.0.1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"error":"dial tcp: lookup mimir-2 on 127.0.0.11:53: server misbehaving"}
2023-01-17T11:15:15+01:00 {"level":"info","ts":"2023-01-17T10:15:15.025Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Length":["20064"],"X-Scope-Orgid":["mimir"],"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.006742751,"size":0,"status":200,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Tue, 17 Jan 2023 10:15:15 GMT"],"Content-Length":["0"]}}
2023-01-17T11:15:15+01:00 {"level":"debug","ts":1673950515.0251415,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-3:8080","duration":0.006480216,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["mimir.example.com"],"Content-Length":["20064"],"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Forwarded-For":["172.18.0.1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Date":["Tue, 17 Jan 2023 10:15:15 GMT"],"Content-Length":["0"]},"status":200}
2023-01-17T11:15:15+01:00 {"level":"debug","ts":1673950515.0185485,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-3:8080","total_upstreams":3}
2023-01-17T11:15:15+01:00 {"level":"debug","ts":1673950515.0166483,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-2:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"info","ts":"2023-01-17T10:15:12.944Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"Content-Length":["119751"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.02324268,"size":0,"status":200,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"],"Server":["Caddy"]}}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.944365,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-1:8080","duration":0.023062001,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"X-Forwarded-Proto":["https"],"Content-Type":["application/x-protobuf"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"Content-Length":["119751"],"Content-Encoding":["snappy"],"X-Forwarded-For":["172.18.0.1"],"User-Agent":["Prometheus/2.37.4"],"X-Scope-Orgid":["mimir"],"X-Forwarded-Host":["mimir.example.com"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"]},"status":200}
2023-01-17T11:15:12+01:00 {"level":"info","ts":"2023-01-17T10:15:12.940Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"Content-Length":["116491"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.02442146,"size":0,"status":200,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"]}}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.940705,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-3:8080","duration":0.024193038,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Encoding":["snappy"],"X-Scope-Orgid":["mimir"],"Content-Length":["116491"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["mimir.example.com"],"Content-Type":["application/x-protobuf"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"]},"status":200}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9229634,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-2:8080","duration":0.021805588,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Length":["29350"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Proto":["https"],"Content-Type":["application/x-protobuf"],"Content-Encoding":["snappy"],"X-Scope-Orgid":["mimir"],"X-Forwarded-Host":["mimir.example.com"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"error":"dial tcp: lookup mimir-2 on 127.0.0.11:53: server misbehaving"}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9228976,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-2:8080","duration":0.024956551,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Length":["31867"],"Content-Type":["application/x-protobuf"],"X-Forwarded-Host":["mimir.example.com"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Proto":["https"],"Content-Encoding":["snappy"],"User-Agent":["Prometheus/2.37.4"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"error":"dial tcp: lookup mimir-2 on 127.0.0.11:53: server misbehaving"}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9212196,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-1:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9164207,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-3:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"info","ts":"2023-01-17T10:15:12.912Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Type":["application/x-protobuf"],"Content-Length":["37835"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"Content-Encoding":["snappy"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.011408476,"size":0,"status":200,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Length":["0"],"Date":["Tue, 17 Jan 2023 10:15:12 GMT"]}}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9124403,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-1:8080","duration":0.011056799,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"Content-Type":["application/x-protobuf"],"X-Forwarded-Proto":["https"],"User-Agent":["Prometheus/2.37.4"],"Content-Encoding":["snappy"],"Content-Length":["37835"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Host":["mimir.example.com"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"]},"status":200}
2023-01-17T11:15:12+01:00 {"level":"info","ts":"2023-01-17T10:15:12.912Z","logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Scope-Orgid":["mimir"],"Content-Encoding":["snappy"],"Content-Type":["application/x-protobuf"],"Content-Length":["37897"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"user_id":"","duration":0.012061571,"size":0,"status":200,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"],"Server":["Caddy"]}}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.911698,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"mimir-3:8080","duration":0.01161726,"request":{"remote_ip":"172.18.0.1","remote_port":"51046","proto":"HTTP/2.0","method":"POST","host":"mimir.example.com","uri":"/api/v1/push","headers":{"X-Scope-Orgid":["mimir"],"Content-Encoding":["snappy"],"X-Forwarded-Host":["mimir.example.com"],"Content-Type":["application/x-protobuf"],"Content-Length":["37897"],"User-Agent":["Prometheus/2.37.4"],"X-Prometheus-Remote-Write-Version":["0.1.0"],"X-Forwarded-For":["172.18.0.1"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mimir.example.com"}},"headers":{"Date":["Tue, 17 Jan 2023 10:15:12 GMT"],"Content-Length":["0"]},"status":200}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9011023,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-1:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.9011018,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-2:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.8999825,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-3:8080","total_upstreams":3}
2023-01-17T11:15:12+01:00 {"level":"debug","ts":1673950512.8977985,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"mimir-2:8080","total_upstreams":3}
5. What I already tried:
Tested with nginx load balancer and it works, that’s exactly what I want to do with Caddy.
events {
worker_connections 1024;
}
http {
upstream backend {
server mimir-1:8080 max_fails=1 fail_timeout=1s;
server mimir-2:8080 max_fails=1 fail_timeout=1s;
server mimir-3:8080 max_fails=1 fail_timeout=1s backup;
}
server {
listen 9009;
access_log /dev/null;
location / {
proxy_pass http://backend;
}
}
}