Skip to content

Format logs on server #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN npm run build
FROM nginx:latest AS host

# COPY nginx-client.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf.template /etc/nginx/templates/

COPY --from=builder /app/build/ /usr/share/nginx/html
66 changes: 66 additions & 0 deletions src/client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format json_combined escape=json
'{'
'"timestamp":"$msec",'
'"address":"$remote_addr",'
'"request":"$request",'
'"body_bytes_sent":$body_bytes_sent,'
'"response_status":$status,'
'"http_user_agent":"$http_user_agent"'
'}';

access_log /var/log/nginx/access.log json_combined;

sendfile on;

keepalive_timeout 65;

include /etc/nginx/conf.d/*.conf;

server {
listen 80;
server_name localhost;
client_max_body_size 100M;

location ^~ /api/internal { # Blocks external access to /api/internal/*
return 404;
}



location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html; # forward all requests to the index.html for react
}

location /api {
try_files $uri @backend;
}

location @backend {
proxy_pass http://backend;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3600;
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
send_timeout 3600;
}
}
}
2 changes: 1 addition & 1 deletion src/server/bin/startServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ echo "SLEEPING.. WAITING FOR DB"; sleep 5; echo "WAKING"; alembic upgrade head;

# --no-reload prevents Flask restart, which usually happens in middle of create_base_users()
#TODO: SECURITY - ensure we are not running in debug mode in production
uwsgi --http-socket :5000 --plugin python38 --module wsgi:app --chdir /app --pythonpath . --processes 2 --threads 4 --master
uwsgi bin/uwsgi.ini
13 changes: 13 additions & 0 deletions src/server/bin/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[uwsgi]
http-socket = :5000
plugin = python38
module = wsgi:app
chdir = /app
pythonpath = .
processes = 2
threads = 4
log-4xx = true
log-5xx = true
disable-logging = true
logformat = {"timestamp": "%(tmsecs)", "address": "%(addr)", "method": "%(method)", "protocol": "%(proto)", "resp_size": "%(size)", "request_body_size": "%(cl)", "response_status": "%(status)", "response_time": "%(secs)", "uri": "%(uri)"}
logformat-strftime = true
2 changes: 1 addition & 1 deletion src/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="iso", utc=True ),
structlog.processors.TimeStamper(fmt=None, utc=True ),
structlog.processors.CallsiteParameterAdder(
[
CallsiteParameter.FILENAME,
Expand Down