-
Notifications
You must be signed in to change notification settings - Fork 607
chore: add metrics and logs to debug db replica usage #3606
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
Flo4604
merged 3 commits into
main
from
07-16-chore_add_metrics_and_logs_to_debug_db_replica_usage
Jul 16, 2025
Merged
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| Package metrics provides Prometheus metric collectors for monitoring application performance. | ||
|
|
||
| This file contains database-related metrics for tracking database operation performance, | ||
| usage patterns, and latency across primary and read-only replicas. | ||
| */ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/promauto" | ||
| ) | ||
|
|
||
| var ( | ||
| // DatabaseOperationLatency tracks database operation latencies as a histogram, | ||
| // labeled by replica type (rw/ro), operation type, and success status. | ||
| // This collector uses predefined buckets optimized for typical database operation latencies. | ||
| // | ||
| // Example usage: | ||
| // timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) { | ||
| // metrics.DatabaseOperationLatency.WithLabelValues("rw", "exec", "success").Observe(v) | ||
| // })) | ||
| // defer timer.ObserveDuration() | ||
| DatabaseOperationLatency = promauto.NewHistogramVec( | ||
| prometheus.HistogramOpts{ | ||
| Subsystem: "database", | ||
| Name: "operation_latency_seconds", | ||
| Help: "Histogram of database operation latencies in seconds.", | ||
| Buckets: latencyBuckets, | ||
| ConstLabels: constLabels, | ||
Flo4604 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| []string{"replica", "operation", "status"}, | ||
| ) | ||
|
|
||
| // DatabaseOperationTotal tracks the total number of database operations, | ||
| // labeled by replica type (rw/ro), operation type, and success status. | ||
| // Use this counter to monitor database traffic patterns and error rates. | ||
| // | ||
| // Example usage: | ||
| // metrics.DatabaseOperationTotal.WithLabelValues("rw", "exec", "success").Inc() | ||
| // metrics.DatabaseOperationTotal.WithLabelValues("ro", "query", "error").Inc() | ||
| DatabaseOperationTotal = promauto.NewCounterVec( | ||
| prometheus.CounterOpts{ | ||
| Subsystem: "database", | ||
| Name: "operations_total", | ||
| Help: "Total number of database operations processed.", | ||
| ConstLabels: constLabels, | ||
| }, | ||
| []string{"replica", "operation", "status"}, | ||
| ) | ||
| ) | ||
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.