From e13cf47ee2f0e9761d3239bcb823dabd408bfbf7 Mon Sep 17 00:00:00 2001 From: Alan Luong Date: Tue, 19 Mar 2024 17:41:42 -0400 Subject: [PATCH 1/2] add action for sending custom metrics --- send-custom-metrics/README.md | 30 +++++++++++++++++++++++++++++ send-custom-metrics/action.yaml | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 send-custom-metrics/README.md create mode 100644 send-custom-metrics/action.yaml diff --git a/send-custom-metrics/README.md b/send-custom-metrics/README.md new file mode 100644 index 0000000..aa7fc6f --- /dev/null +++ b/send-custom-metrics/README.md @@ -0,0 +1,30 @@ +## Description + +Sends custom metrics to a specified metrics endpoint. This action makes a POST request using a bearer token for authorization. + +## Inputs + +| parameter | description | required | default | +|---|---|---|--- +| METRICS_ENDPOINT_URL| The metrics endpoint URL where the data will be sent. | `true` | | +| BEARER_TOKEN | The authorization token for the endpoint. | `true` | | +| data | The metric data to send, formatted as required by the endpoint. | `true` | | + +### Example Usage + +Replace `METRICS_ENDPOINT_URL` and `BEARER_TOKEN` with your actual metrics endpoint URL and bearer token, which should be stored as secrets in your GitHub repository. + +``` +jobs: + send-metrics: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Send Custom Metrics + uses: your-username/send-custom-metrics-action@main + with: + METRICS_ENDPOINT_URL: ${{ secrets.METRICS_ENDPOINT_URL }} + BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }} + data: 'your_metric{label="value"} 123' +``` diff --git a/send-custom-metrics/action.yaml b/send-custom-metrics/action.yaml new file mode 100644 index 0000000..5becf81 --- /dev/null +++ b/send-custom-metrics/action.yaml @@ -0,0 +1,34 @@ +name: Send Custom Metrics +description: Sends custom metrics to an endpoint + +inputs: + METRICS_ENDPOINT_URL: + description: The metrics endpoint URL + required: true + BEARER_TOKEN: + description: The authorization token for the endpoint + required: true + data: + description: The metric data to send + required: true + +runs: + using: composite + steps: + - name: Validate Metrics Data + shell: bash + env: + METRICS_DATA: ${{ inputs.data }} + run: | + if ! [[ "$METRICS_DATA" =~ ^[a-zA-Z_:][a-zA-Z0-9_:]*\{?.*\}? [0-9]+ ]]; then + echo "The provided metric data does not match the expected Prometheus format." + exit 1 + fi + echo "Metric data is valid." + + - name: Send Metric + shell: bash + run: | + curl -H "Authorization: Bearer ${{ inputs.BEARER_TOKEN }}" \ + -X POST "${{ inputs.METRICS_ENDPOINT_URL }}" \ + -d '${{ inputs.data }}' From 82eff4b9bf970fade73b1a31601dd7c281658e66 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 19 Mar 2024 23:20:46 +0000 Subject: [PATCH 2/2] Update Github Action docs --- send-custom-metrics/README.md | 38 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/send-custom-metrics/README.md b/send-custom-metrics/README.md index aa7fc6f..9b19b07 100644 --- a/send-custom-metrics/README.md +++ b/send-custom-metrics/README.md @@ -1,30 +1,18 @@ ## Description -Sends custom metrics to a specified metrics endpoint. This action makes a POST request using a bearer token for authorization. +Sends custom metrics to an endpoint ## Inputs -| parameter | description | required | default | -|---|---|---|--- -| METRICS_ENDPOINT_URL| The metrics endpoint URL where the data will be sent. | `true` | | -| BEARER_TOKEN | The authorization token for the endpoint. | `true` | | -| data | The metric data to send, formatted as required by the endpoint. | `true` | | - -### Example Usage - -Replace `METRICS_ENDPOINT_URL` and `BEARER_TOKEN` with your actual metrics endpoint URL and bearer token, which should be stored as secrets in your GitHub repository. - -``` -jobs: - send-metrics: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Send Custom Metrics - uses: your-username/send-custom-metrics-action@main - with: - METRICS_ENDPOINT_URL: ${{ secrets.METRICS_ENDPOINT_URL }} - BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }} - data: 'your_metric{label="value"} 123' -``` +| parameter | description | required | default | +| --- | --- | --- | --- | +| METRICS_ENDPOINT_URL | The metrics endpoint URL | `true` | | +| BEARER_TOKEN | The authorization token for the endpoint | `true` | | +| data | The metric data to send | `true` | | + + +## Runs + +This action is a `composite` action. + +