Skip to content

Scheduled Metrics

Scheduled Metrics #850

Workflow file for this run

name: Scheduled Metrics
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
# Production metrics require secret SEGMENT_WRITE_KEY
# Test metrics require secret SEGMENT_TEST_WRITE_KEY
production-data:
description: "Upload metrics to production data {true,false}"
required: true
default: "false"
jobs:
metrics:
name: Collect and Send Metrics
runs-on: ubuntu-22.04
env:
SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
SEGMENT_TEST_WRITE_KEY: ${{ secrets.SEGMENT_TEST_WRITE_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.x Part 1
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Set up Python 3.x Part 2
run: |
python3 -m venv ve1
cd scripts
../ve1/bin/pip3 install -r requirements.txt
../ve1/bin/pip3 install .
cd ..
- name: Release Metrics
id: release_metrics
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
if [[ "${{github.event_name}}" == "workflow_dispatch" ]]; then
if [[ "${{github.event.inputs.production-data}}" == "true" ]]; then
echo "Workflow dispatch using production write key"
WRITE_KEY=${SEGMENT_WRITE_KEY}
ID_PREFIX="helm-metric-downloads"
else
echo "Workflow dispatch using test write key"
WRITE_KEY=${SEGMENT_TEST_WRITE_KEY}
ID_PREFIX="helm-test-metric-downloads"
fi
elif [[ "${{github.repository}}" == "openshift-helm-charts/development" ]]; then
echo "Scheduled dispatch using production write key"
WRITE_KEY=${SEGMENT_WRITE_KEY}
ID_PREFIX="helm-metric-downloads"
if [ "${SEGMENT_WRITE_KEY}" != "" ]; then
WRITE_KEY=${SEGMENT_WRITE_KEY}
else
echo "Error: Scheduled dispatch is missing write key"
exit 1
fi
else
echo "Scheduled dispatch not on valid repo, do not set write key"
WRITE_KEY=""
fi
if [ "${WRITE_KEY}" != "" ]; then
ve1/bin/metrics --write-key=${WRITE_KEY} --metric-type=nightly --prefix="${ID_PREFIX}"
else
echo "Do not collect metrics, required segment write key is not set"
fi
- name: Send message to helm_dev slack channel
id: notify_dev
if: ${{ always() && github.event_name == 'schedule' && github.repository == 'openshift-helm-charts/development' && steps.release_metrics.conclusion != 'success' }}
uses: archive/github-actions-slack@v2.8.0
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C02979BDUPL
slack-text: Failure! Nightly collection of metrics. See '${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}'
- name: Result from "Send Message to helm_dev slack channel"
if: ${{ always() && github.event_name == 'schedule' && github.repository == 'openshift-helm-charts/development' && steps.release_metrics.conclusion != 'success' }}
run: echo "The result was ${{ steps.notify_dev.outputs.slack-result }}"
- name: Send message to helm_notify slack channel
id: notify
if: ${{ always() && github.event_name == 'schedule' && github.repository == 'openshift-helm-charts/development' && steps.release_metrics.conclusion == 'success' }}
uses: archive/github-actions-slack@v2.8.0
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C04K1ARMH8A
slack-text: Success! Nightly collection of metrics. See '${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}'
- name: Result from "Send Message to helm_notify slack channel"
if: ${{ always() && github.event_name == 'schedule' && github.repository == 'openshift-helm-charts/development' && steps.release_metrics.conclusion == 'success' }}
run: echo "The result was ${{ steps.notify.outputs.slack-result }}"