Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
fix(error-handling): add http error handling (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
happypoulp authored Nov 24, 2021
1 parent 075f5d4 commit 8dd6e16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/compute/coverage-for-folder.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

# This script computes the test coverage for a list of folders

echo
Expand Down
2 changes: 2 additions & 0 deletions src/monitor/push-metrics-all-folders.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

# This script push computed metrics to Prometheus.

# It expects coverage metrics to be exposed in a tar.gz file called
Expand Down
17 changes: 6 additions & 11 deletions src/monitor/push-metrics-for-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ const pushMetricsForFolder = ({ coverageArtifactsPath, folderName, jobName, push
.reduce((metricsAsText, metric) => metricsAsText + formatMetricPayload(metric), "")

// Sent metrics to Prometheus
try {
pushToGateway(`${pushGatewayUri}/metrics/job/${jobName}/folder_name/${folderName}`, metricsPayload, (err, data) => {
if (err) {
throw new Error(err.message)
}
pushToGateway(`${pushGatewayUri}/metrics/job/${jobName}/folder_name/${folderName}`, metricsPayload, (err, data) => {
if (err) {
throw new Error(err.message)
}

console.log("Done -", data.body)
})
}
catch(e) {
throw new Error(`ERROR: ${e.message}`)
}
console.log("Done -", data.body)
})
}

// If script is used from command-line as standalone
Expand Down
5 changes: 5 additions & 0 deletions src/monitor/push-to-pushgateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const pushToGateway = (pushGatewayUri, metricsPayload, callback) => {
res.setEncoding('utf8')
res.on('data', chunk => body += chunk)
res.on('end', () => {
if (res.statusCode > 204) {
callback(new Error(`Invalid response status code '${res.statusCode}' - response: ${body}`))
return
}

callback(null, {
res,
body,
Expand Down

0 comments on commit 8dd6e16

Please sign in to comment.