From 8ef9995a3ec0270b84fc622ffad2aab966426b15 Mon Sep 17 00:00:00 2001 From: pvyazankin Date: Mon, 29 Sep 2025 15:09:51 +0200 Subject: [PATCH 1/3] MILAB-1133: stats github action --- .github/workflows/test.yaml | 25 ++++++ .gitignore | 53 ++----------- actions/notify/stats/send/action.yaml | 107 ++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 actions/notify/stats/send/action.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..398c625b --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,25 @@ +name: Test Stats Send Action + +on: + workflow_dispatch: # Allows you to manually trigger the workflow + +jobs: + send_stats_job: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Send test statistics + id: send_test_stats + uses: ./actions/notify/stats/send + with: + base-url: "https://mon.pl-open.science/" # Replace with your actual base URL + relative-path: "ci/github/test/" # A unique path for your test data + data-json: '{"test_value": 123, "event": "test_workflow_dispatch"}' + + - name: Check outputs + run: | + echo "Action 'ok' output: ${{ steps.send_test_stats.outputs.ok }}" + echo "Action 'response' output: ${{ steps.send_test_stats.outputs.response }}" + echo "Action 'time' output: ${{ steps.send_test_stats.outputs.time }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore index f1a8d440..b1026f4a 100644 --- a/.gitignore +++ b/.gitignore @@ -101,51 +101,8 @@ dist/ !/actions/**/dist/ node_modules/ -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. - .idea/artifacts - .idea/compiler.xml - .idea/jarRepositories.xml - .idea/modules.xml - .idea/*.iml - .idea/modules - *.iml - *.ipr - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# Editor-based Rest Client -.idea/httpRequests -/.idea/csv-plugin.xml +# IDEs +.idea/* +*.iml +*.ipr +*.iws \ No newline at end of file diff --git a/actions/notify/stats/send/action.yaml b/actions/notify/stats/send/action.yaml new file mode 100644 index 00000000..76b8214a --- /dev/null +++ b/actions/notify/stats/send/action.yaml @@ -0,0 +1,107 @@ +name: "Stats: Send to Statistics" +author: "pvyazankin" +description: | + Send data to statistics system. Core concepts are in + https://github.com/milaboratory/text/blob/main/features/monitoring/platforma-monitoring-prd.md + Example: `curl -X PUT "https://mon.pl-open.science/${USER}/test" -H "Content-Type: application/json" -d '{"psv": 1}'` + +inputs: + base-url: + default: "https://mon.pl-open.science/ci/github/" + description: "Base URL of the statistics system." + required: true + relative-path: + description: | + Relative path of the statistics system. The path where statistics will be stored. + You could find your data in (Metabase)[https://mon-web.pl-open.science/question#] + filtered by RequestPath:`/ci/github/$your-relative-path` + required: true + data-json: + description: "Data to send to the statistics system in JSON format." + required: true + # method: + # description: "The Slack API method to call." + # required: false + # payload: + # description: "Attributes that create the content of the request using JSON or YAML." + # required: false + # payload-delimiter: + # description: "Field seperator for nested attributes in the input payload." + # required: false + # payload-file-path: + # description: "Path to a file containing a valid input payload made of JSON or YAML." + # required: false + # payload-templated: + # default: "false" + # description: "If templated variables in input payloads should be replaced." + # required: false + # proxy: + # description: "An optional proxied route for HTTPS connections." + # required: false + retries: + default: "5" + description: "The strategy to use when performing retried requests." + # token: + # description: "The authentication value used with the Slack API." + # required: false + # webhook: + # description: "A location for posting request payloads." + # required: false + # webhook-type: + # description: "Option to use either an incoming webhook or webhook trigger." + # required: false +outputs: + ok: + description: "If the request completed without returning errors." + value: ${{ steps.send-to-stats.outputs.ok }} + response: + description: "A JSON stringified version of the response." + value: ${{ steps.send-to-stats.outputs.response }} + time: + description: "The Unix epoch time that the step completed." + value: ${{ steps.send-to-stats.outputs.time }} + # channel_id: + # description: "The channel ID returned with some of the Slack API methods." + # value: ${{ steps.send-to-slack.outputs.channel_id }} + # thread_ts: + # description: "The timestamp of a parent Slack message with threaded replies." + # value: ${{ steps.send-to-slack.outputs.thread_ts }} + # ts: + # description: "The timestamp of a Slack message or event in the response." + # value: ${{ steps.send-to-slack.outputs.ts }} + +runs: + using: 'composite' + + steps: + - name: Send to Statistics + id: send-to-stats + env: + RETRY_COUNT: ${{ inputs.retries }} + run: | + attempt=0 + while [ $attempt -lt $RETRY_COUNT ]; do + response_output=$(curl -X PUT "${{ inputs.base-url }}${{ inputs.relative-path }}" -H "Content-Type: application/json" -d '${{ inputs.data-json }}' -w '\n%{http_code}' -s) + http_code=$(echo "$response_output" | tail -n1) + response_body=$(echo "$response_output" | sed '$d') + + echo "Response: $response_body" + echo "HTTP Code: $http_code" + + if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then + echo "::set-output name=ok::true" + echo "::set-output name=response::$response_body" + echo "::set-output name=time::$(date +%s)" + exit 0 + else + echo "Attempt $((attempt + 1)) failed with HTTP code $http_code. Retrying in 5 seconds..." + sleep 5 + fi + attempt=$((attempt + 1)) + done + + echo "::set-output name=ok::false" + echo "::set-output name=response::" + echo "::set-output name=time::$(date +%s)" + exit 1 + shell: bash From 24d81cd95386d73766313e35824ba4092cb3824b Mon Sep 17 00:00:00 2001 From: pvyazankin Date: Mon, 29 Sep 2025 17:32:33 +0200 Subject: [PATCH 2/3] MILAB-1133: code cleanup --- .github/workflows/test.yaml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 398c625b..00000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Test Stats Send Action - -on: - workflow_dispatch: # Allows you to manually trigger the workflow - -jobs: - send_stats_job: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Send test statistics - id: send_test_stats - uses: ./actions/notify/stats/send - with: - base-url: "https://mon.pl-open.science/" # Replace with your actual base URL - relative-path: "ci/github/test/" # A unique path for your test data - data-json: '{"test_value": 123, "event": "test_workflow_dispatch"}' - - - name: Check outputs - run: | - echo "Action 'ok' output: ${{ steps.send_test_stats.outputs.ok }}" - echo "Action 'response' output: ${{ steps.send_test_stats.outputs.response }}" - echo "Action 'time' output: ${{ steps.send_test_stats.outputs.time }}" \ No newline at end of file From 5bd420323f3ae7c7b68f186ef38c9c8b2db624ee Mon Sep 17 00:00:00 2001 From: pvyazankin Date: Mon, 29 Sep 2025 17:32:33 +0200 Subject: [PATCH 3/3] MILAB-1133: stats github action --- .github/workflows/test.yaml | 25 ------------------ actions/notify/stats/send/action.yaml | 37 --------------------------- 2 files changed, 62 deletions(-) delete mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 398c625b..00000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Test Stats Send Action - -on: - workflow_dispatch: # Allows you to manually trigger the workflow - -jobs: - send_stats_job: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Send test statistics - id: send_test_stats - uses: ./actions/notify/stats/send - with: - base-url: "https://mon.pl-open.science/" # Replace with your actual base URL - relative-path: "ci/github/test/" # A unique path for your test data - data-json: '{"test_value": 123, "event": "test_workflow_dispatch"}' - - - name: Check outputs - run: | - echo "Action 'ok' output: ${{ steps.send_test_stats.outputs.ok }}" - echo "Action 'response' output: ${{ steps.send_test_stats.outputs.response }}" - echo "Action 'time' output: ${{ steps.send_test_stats.outputs.time }}" \ No newline at end of file diff --git a/actions/notify/stats/send/action.yaml b/actions/notify/stats/send/action.yaml index 76b8214a..c7818276 100644 --- a/actions/notify/stats/send/action.yaml +++ b/actions/notify/stats/send/action.yaml @@ -19,37 +19,9 @@ inputs: data-json: description: "Data to send to the statistics system in JSON format." required: true - # method: - # description: "The Slack API method to call." - # required: false - # payload: - # description: "Attributes that create the content of the request using JSON or YAML." - # required: false - # payload-delimiter: - # description: "Field seperator for nested attributes in the input payload." - # required: false - # payload-file-path: - # description: "Path to a file containing a valid input payload made of JSON or YAML." - # required: false - # payload-templated: - # default: "false" - # description: "If templated variables in input payloads should be replaced." - # required: false - # proxy: - # description: "An optional proxied route for HTTPS connections." - # required: false retries: default: "5" description: "The strategy to use when performing retried requests." - # token: - # description: "The authentication value used with the Slack API." - # required: false - # webhook: - # description: "A location for posting request payloads." - # required: false - # webhook-type: - # description: "Option to use either an incoming webhook or webhook trigger." - # required: false outputs: ok: description: "If the request completed without returning errors." @@ -60,15 +32,6 @@ outputs: time: description: "The Unix epoch time that the step completed." value: ${{ steps.send-to-stats.outputs.time }} - # channel_id: - # description: "The channel ID returned with some of the Slack API methods." - # value: ${{ steps.send-to-slack.outputs.channel_id }} - # thread_ts: - # description: "The timestamp of a parent Slack message with threaded replies." - # value: ${{ steps.send-to-slack.outputs.thread_ts }} - # ts: - # description: "The timestamp of a Slack message or event in the response." - # value: ${{ steps.send-to-slack.outputs.ts }} runs: using: 'composite'