From df1a3819090b42f32fb4de599aee96a9f57b3ef5 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Wed, 6 Apr 2022 12:11:02 +0200 Subject: [PATCH 01/42] add ddtrace --- backend/metrics.py | 7 +++++++ backend/requirements.txt | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/metrics.py b/backend/metrics.py index 93dbbaa..f2c57d3 100644 --- a/backend/metrics.py +++ b/backend/metrics.py @@ -1,6 +1,7 @@ import os import time from datadog import initialize, api +from ddtrace import tracer class Metrics: send_metrics = False @@ -11,6 +12,12 @@ class Metrics: Metrics.send_metrics = True initialize() api.Event.create(title="Backend start", text="", tags=["server:backend", f"host:{os.environ['HOST']}"], alert_type="info") + if "DD_TRACE_AGENT_HOST" in os.environ and "DD_TRACE_AGENT_PORT" in os.environ: + tracer.configure( + https=False, + hostname=os.environ["DD_TRACE_AGENT_HOST"], + port=os.environ["DD_TRACE_AGENT_PORT"], + ) else: print("Datadog not configured") diff --git a/backend/requirements.txt b/backend/requirements.txt index 3963313..37936e8 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -8,4 +8,5 @@ six==1.16.0 pytest==7.1.1 requests==2.27.1 discord-webhook==0.15.0 -datadog==0.44.0 \ No newline at end of file +datadog==0.44.0 +ddtrace==0.60.1 \ No newline at end of file From 94735d17758cc3fe391d32ba946ccdce564492be Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Wed, 6 Apr 2022 16:19:03 +0200 Subject: [PATCH 02/42] remove armv7 and add ddtrace command to docker --- .github/workflows/dev-image.yml | 12 +----------- backend/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dev-image.yml b/.github/workflows/dev-image.yml index 6e4d839..3221215 100644 --- a/.github/workflows/dev-image.yml +++ b/.github/workflows/dev-image.yml @@ -42,16 +42,6 @@ jobs: --output "type=image,push=false" \ --tag albertoxamin/bang:dev \ --file ./Dockerfile ./ - - - name: Docker Buildx (build armv-7) - run: | - docker buildx build \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - --platform linux/arm/v7 \ - --output "type=image,push=false" \ - --tag albertoxamin/bang:dev \ - --file ./Dockerfile ./ - name: Login to DockerHub uses: docker/login-action@v1 @@ -63,7 +53,7 @@ jobs: run: | docker buildx build \ --cache-from "type=local,src=/tmp/.buildx-cache" \ - --platform linux/amd64,linux/arm/v7,linux/arm64 \ + --platform linux/amd64,linux/arm64 \ --output "type=image,push=true" \ --tag albertoxamin/bang:dev \ --file ./Dockerfile ./ diff --git a/backend/Dockerfile b/backend/Dockerfile index df7d29e..c956f0d 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -8,4 +8,4 @@ RUN RUN apt-get update && apt-get install -y \ RUN pip install -r requirements.txt EXPOSE 5001 -ENTRYPOINT ["python", "/code/__init__.py"] \ No newline at end of file +ENTRYPOINT ["ddtrace-run", "python", "/code/__init__.py"] \ No newline at end of file From 78b0f9fe7ce7e16971231e30a6b1db48465ba267 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Thu, 7 Apr 2022 09:44:11 +0200 Subject: [PATCH 03/42] change the right dockerfile --- Dockerfile | 7 ++++++- backend/metrics.py | 7 ------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa47374..b7da2d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,4 +22,9 @@ COPY --from=builder ./dist /dist/ WORKDIR /dist EXPOSE 5001 -ENTRYPOINT ["python", "/dist/server.py"] +ENV DD_SERVICE="bang-backend" +ENV DD_ENV="dev-test" +ENV DD_LOGS_INJECTION=true +ENV DD_PROFILING_ENABLED=true + +ENTRYPOINT ["ddtrace-run", "python", "/dist/server.py"] diff --git a/backend/metrics.py b/backend/metrics.py index f2c57d3..93dbbaa 100644 --- a/backend/metrics.py +++ b/backend/metrics.py @@ -1,7 +1,6 @@ import os import time from datadog import initialize, api -from ddtrace import tracer class Metrics: send_metrics = False @@ -12,12 +11,6 @@ class Metrics: Metrics.send_metrics = True initialize() api.Event.create(title="Backend start", text="", tags=["server:backend", f"host:{os.environ['HOST']}"], alert_type="info") - if "DD_TRACE_AGENT_HOST" in os.environ and "DD_TRACE_AGENT_PORT" in os.environ: - tracer.configure( - https=False, - hostname=os.environ["DD_TRACE_AGENT_HOST"], - port=os.environ["DD_TRACE_AGENT_PORT"], - ) else: print("Datadog not configured") From 9af8a85df3888e6fe9336e4d5781bd38673d2ce8 Mon Sep 17 00:00:00 2001 From: Giulio Date: Thu, 7 Apr 2022 23:30:28 +0200 Subject: [PATCH 04/42] fix ddtrace PATH --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7da2d5..d54c6f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,9 +22,12 @@ COPY --from=builder ./dist /dist/ WORKDIR /dist EXPOSE 5001 -ENV DD_SERVICE="bang-backend" -ENV DD_ENV="dev-test" +ENV DD_SERVICE=bang-backend +ENV DD_ENV=dev-test ENV DD_LOGS_INJECTION=true ENV DD_PROFILING_ENABLED=true +ENV DD_TRACE_AGENT_URL=http://0.0.0.0:8126 + +ENV PATH=/root/.local/bin:${PATH} ENTRYPOINT ["ddtrace-run", "python", "/dist/server.py"] From 19bea99961632046b794267a3fdbf9acca8a686b Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sun, 10 Apr 2022 19:08:36 +0200 Subject: [PATCH 05/42] add datadog proxy --- backend/server.py | 21 +++++++++++++++++++-- frontend/src/App.vue | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/backend/server.py b/backend/server.py index b3e4daa..7ebe1b8 100644 --- a/backend/server.py +++ b/backend/server.py @@ -13,7 +13,6 @@ import requests from discord_webhook import DiscordWebhook from metrics import Metrics - Metrics.init() import sys @@ -612,6 +611,24 @@ def pool_metrics(): Metrics.send_metric('online_players', points=[online_players]) pool_metrics() +import urllib.parse +class CustomProxyFix(object): + def __init__(self, app): + self.app = app + print('init') + + def __call__(self, environ, start_response): + path = environ.get('PATH_INFO', '') + if 'ddproxy' in path: + newurl = urllib.parse.unquote(environ['QUERY_STRING'].replace('ddforward=', '')) + heads = {'X-Forwarded-For': environ['REMOTE_ADDR']} + for h in environ['headers_raw']: + heads[h[0]] = h[1] + r = requests.post(newurl, data=environ['wsgi.input'].read(), headers=heads) + start_response('200 OK', []) + return [''] + return self.app(environ, start_response) + if __name__ == '__main__': sio.start_background_task(pool_metrics) - eventlet.wsgi.server(eventlet.listen(('', 5001)), app) + eventlet.wsgi.server(eventlet.listen(('', 5001)), CustomProxyFix(app)) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index dda5d6d..14e7005 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -48,7 +48,7 @@