0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2024-12-30 22:34:01 -05:00

Improved error log output for prometheus pushgateway requests (#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.
This commit is contained in:
Chris Raible 2024-11-06 15:03:10 -08:00 committed by GitHub
parent a26f63dc11
commit 7efbc60e1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View file

@ -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",

View file

@ -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;
@ -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);
}
}
}

View file

@ -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==