Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action for sending custom metrics #7

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions send-custom-metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Description

Sends custom metrics to an endpoint

## Inputs

| 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.


34 changes: 34 additions & 0 deletions send-custom-metrics/action.yaml
Original file line number Diff line number Diff line change
@@ -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:
perryjrandall marked this conversation as resolved.
Show resolved Hide resolved
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 }}'