···167167168168 todo: get raspi vcgencmd outputs into metrics
169169170170+- nginx on gateway
171171+172172+ ```nginx
173173+ # in http
174174+175175+ ##
176176+ # cozy cache
177177+ ##
178178+ proxy_cache_path /var/cache/nginx keys_zone=cozy_zone:10m;
179179+180180+ ##
181181+ # cozy limit
182182+ ##
183183+ limit_req_zone $binary_remote_addr zone=cozy_ip_limit:10m rate=50r/s;
184184+ limit_req_zone $server_name zone=cozy_global_limit:10m rate=1000r/s;
185185+186186+ # in sites-available/linsks.bsky.bad-example.com
187187+188188+ upstream cozy_link_aggregator {
189189+ server link-aggregator:6789;
190190+ keepalive 16;
191191+ }
192192+193193+ server {
194194+ listen 8080;
195195+ listen [::]:8080;
196196+197197+ server_name links.bsky.bad-example.com;
198198+199199+ proxy_cache cozy_zone;
200200+ proxy_cache_background_update on;
201201+ proxy_cache_key "$scheme$proxy_host$uri$is_args$args$http_accept";
202202+ proxy_cache_lock on; # make simlutaneous requests for the same uri wait for it to appear in cache instead of hitting origin
203203+ proxy_cache_lock_age 1s;
204204+ proxy_cache_lock_timeout 2s;
205205+ proxy_cache_valid 10s; # default -- should be explicitly set in the response headers
206206+ proxy_cache_valid any 15s; # non-200s default
207207+ proxy_read_timeout 5s;
208208+ proxy_send_timeout 15s;
209209+ proxy_socket_keepalive on;
210210+211211+ limit_req zone=cozy_ip_limit nodelay burst=100;
212212+ limit_req zone=cozy_global_limit;
213213+ limit_req_status 429;
214214+215215+ location / {
216216+ proxy_pass http://cozy_link_aggregator;
217217+ include proxy_params;
218218+ proxy_http_version 1.1;
219219+ proxy_set_header Connection ""; # for keepalive
220220+ }
221221+ }
222222+ ```
223223+170224---
171225172226some todos
···179233 - [x] configure systemd to keep it alive
180234- [x] configure caddy cache
181235- [x] configure caddy rate-limit
182182-- [ ] configure caddy to use a health check (once it's added)
183183-- [ ] configure caddy to only expose cache metrics to tailnet :/
236236+- [ ] configure ~caddy~ nginx to use a health check (once it's added)
237237+- [ ] ~configure caddy to only expose cache metrics to tailnet :/~
184238- [x] make some grafana dashboards
185239- [ ] raspi: mount /dev/sda on boot
186240- [ ] raspi: run link_aggregator via systemd so it starts on startup (and restarts?)
187241242242+- [x] use nginx instead of caddy
243243+- [x] nginx: enable cache
244244+- [x] nginx: rate-limit
245245+- [ ] nginx: get metrics
+8
link_aggregator/readme.md
···118118- [ ] jetstream: connect retry: only reset counter after some *time* has passed.
119119- [x] either count or estimate the total number of links added (distinct from link targets)
120120121121+cache
122122+- [ ] set api response headers
123123+ - [ ] put "stale-while-revalidate" in Cache-Control w/ num seconds
124124+ - [ ] put "stale-if-error" in Cache-Control w/ num seconds
125125+ - [ ] set Expires or Cache-Control expires
126126+ - [ ] add Accept to vary response
127127+- [ ] cache vary: might need to take bsky account privacy setting into account (unless this ends up being in query)
128128+121129data fixes
122130- [x] add rkey to linkers 🤦♀️
123131- [x] don't remove deleted links from the reverse records -- null them out. this will keep things stable for paging.