From dec9e4c87ca7829761ae6f63a4809783e53ae558 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 13 Dec 2021 11:28:04 +0000 Subject: [PATCH] chore: fix monitoring (#3972) Allow GET requests for prom stats and return correct response type --- .github/workflows/test.yml | 1 + packages/ipfs-http-server/src/api/routes/debug.js | 6 ++++-- packages/ipfs-http-server/src/index.js | 13 ++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05be9120ae..7c0c09832c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -312,6 +312,7 @@ jobs: name: Test example ${{ matrix.example.name }} needs: build runs-on: ubuntu-latest + continue-on-error: true strategy: matrix: example: diff --git a/packages/ipfs-http-server/src/api/routes/debug.js b/packages/ipfs-http-server/src/api/routes/debug.js index f73dd58035..f4d19de8d5 100644 --- a/packages/ipfs-http-server/src/api/routes/debug.js +++ b/packages/ipfs-http-server/src/api/routes/debug.js @@ -7,7 +7,7 @@ const gauge = new client.Gauge({ name: 'number_of_peers', help: 'the_number_of_c // Endpoint for handling debug metrics export default [{ - method: 'POST', + method: 'GET', path: '/debug/metrics/prometheus', /** * @param {import('../../types').Request} request @@ -23,7 +23,9 @@ export default [{ gauge.set(peers.length) - return h.response(client.register.metrics()) + const metrics = await client.register.metrics() + + return h.response(metrics) .type(client.register.contentType) } }] diff --git a/packages/ipfs-http-server/src/index.js b/packages/ipfs-http-server/src/index.js index b168d091e5..b77fbd0262 100644 --- a/packages/ipfs-http-server/src/index.js +++ b/packages/ipfs-http-server/src/index.js @@ -171,9 +171,16 @@ export class HttpApi { return h.continue } - if (request.method === 'get' && (request.path.startsWith('/ipfs') || request.path.startsWith('/webui'))) { - // allow requests to the webui - return h.continue + if (request.method === 'get') { + if (request.path.startsWith('/ipfs') || request.path.startsWith('/webui')) { + // allow requests to the gateway and webui + return h.continue + } + + if (process.env.IPFS_MONITORING && request.path.startsWith('/debug')) { + // allow requests to prometheus stats when monitoring is enabled + return h.continue + } } throw Boom.methodNotAllowed()