Skip to content

Commit 67cfcf3

Browse files
committed
Add HAProxy monitoring dashboard features
- Introduced a new `dashboard` frontend in HAProxy configuration to serve a real-time monitoring dashboard. - Added support for returning prebuilt `dashboard.html` for `/` or `/index.html` paths. - Updated test cases and expected outputs to accommodate the new frontend.
1 parent 580c904 commit 67cfcf3

9 files changed

Lines changed: 186 additions & 1 deletion

File tree

deploy/docker/assets/etc/easyhaproxy/www/dashboard.html

Lines changed: 103 additions & 0 deletions
Large diffs are not rendered by default.

src/templates/haproxy.cfg.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ frontend stats
9191
backend srv_stats
9292
mode http
9393
server Local 127.0.0.1:{{ data_stats["port"] | default(1936) }}
94+
95+
frontend dashboard
96+
bind *:{{ (data_stats["port"] | default(1936) | int) + 10000 }}
97+
mode http
98+
acl is_index path /
99+
acl is_index path /index.html
100+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
101+
http-request return status 404
94102
{% endif %}
95103
{% for o in data["easymapping"] -%}
96104
{% set mode = o["mode"] or "http" %}

tests/conftest.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,46 @@
1616
os.environ["EASYHAPROXY_BASE_PATH"] = _test_session_dir
1717

1818

19+
_CONTAINER_ENV_VARS = [
20+
"HAPROXY_USERNAME",
21+
"HAPROXY_PASSWORD",
22+
"HAPROXY_STATS_PORT",
23+
"HAPROXY_STATS_CORS_ORIGIN",
24+
"HAPROXY_CUSTOMERRORS",
25+
"EASYHAPROXY_SSL_MODE",
26+
"EASYHAPROXY_LABEL_PREFIX",
27+
"EASYHAPROXY_LOG_LEVEL",
28+
"HAPROXY_LOG_LEVEL",
29+
"CERTBOT_LOG_LEVEL",
30+
"EASYHAPROXY_CERTBOT_EMAIL",
31+
"EASYHAPROXY_CERTBOT_SERVER",
32+
"EASYHAPROXY_CERTBOT_AUTOCONFIG",
33+
"EASYHAPROXY_CERTBOT_EAB_KID",
34+
"EASYHAPROXY_CERTBOT_EAB_HMAC_KEY",
35+
"EASYHAPROXY_PLUGINS_ENABLED",
36+
"EASYHAPROXY_PLUGINS_ABORT_ON_ERROR",
37+
]
38+
39+
1940
@pytest.fixture(scope="function", autouse=True)
2041
def reset_consts():
2142
"""
22-
Reset Consts before and after each test.
43+
Reset Consts and ContainerEnv environment variables before and after each test.
2344
2445
This ensures:
2546
1. Each test picks up the EASYHAPROXY_BASE_PATH environment variable
2647
2. Tests don't get permission errors trying to write to /etc/easyhaproxy/
2748
3. Consts path cache is cleared between tests for isolation
49+
4. Environment variables set by ContainerEnv._yaml_to_env don't bleed across tests
2850
"""
2951
from functions import Consts
3052
Consts.reset()
53+
for var in _CONTAINER_ENV_VARS:
54+
os.environ.pop(var, None)
3155
yield
3256
Consts.reset()
57+
for var in _CONTAINER_ENV_VARS:
58+
os.environ.pop(var, None)
3359

3460

3561
def pytest_sessionfinish(session, exitstatus):

tests/expected/docker.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ backend srv_stats
3737
mode http
3838
server Local 127.0.0.1:1936
3939

40+
frontend dashboard
41+
bind *:11936
42+
mode http
43+
acl is_index path /
44+
acl is_index path /index.html
45+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
46+
http-request return status 404
47+
4048
frontend http_in_443
4149
bind *:443 ssl crt /etc/easyhaproxy/certs/certbot/ alpn h2,http/1.1 crt /etc/easyhaproxy/certs/haproxy/ alpn h2,http/1.1
4250
mode http

tests/expected/services-letsencrypt.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ backend srv_stats
4545
mode http
4646
server Local 127.0.0.1:1936
4747

48+
frontend dashboard
49+
bind *:11936
50+
mode http
51+
acl is_index path /
52+
acl is_index path /index.html
53+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
54+
http-request return status 404
55+
4856
frontend http_in_80
4957
bind *:80
5058
mode http

tests/expected/services-multiple-hosts.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ backend srv_stats
4545
mode http
4646
server Local 127.0.0.1:1937
4747

48+
frontend dashboard
49+
bind *:11937
50+
mode http
51+
acl is_index path /
52+
acl is_index path /index.html
53+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
54+
http-request return status 404
55+
4856
frontend http_in_19901
4957
bind *:19901
5058
mode http

tests/expected/ssl-loose.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ backend srv_stats
3535
mode http
3636
server Local 127.0.0.1:1936
3737

38+
frontend dashboard
39+
bind *:11936
40+
mode http
41+
acl is_index path /
42+
acl is_index path /index.html
43+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
44+
http-request return status 404
45+
3846
backend certbot_backend
3947
mode http
4048
server certbot 127.0.0.1:2080

tests/expected/static-cors.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ backend srv_stats
5252
mode http
5353
server Local 127.0.0.1:1936
5454

55+
frontend dashboard
56+
bind *:11936
57+
mode http
58+
acl is_index path /
59+
acl is_index path /index.html
60+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
61+
http-request return status 404
62+
5563
frontend http_in_80
5664
bind *:80
5765
mode http

tests/expected/static.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ backend srv_stats
4545
mode http
4646
server Local 127.0.0.1:1936
4747

48+
frontend dashboard
49+
bind *:11936
50+
mode http
51+
acl is_index path /
52+
acl is_index path /index.html
53+
http-request return status 200 content-type "text/html" file /etc/easyhaproxy/www/dashboard.html if is_index
54+
http-request return status 404
55+
4856
frontend http_in_443
4957
bind *:443 ssl crt /etc/easyhaproxy/certs/certbot/ alpn h2,http/1.1 crt /etc/easyhaproxy/certs/haproxy/ alpn h2,http/1.1
5058
mode http

0 commit comments

Comments
 (0)