Skip to content
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

feat: Add Prometheus metrics endpoint #10864

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dbumblis-parabol
Copy link
Contributor

@dbumblis-parabol dbumblis-parabol commented Feb 13, 2025

Description

Fixes/Partially Fixes (https://github.com/ParabolInc/action-devops/issues/262)

  • Adds prom-client package
  • Metrics handler
  • Adds metrics server if env var is set
  • Exports websocket metrics

Demo

https://www.loom.com/share/9aa4f099360d46479f4ab3129041c261

Testing scenarios

  • Scenario A (testing locally)
    • Set ENABLE_METRICS='true' & METRICS_PORT=9090 in env file
    • Observe the metrics server listen on specified port (or default port of 9090)
    • Visit localhost:9090/metrics and see exported values in prometheus format

Final checklist

  • I checked the code review guidelines
  • I have added Metrics Representative as reviewer(s) if my PR invovles metrics/data/analytics related changes
  • I have performed a self-review of my code, the same way I'd do it for any other team member
  • I have tested all cases I listed in the testing scenarios and I haven't found any issues or regressions
  • Whenever I took a non-obvious choice I added a comment explaining why I did it this way
  • I added the label Skip Maintainer Review Indicating the PR only requires reviewer review and can be merged right after it's approved if the PR introduces only minor changes, does not contain any architectural changes or does not introduce any new patterns and I think one review is sufficient'
  • PR title is human readable and could be used in changelog

@dbumblis-parabol dbumblis-parabol marked this pull request as ready for review February 13, 2025 02:20
@@ -53,6 +60,9 @@ process.on('SIGTERM', async (signal) => {
})

const PORT = Number(__PRODUCTION__ ? process.env.PORT : process.env.SOCKET_PORT)
const METRICS_PORT = Number(process.env.METRICS_PORT || 9090) // Default to 9090
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 Default to 9090 is obvious from the code, please remove the comment.
Useful would be why we've chosen 9090, for example 9090 is the standard prometheus port, if that's true

})
.any('/*', createSSR)
.listen(PORT, listenHandler)

// Metrics App (only start if ENABLE_METRICS is 'true')
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 (only start if ENABLE_METRICS is 'true') is obvious, please remove

Comment on lines +90 to +91
incrementWebSocketConnections()
trackWebSocketOpen(ws)
Copy link
Contributor

Choose a reason for hiding this comment

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

-1 Why have a setting ENABLE_METRICS if we're collecting metrics unconditionally? Instead we should conditionally bind the function here. I suggest something along the lines of

// at the top of the file
const metricsEnabled = process.env.ENABLE_METRICS === 'true'
// here
open: !metricsEnabled ? handleOpen : (ws) => {
  trackOpen(ws)
  handleOpen(ws)
}
// metrics.ts
export const trackOpen = ((ws: WebSocket) => {
    incrementWebSocketConnections()
    trackWebSocketOpen(ws)
}

This way we don't need to know how to track things here and we don't spend any effort if tracking is disabled.

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.

2 participants