Skip to content

chore: integrate Prometheus#129

Merged
kevcodez merged 5 commits intomainfrom
k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant
Mar 2, 2026
Merged

chore: integrate Prometheus#129
kevcodez merged 5 commits intomainfrom
k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant

Conversation

@kevcodez
Copy link
Collaborator

@kevcodez kevcodez commented Feb 18, 2026

  • Integrate Prometheus and expose via /metrics endpoint
  • Add custom metrics to help identify operational issues
  • Added missing log in case of server errors
  • Increases webhook max size to 10 MB
  • Bumped deps to resolve security warning
  • Metrics for pg pool to potentially flag bottleneck

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9b76dc1 and 0585c57.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • apps/node-fastify/.env.sample
  • apps/node-fastify/package.json
  • apps/node-fastify/src/app.ts
  • apps/node-fastify/src/prometheus.ts
  • apps/node-fastify/src/routes/webhooks.ts
  • apps/node-fastify/src/test/metrics.test.ts
  • apps/node-fastify/src/test/orb/subscription.json
  • apps/node-fastify/src/utils/config.ts
  • package.json
  • packages/orb-sync-lib/package.json
  • packages/orb-sync-lib/src/orb-sync.ts
  • packages/orb-sync-lib/src/schemas/subscription_usage_exceeded.ts
  • packages/orb-sync-lib/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • apps/node-fastify/src/routes/webhooks.ts
  • apps/node-fastify/src/utils/config.ts
  • apps/node-fastify/src/app.ts
  • packages/orb-sync-lib/src/types.ts
  • apps/node-fastify/package.json
  • apps/node-fastify/src/test/metrics.test.ts
  • packages/orb-sync-lib/package.json

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Prometheus metrics for webhook processing, delays, DB pool stats and internal server errors; exposed at /metrics and toggleable via PROMETHEUS_METRICS_ENABLED (default: true)
  • Improvements

    • Webhook processing now records and exposes event-type and processing latency; increased maximum webhook payload size
    • Error handling improved to avoid leaking internal details
  • Tests

    • Added test coverage for the /metrics endpoint
  • Chores

    • Updated dependency versions across the repo

Walkthrough

This PR integrates Prometheus into the Fastify service and adds webhook and infrastructure metrics. A new prometheus module defines counters, a histogram, and gauges. orb-sync-lib's processWebhook now returns { eventType, timeSinceEventCreatedMs }. Webhook handling records processed counts and delay; the Fastify app conditionally registers /metrics controlled by PROMETHEUS_METRICS_ENABLED, wires prom-client via fastify-metrics, periodically updates Postgres pool gauges, and increments an internal-server-error counter for 5xx responses. Dependency version bumps and a test validating /metrics exposure were added.

Sequence Diagram(s)

sequenceDiagram
  participant Sender as Webhook Sender
  participant Fastify as Fastify App
  participant OrbSync as orb-sync-lib
  participant Prom as Prometheus (prom-client / /metrics)

  Sender->>Fastify: POST /webhooks (payload, headers)
  Fastify->>OrbSync: processWebhook(payload, headers)
  OrbSync-->>Fastify: { eventType, timeSinceEventCreatedMs }
  Fastify->>Prom: webhooksProcessedCounter.inc(label=eventType)
  Fastify->>Prom: webhookDelayMsHistogram.observe(label=eventType, value=timeSinceEventCreatedMs)
  alt 5xx error
    Fastify->>Prom: internalServerErrorsCounter.inc()
  end
  Prom->>Client: GET /metrics (scrape)
Loading
sequenceDiagram
  participant Scheduler as Background Task
  participant Fastify as Fastify App
  participant PGPool as Postgres Pool
  participant Prom as Prometheus (prom-client)

  Scheduler->>PGPool: collect pool stats (total, idle, waiting)
  PGPool-->>Fastify: stats
  Fastify->>Prom: pgPoolTotalGauge.set(total)
  Fastify->>Prom: pgPoolIdleGauge.set(idle)
  Fastify->>Prom: pgPoolWaitingGauge.set(waiting)
  Prom->>Client: GET /metrics (scrape)
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/node-fastify/src/prometheus.ts`:
- Line 6: The CI fails because explicit "as any" casts are used when
constructing prom-client metrics; replace those casts with the correct
prom-client types: change the type of the config parameter/variable to the
appropriate prom-client config interface (e.g., client.CounterConfiguration) and
remove "as any" so you call new client.Counter(config) with a properly typed
config; do the same for the other occurrence (line 11) using the corresponding
prom-client metric config type (use client.<MetricName>Configuration or import
the specific type) and update any variable signatures so TypeScript infers the
correct types instead of using "any".

kevcodez added 5 commits March 2, 2026 15:06
- Integrate Prometheus and expose via /metrics endpoint
- Add custom metrics to help identify operational issues
- Added missing log in case of server errors
- Increases webhook max size to 10 MB
- Bumped deps to resolve security warning
@kevcodez kevcodez force-pushed the k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant branch from 9b76dc1 to 0585c57 Compare March 2, 2026 07:06
@kevcodez kevcodez merged commit ef71794 into main Mar 2, 2026
2 checks passed
@kevcodez kevcodez deleted the k-dog/billing-2055-integrate-prometheus-client-and-expose-additional-relevant branch March 2, 2026 12:21
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

🎉 This PR is included in version 1.14.14 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants