From 39f597b8eb82204c357c034a42b6417d8de724e4 Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:20:03 -0500 Subject: [PATCH] [mini-relay] collect data (#348) --- docker-compose.yml | 1 + mini-relay/app.py | 14 +++++++++++++- mini-relay/data/.gitignore | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 mini-relay/data/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 5afdb1ea..7628523c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: build: mini-relay init: true ports: [9989:9989] + volumes: [./mini-relay/data:/data:rw] postgres: image: 'postgres:alpine' environment: diff --git a/mini-relay/app.py b/mini-relay/app.py index e03895ce..0fefc9ee 100644 --- a/mini-relay/app.py +++ b/mini-relay/app.py @@ -1,5 +1,9 @@ from __future__ import annotations +import os +import gzip +import time + import flask app = flask.Flask(__name__) @@ -7,7 +11,15 @@ @app.post('/api/
/envelope/') def envelope(p: str) -> flask.Response: - # TODO: save out flask.request.data + if flask.request.headers.get('content-encoding', 'identity') == 'gzip': + data = gzip.decompress(flask.request.data) + else: + data = flask.request.data + + os.makedirs(f'/data/{p}', exist_ok=True) + with open(f'/data/{p}/{time.monotonic()}', 'wb') as f: + f.write(data) + ret = app.make_response(('', 204)) ret.access_control_allow_origin = '*' return ret diff --git a/mini-relay/data/.gitignore b/mini-relay/data/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/mini-relay/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore