Skip to content

Commit

Permalink
Add setup node action
Browse files Browse the repository at this point in the history
  • Loading branch information
actualwitch committed Feb 27, 2024
1 parent d1535b3 commit f10cf11
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ on:
branches: ["*"]

jobs:
lint:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: isbang/[email protected]
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Build
run: npm run tsc
- name: Test prometheus push gateway
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost:9091' INPUT_GATEWAYTYPE=prometheus node dist/test.js
- name: Test zapier push gateway
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost' node dist/test.js
- name: Test gravel push gateway
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost:4278' INPUT_GATEWAYTYPE=gravel node dist/test.js
run: |
npm ci
npm run build:test
- name: Test prometheus
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost:9091' INPUT_GATEWAYTYPE=prometheus node test/index.js
- name: Test zapier
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost' node test/index.js
- name: Test gravel
run: GITHUB_WORKFLOW=workflow GITHUB_JOB=job INPUT_PUSHGATEWAY='http://localhost:4278' INPUT_GATEWAYTYPE=gravel node test/index.js
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ branding:
inputs:
pushgateway:
required: true
description: "Full URL to the aggregation gateway, optionally including the /metrics suffix"
description: "URL to the aggregation gateway, for example `http://localhost:9091`"
gatewaytype:
required: false
description: "Type of the aggregation gateway, one of 'prometheus', 'gravel', or 'zapier'. Uses 'zapier' by default"
description: "Type of the aggregation gateway, one of `prometheus`, `gravel`, or `zapier`. Currently only changes the url format in case of prometheus"
buckets:
required: false
description: "Comma separated list of buckets for duration histogram, with or without the brackets []"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "npx concurrently -- \"npm run build:main\" \"npm run build:post\"",
"build:main": "ncc build src/main.ts -o main",
"build:post": "ncc build src/post.ts -o post",
"tsc": "tsc"
"build:test": "ncc build src/test.ts -o test"
},
"repository": {
"type": "git",
Expand Down
37 changes: 16 additions & 21 deletions src/metrics/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,21 @@ export function init(buckets?: number[]) {
}

export async function pushToGateway(exporter: PeriodicExportingMetricReader) {
try {
const exporterResponse = await exporter.collect();
const serialized = new PrometheusSerializer().serialize(
exporterResponse.resourceMetrics
);
const url = getMetricsUrl();

const response = await fetch(url, {
method: "POST",
body: serialized,
});
if (response.status < 200 || response.status >= 300) {
const text = await response.text();
throw new Error(`Failed to push to gateway: ${response.status} ${text}`);
}
console.log("Metrics successfully pushed to gateway");
// we flush the metrics at the end of the submission to ensure the data is not repeated
await exporter.forceFlush();
} catch (error) {
console.error(error);
process.exit(1);
const exporterResponse = await exporter.collect();
const serialized = new PrometheusSerializer().serialize(
exporterResponse.resourceMetrics
);
const url = getMetricsUrl();

const response = await fetch(url, {
method: "POST",
body: serialized,
});
if (response.status < 200 || response.status >= 300) {
const text = await response.text();
throw new Error(`Failed to push to gateway: ${response.status} ${text}`);
}
console.log("Metrics successfully pushed to gateway");
// we flush the metrics at the end of the submission to ensure the data is not repeated
await exporter.forceFlush();
}

0 comments on commit f10cf11

Please sign in to comment.