Skip to content

Commit 46c75b6

Browse files
committed
separate health check
1 parent 034d3e3 commit 46c75b6

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

avgate/avgate.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from email.message import EmailMessage
1313
from typing import List, cast
1414
from urllib.parse import unquote, urlparse
15-
from prometheus_flask_instrumentator import PrometheusFlaskInstrumentator
1615

1716
import lxml.etree as ET
1817
import requests
@@ -36,7 +35,7 @@
3635
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
3736

3837
app = Flask(__name__)
39-
PrometheusFlaskInstrumentator().instrument(app).expose(app)
38+
4039
config = configparser.ConfigParser()
4140

4241
config.read("avgate.ini")
@@ -119,7 +118,7 @@ def health():
119118
res = check_clamav() or ""
120119
res += check_icap() or ""
121120
if res:
122-
return Response(res, mimetype="text/xml", status=503)
121+
return Response(res, mimetype="text/plain", status=503)
123122
return "OK"
124123

125124

@@ -150,7 +149,7 @@ def check():
150149
)
151150

152151
if test.ok:
153-
res += f"{konn}: ok"
152+
res += f"{konn}: ok \n"
154153
else:
155154
err_count += 1
156155
res += f"{client} {konn}: {test.status_code} \n"
@@ -163,7 +162,7 @@ def check():
163162
res += f"{client} {konn}: {err} \n"
164163
logger.warn(f"check failed for Konnektor: {client} {konn} {err}")
165164

166-
return Response(res, mimetype="text/xml", status=503 if err_count else 200)
165+
return Response(res, mimetype="text/plain", status=503 if err_count else 200)
167166

168167

169168
def check_clamav():

docs/develop.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ Für den Zugriff ohne Nginx ist ein Beispiel unter ./script/retrieveDocumentSet-
66
Für den Zugriff mit Nginx muss dieser umkonfiguriert werden. In nginx.conf statt uwsgi die Zeilen für den Fallback konfigurieren
77

88
```
9-
proxy_set_header X-real-ip $remote_addr;
10-
proxy_set_header host $server_addr:$server_port;
11-
proxy_pass "http://127.0.0.1:5001";
9+
proxy_set_header X-real-ip $remote_addr;
10+
proxy_set_header host $server_addr:$server_port;
11+
proxy_pass "http://127.0.0.1:5001";
1212
```
1313

14-
14+
Ein lokaler icap server kann gestartet werden über
15+
```
16+
docker build -t c-icap c-icap
17+
docker run -p 1344:1344 --rm --name c-icap c-icap
18+
```

nginx.conf

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
### for more information
3-
#error_log /opt/homebrew/var/log/nginx/error.log info;
3+
# error_log ~/Library/Logs/Homebrew/nginx/error.log info;
44

55
events {
66
worker_connections 1024;
@@ -11,7 +11,6 @@ http {
1111
server {
1212
# entry point for clients
1313
listen 8400-8500 ssl;
14-
# listen 5002 ssl;
1514

1615
# TLS
1716
ssl_certificate /Users/nferc/Workspace/gematik/ePa_av-gate/cert/server.cert;
@@ -22,27 +21,28 @@ http {
2221
ssl_verify_client on;
2322

2423
# only pass PHRService and connector.sds to av-gate
25-
# location ~ ^/(soap-api/PHRService|connector.sds|health|check) {
24+
# location ~ ^/(soap-api/PHRService|connector.sds) {
2625
location / {
27-
2826
proxy_redirect off;
2927
proxy_set_header X-Client-Cert $ssl_client_s_dn;
3028

3129
### uwsgi preferred
32-
# include docker/uwsgi_params;
33-
# uwsgi_param HTTP_X_REAL_IP $remote_addr;
34-
# uwsgi_pass localhost:5001;
35-
36-
### Fallback for no uwsgi
37-
include /opt/homebrew/etc/nginx/uwsgi_params;
38-
proxy_set_header X-real-ip $remote_addr;
39-
proxy_set_header host $server_addr:$server_port;
40-
proxy_pass "http://127.0.0.1:5001";
30+
uwsgi_param HTTP_X_REAL_IP $remote_addr;
31+
include docker/uwsgi_params;
32+
uwsgi_pass localhost:8080;
33+
34+
### Fallback for no uwsgi (dev only)
35+
# include /opt/homebrew/etc/nginx/uwsgi_params;
36+
# proxy_set_header X-real-ip $remote_addr;
37+
# proxy_set_header host $server_addr:$server_port;
38+
# proxy_pass "http://127.0.0.1:5001";
4139
}
4240

4341
# bypass other services to connector (optional)
4442
# only neccessary for av_proxy.ini/[konnektor]/proxy_all_services = true
4543
# this reduce workload for av-gate dramatically and should be used when proxy_all_services is set.
44+
# you have to set the location for the previous section to "~ ^/(soap-api/PHRService|connector.sds)"
45+
4646
# location / {
4747
# proxy_ssl_certificate /Users/nferc/Workspace/gematik/ePa_av-gate/cert/kclient.cert;
4848
# proxy_ssl_certificate_key /Users/nferc/Workspace/gematik/ePa_av-gate/cert/kclient.key;
@@ -53,6 +53,17 @@ http {
5353

5454
# }
5555
}
56+
57+
# separate endpoint for health, check, metrics without ssl and m-tls
58+
server {
59+
listen 8300;
60+
location ~ ^/(health|check) {
61+
proxy_redirect off;
62+
uwsgi_param HTTP_X_REAL_IP $remote_addr;
63+
include docker/uwsgi_params;
64+
uwsgi_pass localhost:8080;
65+
}
66+
}
5667
}
5768

5869

requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ mypy==1.8.0
1717
mypy-extensions==1.0.0
1818
packaging==23.2
1919
pluggy==1.4.0
20-
prometheus-flask-instrumentator==4.1.1
21-
prometheus_client==0.20.0
2220
pycparser==2.21
2321
pytest==8.0.1
2422
requests==2.31.0

uwsgi.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ processes = 4
44
socket = localhost:8080
55

66
chdir = /Users/nferc/Workspace/gematik/ePa_av-gate
7-
wsgi-file = avgate.py
7+
module = avgate.avgate:app
88

99
# only when virtualenv was used on install
1010
virtualenv = venv

0 commit comments

Comments
 (0)