From b4c7d2b12d8834f61cb9d56d3fdcac1e89332870 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 17 Nov 2021 23:07:46 +0100 Subject: [PATCH] Added influx stuff --- birb_latency_collector/config.py | 8 +-- birb_latency_collector/utils/influx.py | 4 +- birb_latency_collector/views/report_view.py | 21 ++++++- k8s/configmap.yaml | 4 +- k8s/influxdb.yaml | 62 +++++++++++++++++++++ requirements.txt | 2 +- 6 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 k8s/influxdb.yaml diff --git a/birb_latency_collector/config.py b/birb_latency_collector/config.py index ff47a9c..d4b54b7 100644 --- a/birb_latency_collector/config.py +++ b/birb_latency_collector/config.py @@ -8,10 +8,8 @@ class Config: RELEASE_ID = os.environ.get("RELEASE_ID", "test") RELEASEMODE = os.environ.get("RELEASEMODE", "dev") - INFLUXDB_HOST = os.environ['INFLUXDB_HOST'] - INFLUXDB_PORT = os.environ['INFLUXDB_PORT'] - INFLUXDB_USER = os.environ['INFLUXDB_USER'] - INFLUXDB_PASSWORD = os.environ['INFLUXDB_PASSWORD'] - INFLUXDB_DATABASE = os.environ['INFLUXDB_DATABASE'] + INFLUXDB_V2_URL = os.environ['INFLUXDB_URL'] + INFLUXDB_V2_TOKEN = os.environ['INFLUXDB_TOKEN'] + INFLUXDB_V2_ORG = os.environ['INFLUXDB_ORG'] INFLUXDB_TIMEOUT = 30 diff --git a/birb_latency_collector/utils/influx.py b/birb_latency_collector/utils/influx.py index c3d43cb..d63caa7 100644 --- a/birb_latency_collector/utils/influx.py +++ b/birb_latency_collector/utils/influx.py @@ -1,4 +1,4 @@ #!/usr/bin/env python3 -from flask_influxdb import InfluxDB +from flask_influxdb2 import InfluxDB2 -influxdb_instance = InfluxDB() +influxdb_instance = InfluxDB2() diff --git a/birb_latency_collector/views/report_view.py b/birb_latency_collector/views/report_view.py index 9b7b545..63978ea 100644 --- a/birb_latency_collector/views/report_view.py +++ b/birb_latency_collector/views/report_view.py @@ -1,7 +1,26 @@ #!/usr/bin/env python3 from flask import jsonify, request, abort, current_app, Response from flask_classful import FlaskView +from utils import json_required, influxdb_instance +from influxdb_client import Point class ReportView(FlaskView): - pass + + @json_required + def post(self): + data = request.json + + points = [] + + for type_ in ['latency', 'queue', 'rate']: + if type_ in data['measurements']: + points.append( + Point(type_) + .tag("client", data['client']) + .tag("cloud", data['cloud']) + .field("latency", data['measurements'][type_]) + ) + + influxdb_instance.connection.write_api().write("alma", "alma", points) + return Response(status=201) diff --git a/k8s/configmap.yaml b/k8s/configmap.yaml index 458e48d..3ba2c45 100644 --- a/k8s/configmap.yaml +++ b/k8s/configmap.yaml @@ -9,4 +9,6 @@ data: SENTRY_DSN: RELEASE_ID: kmlabz-k8s RELEASEMODE: release - + INFLUXDB_URL: http://birb-latency-influxdb:8086 + INFLUXDB_TOKEN: my-super-secret-auth-token + INFLUXDB_ORG: alma diff --git a/k8s/influxdb.yaml b/k8s/influxdb.yaml new file mode 100644 index 0000000..011f51d --- /dev/null +++ b/k8s/influxdb.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: birb-latency-influxdb + namespace: birbnetes + labels: + app: birb-latency-influxdb +spec: + replicas: 1 + selector: + matchLabels: + app: birb-latency-influxdb + strategy: + type: Recreate + template: + metadata: + labels: + app: birb-latency-influxdb + spec: + containers: + - image: "influxdb:2.1" + imagePullPolicy: Always + name: birb-latency-influxdb + envFrom: + - configMapRef: + name: birb-latency-influxdb + ports: + - containerPort: 8086 + imagePullSecrets: + - name: regcred +--- +apiVersion: v1 +kind: Service +metadata: + name: birb-latency-influxdb + namespace: birbnetes + labels: + app: birb-latency-influxdb +spec: + ports: + - name: birb-latency-influxdb + port: 8086 + targetPort: 8086 + protocol: TCP + selector: + app: birb-latency-influxdb + type: ClusterIP +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: birb-latency-influxdb + labels: + app: birb-latency-influxdb + namespace: birbnetes +data: + DOCKER_INFLUXDB_INIT_USERNAME: admin + DOCKER_INFLUXDB_INIT_PASSWORD: adminadmin + DOCKER_INFLUXDB_INIT_ORG: alma + DOCKER_INFLUXDB_INIT_BUCKET: alma + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: my-super-secret-auth-token + diff --git a/requirements.txt b/requirements.txt index 7b0005d..1baef5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ sentry_sdk flask_minio py-healthcheck -Flask-InfluxDB~=0.3.3 +Flask-InfluxDB2~=0.3 jaeger-client Flask-Opentracing