From 49946a72b72884d4f84269b90e6a615d3928c9de Mon Sep 17 00:00:00 2001
From: Sergey Kaplun <skaplun@tarantool.org>
Date: Tue, 28 May 2024 13:56:14 +0300
Subject: [PATCH] ci: send perf statistics to InfluxDB

This patch adds an additional steps in the <perf_micro.yml> workflow to
aggregate and send aggregated data to InfluxDB via curl.

Also, this patch adds the corresponding environment variables to be used
during workflow to preserve the original commit hash and branch name.

NO_DOC=CI
NO_CHANGELOG=CI
NO_TEST=CI
---
 .github/workflows/perf_micro.yml | 25 +++++++++++++++++++++++++
 .test.mk                         |  4 ++++
 2 files changed, 29 insertions(+)

diff --git a/.github/workflows/perf_micro.yml b/.github/workflows/perf_micro.yml
index 4cca227854..af649a86ab 100644
--- a/.github/workflows/perf_micro.yml
+++ b/.github/workflows/perf_micro.yml
@@ -52,6 +52,10 @@ jobs:
 
     timeout-minutes: 60
 
+    env:
+        PERF_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
+        PERF_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
+
     steps:
       - name: Prepare checkout
         uses: tarantool/actions/prepare-checkout@master
@@ -72,6 +76,27 @@ jobs:
           revision: ${{ inputs.revision }}
       - name: test
         run: make -f .test.mk test-perf
+      - name: Aggregate benchmark results
+        run: make -f .test.mk test-perf-aggregate
+      - name: Send statistics to InfluxDB
+        # TODO: For now, use the debug bucket for this PoC.
+        # --silent -o /dev/null: Prevent dumping any reply part
+        # in the output in case of an error.
+        # --fail: Exit with the 22 error code is status >= 400.
+        # --write-out: See the reason for the failure, if any.
+        # --retry, --retry-delay: To avoid losing the results of
+        # running after such a long job, try to retry sending the
+        # results.
+        run: >
+          curl --request POST
+          "${{ secrets.INFLUXDB_URL }}/api/v2/write?org=tarantool&bucket=perf-debug&precision=s"
+          --write-out "%{http_code}"
+          --retry 5
+          --retry-delay 5
+          --connect-timeout 120
+          --fail --silent -o /dev/null
+          --header "Authorization: Token ${{ secrets.INFLUXDB_TOKEN_DEBUG }}"
+          --data-binary @./perf/output/summary.txt
       - name: Send VK Teams message on failure
         if: failure()
         uses: ./.github/actions/report-job-status
diff --git a/.test.mk b/.test.mk
index 60890a1415..601666fe9f 100644
--- a/.test.mk
+++ b/.test.mk
@@ -80,6 +80,10 @@ test-perf: CMAKE_PARAMS = -DCMAKE_BUILD_TYPE=RelWithDebInfo \
 
 test-perf: build run-perf-test
 
+.PHONY: test-perf-aggregate
+test-perf-aggregate:
+	cmake --build ${BUILD_DIR} --target test-perf-aggregate
+
 # *_ASAN variables are common part of respective variables for all ASAN builds.
 CMAKE_PARAMS_ASAN = -DENABLE_WERROR=ON \
                     -DENABLE_ASAN=ON \
-- 
GitLab