Skip to content

Commit

Permalink
Improved error log output for prometheus pushgateway requests (TryGho…
Browse files Browse the repository at this point in the history
…st#21556)

ref
https://linear.app/ghost/issue/ENG-1746/enable-ghost-to-push-metrics-to-a-pushgateway

- Trying to get Ghost working with the prometheus pushgateway in
staging, but it's logging an error each time it tries to push the
metrics. The error output is pretty useless for debugging, so this
commit improves the error messages to make it easier to debug.
  • Loading branch information
cmraible authored and tilak999 committed Nov 20, 2024
1 parent 485b9df commit 2874f55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions ghost/prometheus-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"typescript": "5.6.2"
},
"dependencies": {
"@tryghost/errors": "1.3.6",
"@tryghost/logging": "2.4.19",
"express": "4.21.1",
"prom-client": "15.1.3",
Expand Down
11 changes: 9 additions & 2 deletions ghost/prometheus-metrics/src/PrometheusClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Request, Response} from 'express';
import client from 'prom-client';
import logging from '@tryghost/logging';
import errors from '@tryghost/errors';

type PrometheusClientConfig = {
register?: client.Registry;
Expand Down Expand Up @@ -56,8 +57,14 @@ export class PrometheusClient {
try {
await this.gateway.pushAdd({jobName});
logging.debug('Metrics pushed to pushgateway - jobName: ', jobName);
} catch (error) {
logging.error('Error pushing metrics to pushgateway - jobName: ', jobName);
} catch (err) {
let error;
if (typeof err === 'object' && err !== null && 'code' in err) {
error = new errors.InternalServerError({message: 'Error pushing metrics to pushgateway: ' + err.code, code: err.code as string});
} else {
error = new errors.InternalServerError({message: 'Error pushing metrics to pushgateway: Unknown error'});
}
logging.error(error);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7430,7 +7430,7 @@
focus-trap "^6.7.2"
postcss-preset-env "^7.3.1"

"@tryghost/errors@1.3.1", "@tryghost/errors@1.3.5", "@tryghost/errors@^1.2.26", "@tryghost/errors@^1.2.3", "@tryghost/errors@^1.3.5", "@tryghost/errors@^1.3.6":
"@tryghost/errors@1.3.1", "@tryghost/errors@1.3.5", "@tryghost/errors@1.3.6", "@tryghost/errors@^1.2.26", "@tryghost/errors@^1.2.3", "@tryghost/errors@^1.3.5", "@tryghost/errors@^1.3.6":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-1.3.5.tgz#f4ef8e5c41a8a37456f2285271124180685827ae"
integrity sha512-iOkiHGnYFqSdFM9AVlgiL56Qcx6V9iQ3kbDKxyOAxrhMKq1OnOmOm7tr1CgGK1YDte9XYEZmR9hUZEg+ujn/jQ==
Expand Down

0 comments on commit 2874f55

Please sign in to comment.