-
Notifications
You must be signed in to change notification settings - Fork 6
chore: integrate Prometheus #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevcodez
merged 5 commits into
main
from
k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant
Mar 2, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import client from 'prom-client'; | ||
|
|
||
| // Avoid duplicate metric registration across test runs or multiple app instances | ||
| function getOrCreateCounter(config: { name: string; help: string; labelNames?: string[] }) { | ||
| const existing = client.register.getSingleMetric(config.name); | ||
| return (existing as client.Counter) ?? new client.Counter(config); | ||
| } | ||
|
|
||
| function getOrCreateHistogram(config: { name: string; help: string; labelNames?: string[]; buckets?: number[] }) { | ||
| const existing = client.register.getSingleMetric(config.name); | ||
| return (existing as client.Histogram) ?? new client.Histogram(config); | ||
| } | ||
|
|
||
| function getOrCreateGauge(config: { name: string; help: string; labelNames?: string[] }) { | ||
| const existing = client.register.getSingleMetric(config.name); | ||
| return (existing as client.Gauge) ?? new client.Gauge(config); | ||
| } | ||
|
|
||
| const webhooksProcessedCounter = getOrCreateCounter({ | ||
| name: 'orb_sync_webhooks_processed_total', | ||
| help: 'Total number of webhooks processed', | ||
| labelNames: ['event'], | ||
| }); | ||
|
|
||
| const webhookDelayMsHistogram = getOrCreateHistogram({ | ||
| name: 'orb_sync_webhook_delay_ms', | ||
| help: 'Delay between when an event is emitted and when it is processed by the API in milliseconds', | ||
| labelNames: ['event'], | ||
| }); | ||
|
|
||
| const internalServerErrorsCounter = getOrCreateCounter({ | ||
| name: 'orb_sync_internal_server_errors_total', | ||
| help: 'Total number of errors encountered', | ||
| }); | ||
|
|
||
| const pgPoolTotalGauge = getOrCreateGauge({ | ||
| name: 'orb_sync_pg_pool_total', | ||
| help: 'Total number of clients in the Postgres pool', | ||
| }); | ||
|
|
||
| const pgPoolIdleGauge = getOrCreateGauge({ | ||
| name: 'orb_sync_pg_pool_idle', | ||
| help: 'Number of idle clients in the Postgres pool', | ||
| }); | ||
|
|
||
| const pgPoolWaitingGauge = getOrCreateGauge({ | ||
| name: 'orb_sync_pg_pool_waiting', | ||
| help: 'Number of waiting requests for a client from the Postgres pool', | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| export default { | ||
| client, | ||
| metrics: { | ||
| webhooksProcessedCounter, | ||
| webhookDelayMsHistogram, | ||
| internalServerErrorsCounter, | ||
| pgPoolTotalGauge, | ||
| pgPoolIdleGauge, | ||
| pgPoolWaitingGauge, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use strict'; | ||
| import { FastifyInstance } from 'fastify'; | ||
| import { beforeAll, describe, test, expect, afterAll } from 'vitest'; | ||
| import { createApp } from '../app'; | ||
| import pino from 'pino'; | ||
|
|
||
| describe('/metrics', () => { | ||
| let app: FastifyInstance; | ||
|
|
||
| beforeAll(async () => { | ||
| const logger = pino({ level: 'silent' }); | ||
|
|
||
| app = await createApp( | ||
| { | ||
| loggerInstance: logger, | ||
| disableRequestLogging: true, | ||
| requestIdHeader: 'Request-Id', | ||
| }, | ||
| logger | ||
| ); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await app.close(); | ||
| }); | ||
|
|
||
| test('is alive', async () => { | ||
| const response = await app.inject({ | ||
| url: `/metrics`, | ||
| method: 'GET', | ||
| }); | ||
| const text = response.body; | ||
| expect(response.statusCode).toBe(200); | ||
| expect(text).toContain('orb_sync_webhooks_processed_total'); | ||
| expect(text).toContain('process_cpu_seconds_total'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.