From 44c38faa0b9b0bfc83092d25c487be89891883dc Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 4 Sep 2020 13:00:27 +0200 Subject: [PATCH 1/3] drop health-check endpoint from access.log --- docker/nginx/conf.d/client.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 8a68f603..255caf3d 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -108,6 +108,8 @@ server { location /health-check { include /etc/nginx/conf.d/include/cors; + access_log off; # do not log traffic to health-check endpoint + proxy_pass http://health-check:3100; } From cd7696c97dd7c967e972497223b21ddf1a142480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Tue, 8 Dec 2020 12:21:20 +0100 Subject: [PATCH 2/3] fix /portals and /stats rewrites (#561) --- docker/nginx/conf.d/client.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 4d8a904b..a82601f5 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -54,9 +54,9 @@ server { client_max_body_size 128k; # legacy endpoint rewrite - rewrite /portals /skynet/portals permanent; - rewrite /stats /skynet/stats permanent; - rewrite /skynet/blacklist /skynet/blocklist permanent; + rewrite ^/portals /skynet/portals permanent; + rewrite ^/stats /skynet/stats permanent; + rewrite ^/skynet/blacklist /skynet/blocklist permanent; location / { # This is only safe workaround to reroute based on some conditions From 83d2aa396ed1b335a8e1807d8fab1979b279a0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Thu, 10 Dec 2020 14:43:59 +0100 Subject: [PATCH 3/3] allow to include previous skynet stats (#562) * allow to include previous skynet stats * explain chunked response --- docker-compose.yml | 1 + docker/nginx/conf.d/client.conf | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index b3d2ae3d..534428aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -72,6 +72,7 @@ services: - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro - ./docker/data/nginx/cache:/data/nginx/cache - ./docker/data/nginx/logs:/usr/local/openresty/nginx/logs + - ./docker/data/nginx/skynet:/data/nginx/skynet:ro - ./docker/data/sia/apipassword:/data/sia/apipassword:ro - webapp:/var/www/webportal:ro networks: diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index a82601f5..4d76586a 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -105,6 +105,33 @@ server { location /skynet/stats { include /etc/nginx/conf.d/include/cors; + set $response_body ''; # we need a variable for full response body (not chuncked) + + # modify the response to add numfiles and totalsize to account for node rotation + # example prevstats.lua: 'return { numfiles = 12345, totalsize = 123456789 }' + body_filter_by_lua_block { + local file_exists = io.open("/data/nginx/skynet/prevstats.lua") + if file_exists then + file_exists.close() + + -- because response data is chunked, we need to concat ngx.arg[1] until + -- last chunk is received (when ngx.arg[2] is set to true) + ngx.var.response_body = ngx.var.response_body .. ngx.arg[1] + + if ngx.arg[2] then + local json = require('cjson') + local prevstats = require('/data/nginx/skynet/prevstats') + local stats = json.decode(ngx.var.response_body) + stats.uploadstats.numfiles = stats.uploadstats.numfiles + prevstats.numfiles + stats.uploadstats.totalsize = stats.uploadstats.totalsize + prevstats.totalsize + ngx.arg[1] = json.encode(stats) + else + -- do not send any data in this chunk (wait for last chunk) + ngx.arg[1] = nil + end + end + } + proxy_cache skynet; proxy_cache_valid any 10m; # cache stats for 10 minutes proxy_set_header User-Agent: Sia-Agent;