feat(server): add mongodb command monitoring metrics#5437
Open
mihir-dixit2k27 wants to merge 6 commits intolitmuschaos:masterfrom
Open
feat(server): add mongodb command monitoring metrics#5437mihir-dixit2k27 wants to merge 6 commits intolitmuschaos:masterfrom
mihir-dixit2k27 wants to merge 6 commits intolitmuschaos:masterfrom
Conversation
Implements event.CommandMonitor to track database latency, throughput, and concurrency. Exposes Prometheus metrics (duration, total, in-flight) via the /metrics endpoint. Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds MongoDB command-level observability to the GraphQL server by introducing a Prometheus-backed MongoDB event.CommandMonitor, enabling visibility into command latency, throughput, and concurrency with minimal impact to existing repository/business logic.
Changes:
- Added a new telemetry package that defines and registers Prometheus metrics and a MongoDB
CommandMonitor. - Wired the command monitor into the MongoDB client initialization (
SetMonitor(...)). - Exposed a Prometheus scrape endpoint at
GET /metricson the main Gin server.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
chaoscenter/graphql/server/server.go |
Registers telemetry metrics at startup and exposes /metrics via promhttp.Handler(). |
chaoscenter/graphql/server/pkg/telemetry/mongo_monitor.go |
Implements MongoDB command monitoring + Prometheus histogram/counter/gauge with command normalization. |
chaoscenter/graphql/server/pkg/database/mongodb/init.go |
Enables MongoDB driver command monitoring by setting a client monitor. |
chaoscenter/graphql/server/go.mod |
Adds Prometheus client dependency (and related indirects). |
chaoscenter/graphql/server/go.sum |
Adds checksums for newly introduced Prometheus dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
151
to
153
| router.GET("/", handlers.PlaygroundHandler()) | ||
| router.GET("/metrics", gin.WrapH(promhttp.Handler())) | ||
| router.Any("/query", authorization.Middleware(srv, mongodb.MgoClient)) |
| @@ -91,7 +92,7 @@ func MongoConnection() (*mongo.Client, error) { | |||
| Password: dbPassword, | |||
| } | |||
|
|
|||
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does
This PR introduces MongoDB observability to the GraphQL server by implementing a Prometheus-based
event.CommandMonitor. It enables real-time tracking of database latency, throughput, and concurrency without modifying repository or business logic.Key Changes
New Telemetry Package
pkg/telemetry/mongo_monitor.goto intercept MongoDBStarted,Succeeded, andFailedevents.New Metrics
litmus_mongo_command_duration_seconds(Histogram) — latency (5ms–10s buckets)litmus_mongo_command_total(Counter) — total commands by status (success,failed)litmus_mongo_in_flight_commands(Gauge) — concurrent operationsIntegration
pkg/database/mongodb/init.go/metricsTechnical Details
find,insert,update,delete,aggregate) are labeled explicitly; others are grouped as"other"to prevent metric explosion.sync.Oncefor safe metric registration. The gauge is decremented in bothSucceededandFailedhandlers to prevent stuck metrics.Verification
Verified locally using MongoDB 4.4 (Docker).
Steps
go run server.go curl http://localhost:8080/metrics | grep litmus_mongoAfter triggering database operations via the UI or GraphQL queries.
Example Output
Impact