diff --git a/Dockerfile b/Dockerfile index 0bf02231..18c4b2ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,13 +20,11 @@ ENV PYTHONUNBUFFERED True COPY --chown=kerrokantasi:kerrokantasi requirements.txt . COPY --chown=kerrokantasi:kerrokantasi requirements-prod.txt . -COPY --chown=kerrokantasi:kerrokantasi deploy/escape_json.c ./deploy/escape_json.c # less & netcat-openbsd are there for in-container manual debugging # kerrokantasi needs gdal RUN apt-get update \ && apt-get install -y \ - build-essential \ postgresql-client \ less \ netcat-openbsd \ @@ -39,10 +37,7 @@ RUN apt-get update \ && locale-gen \ && pip install --upgrade pip setuptools wheel \ && pip install --no-cache-dir -r ./requirements.txt \ - && pip install --no-cache-dir -r ./requirements-prod.txt \ - && uwsgi --build-plugin ./deploy/escape_json.c \ - && mv ./escape_json_plugin.so ./deploy/escape_json_plugin.so \ - && apt-get remove -y build-essential + && pip install --no-cache-dir -r ./requirements-prod.txt # Sentry CLI for sending events from non-Python processes to Sentry # eg. https://docs.sentry.io/cli/send-event/#bash-hook diff --git a/deploy/escape_json.c b/deploy/escape_json.c deleted file mode 100644 index f9943c7b..00000000 --- a/deploy/escape_json.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - https://github.com/velebit-ai/uwsgi-json-logging-plugin/blob/4edb5cc59013b18f32658195b328afb2ac21b2d2/escape_json.c - uWSGI plugin that creates custom json-escaped logging variables. - build plugin with `uwsgi --build-plugin ` - and use it with `uwsgi --plugin ...` -*/ -#include - - -static ssize_t uwsgi_lf_json_uri(struct wsgi_request *wsgi_req, char **buf) { - long pos = offsetof(struct wsgi_request, uri); - long pos_len = offsetof(struct wsgi_request, uri_len); - char **var = (char **) (((char *) wsgi_req) + pos); - uint16_t *varlen = (uint16_t *) (((char *) wsgi_req) + pos_len); - - char *e_json = uwsgi_malloc((*varlen * 2) + 1); - escape_json(*var, *varlen, e_json); - *buf = e_json; - return strlen(*buf); -} - -static ssize_t uwsgi_lf_json_host(struct wsgi_request *wsgi_req, char **buf) { - long pos = offsetof(struct wsgi_request, host); - long pos_len = offsetof(struct wsgi_request, host_len); - char **var = (char **) (((char *) wsgi_req) + pos); - uint16_t *varlen = (uint16_t *) (((char *) wsgi_req) + pos_len); - - char *e_json = uwsgi_malloc((*varlen * 2) + 1); - escape_json(*var, *varlen, e_json); - *buf = e_json; - return strlen(*buf); -} - -static void register_logchunks() { - uwsgi_register_logchunk("json_uri", uwsgi_lf_json_uri, 1); - uwsgi_register_logchunk("json_host", uwsgi_lf_json_host, 1); -} - -struct uwsgi_plugin escape_json_plugin = { - .name = "escape_json", - .on_load = register_logchunks, -}; diff --git a/deploy/uwsgi.yml b/deploy/uwsgi.yml index 78885b5b..1a1e09fd 100644 --- a/deploy/uwsgi.yml +++ b/deploy/uwsgi.yml @@ -1,5 +1,4 @@ uwsgi: - plugin: deploy/escape_json_plugin.so # Needed plugins if running against Debian uwsgi-package # python docker image cannot use that due to linker mishaps # plugins: python3,http @@ -23,6 +22,6 @@ uwsgi: disable-write-exception: true logger-req: stdio - log-format: '"remote_addr": "%(addr)", "x_forwarded_for":"%(var.HTTP_X_FORWARDED_FOR)", "request_id":"%(var.HTTP_X_REQUEST_ID)", "remote_user":"%(user)", "bytes_sent":%(size), "request_time":%(secs), "status":%(status), "host":"%(json_host)", "request_proto":"%(proto)", "path":"%(json_uri)", "request_length":%(cl), "http_referer":"%(referer)", "http_user_agent":"%(uagent)"' + log-format: '"remote_addr": "%(addr)", "x_forwarded_for":"%(var.HTTP_X_FORWARDED_FOR)", "request_id":"%(var.HTTP_X_REQUEST_ID)", "remote_user":"%(user)", "bytes_sent":%(size), "request_time":%(secs), "status":%(status), "host":"%(host)", "request_proto":"%(proto)", "path":"%(uri)", "request_length":%(cl), "http_referer":"%(referer)", "http_user_agent":"%(uagent)"' log-req-encoder: format {"time":"${strftime:%%Y:%%m:%%d %%H:%%M:%%S}", "source":"uwsgi-req", ${msg}} log-req-encoder: nl