From fa9b9cef3b4c3429cd301d4d6c15b68945eee8a9 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Fri, 11 Aug 2023 00:49:00 +0900 Subject: [PATCH] feat: install metrics system --- package.json | 1 + src/index.ts | 2 ++ src/metrics.ts | 15 +++++++++++++++ yarn.lock | 42 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/metrics.ts diff --git a/package.json b/package.json index 8417d1e..72aa5a3 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@aws-sdk/client-s3": "^3.75.0", "@fleekhq/fleek-storage-js": "^1.0.21", "@pinata/sdk": "^1.1.25", + "@snapshot-labs/snapshot-metrics": "^1.0.0", "@snapshot-labs/snapshot-sentry": "^1.0.0", "bluebird": "^3.7.2", "cors": "^2.8.5", diff --git a/src/index.ts b/src/index.ts index ceac1fc..6b753f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import upload from './upload'; import proxy from './proxy'; import { version } from '../package.json'; import { stats } from './stats'; +import initMetrics from './metrics'; const app = express(); const PORT = process.env.PORT || 3000; @@ -15,6 +16,7 @@ const commit = process.env.COMMIT_HASH || ''; const v = commit ? `${version}#${commit.substr(0, 7)}` : version; initLogger(app); +initMetrics(app); app.use(express.json({ limit: '4mb' })); app.use(express.urlencoded({ limit: '4mb', extended: false })); diff --git a/src/metrics.ts b/src/metrics.ts new file mode 100644 index 0000000..b4c5184 --- /dev/null +++ b/src/metrics.ts @@ -0,0 +1,15 @@ +import init, { client } from '@snapshot-labs/snapshot-metrics'; +import type { Express } from 'express'; + +export default function initMetrics(app: Express) { + init(app, { + normalizedPath: [ + ['^/ipfs/.*', '/ipfs/#url'], + ], + whitelistedPath: [ + /^\/$/, + /^\/upload$/, + /^\/ipfs\/.*$/, + ] + }); +} diff --git a/yarn.lock b/yarn.lock index a21a343..139dd10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1786,6 +1786,14 @@ resolved "https://registry.yarnpkg.com/@snapshot-labs/prettier-config/-/prettier-config-0.1.0-beta.7.tgz#c8e07e7e9baabee245020a72ac05835b65139823" integrity sha512-k/FUf4VWhwLFUmKuWs2mNvmPe691hqhvCJuujD4TfbIivWysmL1TqthwfdQUrQEAQUqVQ2ZKEiGkbufp5J27eQ== +"@snapshot-labs/snapshot-metrics@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot-metrics/-/snapshot-metrics-1.0.0.tgz#1f88a6aacc81f639f7059c153b53c550934cd3b3" + integrity sha512-6T8a2NX6Qo6zVAoNIWV8eSJCukCynI/HCLp37VZTzX8jwU/ahGsiDTQC3I/MDus+LDB+8pI5nju33NwM8Q7n2g== + dependencies: + express-prom-bundle "^6.6.0" + prom-client "^14.2.0" + "@snapshot-labs/snapshot-sentry@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot-sentry/-/snapshot-sentry-1.1.0.tgz#b357d4789ffd287f90fb70e7f0b207b47627cf24" @@ -2475,6 +2483,11 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== +bintrees@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.2.tgz#49f896d6e858a4a499df85c38fb399b9aff840f8" + integrity sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw== + bl@^4.0.3: version "4.1.0" resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" @@ -3540,6 +3553,14 @@ expect@^28.1.0: jest-message-util "^28.1.0" jest-util "^28.1.0" +express-prom-bundle@^6.6.0: + version "6.6.0" + resolved "https://registry.yarnpkg.com/express-prom-bundle/-/express-prom-bundle-6.6.0.tgz#9c33c1bd1478d70e3961a53aed2d17f15ef821ca" + integrity sha512-tZh2P2p5a8/yxQ5VbRav011Poa4R0mHqdFwn9Swe/obXDe5F0jY9wtRAfNYnqk4LXY7akyvR/nrvAHxQPWUjsQ== + dependencies: + on-finished "^2.3.0" + url-value-parser "^2.0.0" + express@^4.18.2: version "4.18.2" resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59" @@ -5903,7 +5924,7 @@ object.assign@^4.1.2: has-symbols "^1.0.1" object-keys "^1.1.1" -on-finished@2.4.1: +on-finished@2.4.1, on-finished@^2.3.0: version "2.4.1" resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f" integrity sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg== @@ -6172,6 +6193,13 @@ process-nextick-args@~2.0.0: resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== +prom-client@^14.2.0: + version "14.2.0" + resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.2.0.tgz#ca94504e64156f6506574c25fb1c34df7812cf11" + integrity sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA== + dependencies: + tdigest "^0.1.1" + prompts@^2.0.1: version "2.4.2" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069" @@ -6998,6 +7026,13 @@ tar-stream@^2.1.4: inherits "^2.0.3" readable-stream "^3.1.1" +tdigest@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/tdigest/-/tdigest-0.1.2.tgz#96c64bac4ff10746b910b0e23b515794e12faced" + integrity sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA== + dependencies: + bintrees "1.0.2" + terminal-link@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.1.1.tgz#14a64a27ab3c0df933ea546fba55f2d078edc994" @@ -7291,6 +7326,11 @@ url-parse-lax@^3.0.0: dependencies: prepend-http "^2.0.0" +url-value-parser@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/url-value-parser/-/url-value-parser-2.2.0.tgz#f38ae8cd24604ec69bc219d66929ddbbd93a2b32" + integrity sha512-yIQdxJpgkPamPPAPuGdS7Q548rLhny42tg8d4vyTNzFqvOnwqrgHXvgehT09U7fwrzxi3RxCiXjoNUNnNOlQ8A== + url@0.10.3: version "0.10.3" resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64"