This repository was archived by the owner on Jan 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
[WIP] Implement Prometheus metrics collection for monitoring #87
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/implement-prometheus-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25eabfa
Initial plan
Copilot 5e93932
Implement Prometheus metrics collection with prom-client
Copilot f33db39
Add comprehensive metrics documentation and verification script
Copilot 61b2260
Add comprehensive implementation documentation
Copilot 455e6b6
Fix code review issues: remove unused variable and add jq fallback
Copilot 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
| /** | ||
| * Error Handler Middleware | ||
| * | ||
| * Centralized error handling with metrics tracking. | ||
| */ | ||
|
|
||
| import { errorsTotal } from '../../monitoring/metrics.js'; | ||
|
|
||
| /** | ||
| * Error handling middleware | ||
| */ | ||
| export function errorHandler(err, req, res, next) { | ||
| // Increment error counter | ||
| errorsTotal.inc({ | ||
| type: err.name || 'UnknownError', | ||
| path: req.path | ||
| }); | ||
|
|
||
| console.error('Error:', err); | ||
|
|
||
| res.status(500).json({ | ||
| error: 'Internal server error', | ||
| message: err.message | ||
|
clduab11 marked this conversation as resolved.
|
||
| }); | ||
| } | ||
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,29 @@ | ||
| /** | ||
| * Metrics Middleware | ||
| * | ||
| * Tracks HTTP request duration and counts for all routes. | ||
| */ | ||
|
|
||
| import { httpRequestDuration, httpRequestTotal } from '../../monitoring/metrics.js'; | ||
|
|
||
| /** | ||
| * Middleware to collect HTTP request metrics | ||
| */ | ||
| export function metricsMiddleware(req, res, next) { | ||
| const start = Date.now(); | ||
|
|
||
| res.on('finish', () => { | ||
| const duration = (Date.now() - start) / 1000; // Convert to seconds | ||
| const route = req.route?.path || req.path; | ||
| const labels = { | ||
| method: req.method, | ||
|
clduab11 marked this conversation as resolved.
|
||
| route, | ||
| status_code: res.statusCode | ||
| }; | ||
|
|
||
| httpRequestDuration.observe(labels, duration); | ||
| httpRequestTotal.inc(labels); | ||
| }); | ||
|
|
||
| next(); | ||
| } | ||
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,67 @@ | ||
| /** | ||
| * Prometheus Metrics Configuration | ||
| * | ||
| * Defines and exports all metrics for the Gemini Flow backend. | ||
| * Metrics are collected and exposed for Prometheus scraping. | ||
| */ | ||
|
|
||
| import client from 'prom-client'; | ||
|
|
||
| // Enable default metrics (CPU, memory, event loop lag) | ||
| client.collectDefaultMetrics({ | ||
| prefix: 'gemini_flow_', | ||
| gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5] | ||
| }); | ||
|
|
||
| // HTTP Request Duration Histogram | ||
| export const httpRequestDuration = new client.Histogram({ | ||
| name: 'gemini_flow_http_request_duration_seconds', | ||
| help: 'Duration of HTTP requests in seconds', | ||
| labelNames: ['method', 'route', 'status_code'], | ||
| buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2, 5] | ||
| }); | ||
|
|
||
| // HTTP Request Counter | ||
| export const httpRequestTotal = new client.Counter({ | ||
| name: 'gemini_flow_http_requests_total', | ||
| help: 'Total number of HTTP requests', | ||
| labelNames: ['method', 'route', 'status_code'] | ||
| }); | ||
|
|
||
| // Error Counter | ||
| export const errorsTotal = new client.Counter({ | ||
| name: 'gemini_flow_errors_total', | ||
| help: 'Total number of errors', | ||
| labelNames: ['type', 'path'] | ||
| }); | ||
|
|
||
| // Gemini API Request Duration (specific to our use case) | ||
| export const geminiApiDuration = new client.Histogram({ | ||
| name: 'gemini_flow_gemini_api_duration_seconds', | ||
| help: 'Duration of Gemini API requests in seconds', | ||
| labelNames: ['status'], | ||
| buckets: [0.1, 0.5, 1, 2, 5, 10, 30] | ||
| }); | ||
|
|
||
| // Gemini API Request Counter | ||
| export const geminiApiTotal = new client.Counter({ | ||
| name: 'gemini_flow_gemini_api_requests_total', | ||
| help: 'Total number of Gemini API requests', | ||
| labelNames: ['status'] | ||
| }); | ||
|
|
||
| // Flow Execution Metrics | ||
| export const flowNodesProcessed = new client.Histogram({ | ||
| name: 'gemini_flow_nodes_processed', | ||
| help: 'Distribution of node counts in executed flows', | ||
| buckets: [0, 5, 10, 25, 50, 100, 250, 500] | ||
| }); | ||
|
|
||
| export const flowEdgesProcessed = new client.Histogram({ | ||
| name: 'gemini_flow_edges_processed', | ||
| help: 'Distribution of edge counts in executed flows', | ||
| buckets: [0, 5, 10, 25, 50, 100, 250, 500] | ||
| }); | ||
|
|
||
| // Registry for all metrics | ||
| export const register = client.register; |
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
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.