diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 01538b5..6d95c0f 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -3,11 +3,11 @@ FROM ghcr.io/aasaam/nginx-extra:latest ENV ASM_NGX_EXTRA_WORKER_PROCESSES="auto" \ ASM_NGX_EXTRA_WORKER_RLIMIT_NOFILE="80000" \ ASM_NGX_EXTRA_ERROR_LOG_LEVEL="warn" \ - ASM_NGX_EXTRA_WORKER_CONNECTIONS="2048" \ + ASM_NGX_EXTRA_WORKER_CONNECTIONS="4096" \ ASM_NGX_EXTRA_CLIENT_BODY_TIMEOUT="4s" \ ASM_NGX_EXTRA_CLIENT_HEADER_TIMEOUT="4s" \ ASM_NGX_EXTRA_KEEPALIVE_REQUESTS="20480" \ - ASM_NGX_EXTRA_KEEPALIVE_TIMEOUT="30" \ + ASM_NGX_EXTRA_KEEPALIVE_TIMEOUT="10" \ ASM_NGX_EXTRA_SEND_TIMEOUT="2" \ ASM_NGX_EXTRA_CLIENT_BODY_BUFFER_SIZE="256k" \ ASM_NGX_EXTRA_CLIENT_HEADER_BUFFER_SIZE="2k" \ @@ -16,8 +16,8 @@ ENV ASM_NGX_EXTRA_WORKER_PROCESSES="auto" \ ASM_NGX_EXTRA_CLIENT_MAX_BODY_SIZE="2m" \ ASM_NGX_EXTRA_PROXY_CACHE_FAST_SIZE="128m" \ ASM_NGX_EXTRA_ACCESS_LOG_COMMENT="#" \ - ASM_NGX_EXTRA_SSL_PROFILE="legacy" \ - ASM_NGX_EXTRA_UPSTREAM="http://analytics-collector-producer:4000" + ASM_NGX_EXTRA_SSL_PROFILE="legacy" ADD nginx/nginx.conf /template/nginx.conf +ADD nginx/upstream.conf /upstream.conf ADD nginx/cert /cert diff --git a/http_record.go b/http_record.go index 082bd99..9ef3292 100644 --- a/http_record.go +++ b/http_record.go @@ -208,30 +208,27 @@ func httpRecord( ) } - _, redErr := redisClient.LPush(context.Background(), redisKeyRecords, recordBytes).Result() + go func() { + _, redErr := redisClient.LPush(context.Background(), redisKeyRecords, recordBytes).Result() + if redErr != nil { + blockErr := errorInternalDependencyFailed + blockErr.debug = redErr.Error() - if redErr != nil { - blockErr := errorInternalDependencyFailed - blockErr.debug = redErr.Error() - - conf.getLogger(). - Error(). - Str("part", "finalize"). - Str("on", blockErr.msg). - Str("error", blockErr.debug). - Str("ip", ip.String()). - Str("method", c.Method()). - Str("path", c.Path()). - Str("qs", string(c.Request().URI().QueryString())). - Str("body", string(c.Request().Body())). - Strs("headers", rawHeaderLog(c.Request().Header.RawHeaders())). - Send() + conf.getLogger(). + Error(). + Str("part", "finalize"). + Str("on", blockErr.msg). + Str("error", blockErr.debug). + Str("ip", ip.String()). + Str("method", c.Method()). + Str("path", c.Path()). + Str("qs", string(c.Request().URI().QueryString())). + Str("body", string(c.Request().Body())). + Strs("headers", rawHeaderLog(c.Request().Header.RawHeaders())). + Send() - return httpErrorResponse( - c, - blockErr, - ) - } + } + }() if record.isImage() { return responseImage(c) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 280241f..02881ad 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -23,6 +23,8 @@ http { include /.defaults/http.conf; + include /upstream.conf; + client_body_timeout ${ASM_NGX_EXTRA_CLIENT_BODY_TIMEOUT}; client_header_timeout ${ASM_NGX_EXTRA_CLIENT_HEADER_TIMEOUT}; keepalive_requests ${ASM_NGX_EXTRA_KEEPALIVE_REQUESTS}; @@ -38,11 +40,14 @@ http { proxy_buffering on; proxy_buffers 16 128k; proxy_buffer_size 128k; - proxy_cache_methods GET HEAD; - proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504 http_429; proxy_http_version 1.1; proxy_read_timeout 20s; - proxy_cache_valid 200 301 4m; + proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504 http_429; + proxy_cache_methods GET HEAD; + proxy_cache_valid 200 206 301 10m; + proxy_cache_lock_timeout 0s; + proxy_cache_lock_age 60s; + proxy_cache_lock on; proxy_request_buffering off; # proxy cache @@ -83,8 +88,6 @@ http { ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA; ssl_prefer_server_ciphers on; - - location = /stub_status { allow 127.0.0.0/8; allow 192.168.0.0/16; @@ -131,7 +134,7 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache PROXY_CACHE_FAST; - proxy_pass ${ASM_NGX_EXTRA_UPSTREAM}; + proxy_pass http://producers; ${ASM_NGX_EXTRA_ACCESS_LOG_COMMENT} access_log /dev/stdout http_jsonlog if=$loggable; } diff --git a/nginx/upstream.conf b/nginx/upstream.conf new file mode 100644 index 0000000..79489fb --- /dev/null +++ b/nginx/upstream.conf @@ -0,0 +1,8 @@ +upstream producers { + server analytics-collector-producer:4000; + # server analytics-collector-producer-0:4000; + # server analytics-collector-producer-1:4000; + # server analytics-collector-producer-2:4000; + # server analytics-collector-producer-3:4000; + # server analytics-collector-producer-4:4000; +}