From 2d2b2535679008b473e6b193a487f006b0416fa6 Mon Sep 17 00:00:00 2001 From: Konstantin Pogorelov Date: Sat, 18 Jun 2022 12:23:59 +0200 Subject: [PATCH] minor codestyle fixes, turn async/await in metricsApp into a conventional promise --- Makefile | 4 ++-- spec/index.spec.js | 22 +++++++++++----------- src/index.js | 5 +++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 16ce785..7bfe587 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ test: npm test lint: - node_modules/eslint/bin/eslint.js src - node_modules/.bin/dtslint types + npx eslint src + npm run dtslint-next coverage: node_modules/istanbul/lib/cli.js cover \ -i 'src/*' \ diff --git a/spec/index.spec.js b/spec/index.spec.js index b4cf671..3236696 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -206,7 +206,7 @@ describe('index', () => { bypass: (req)=> { // metrics added here to attempt skipping /metrics // this should fail though, because serving /metrics preceeds bypassing - return !!req.url.match(/test|bad.word|metrics/) + return !!req.url.match(/test|bad.word|metrics/); } }); app.use(instance); @@ -512,18 +512,18 @@ describe('index', () => { describe('usage of clusterMetrics()', () => { it('clusterMetrics returns 200 even without a cluster', (done) => { - const app = express(); + const app = express(); - cluster.workers = []; + cluster.workers = []; - app.use('/cluster_metrics', bundle.clusterMetrics()); - const agent = supertest(app); - agent - .get('/cluster_metrics') - .end((err, res) => { - expect(res.status).toBe(200); - done(); - }); + app.use('/cluster_metrics', bundle.clusterMetrics()); + const agent = supertest(app); + agent + .get('/cluster_metrics') + .end((err, res) => { + expect(res.status).toBe(200); + done(); + }); }); it('clusterMetrics returns 500 in case of an error', (done) => { diff --git a/src/index.js b/src/index.js index cc6969e..88e80bc 100644 --- a/src/index.js +++ b/src/index.js @@ -206,9 +206,10 @@ function main(opts) { }; if (opts.metricsApp) { - opts.metricsApp.get(opts.metricsPath || '/metrics', async (req, res, next) => { + opts.metricsApp.get(opts.metricsPath || '/metrics', (req, res) => { res.set('Content-Type', opts.promRegistry.contentType); - return res.end(await opts.promRegistry.metrics()); + opts.promRegistry.metrics() + .then(metrics => res.end(metrics)); }); }