-
Notifications
You must be signed in to change notification settings - Fork 20
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(observability): add prometheus metrics #37
base: main
Are you sure you want to change the base?
Conversation
It seems like you've provided a comprehensive summary of changes and a delightful poem! Is there anything else you'd like to add or modify? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (7)
- cmd/feeder/main.go (2 hunks)
- feeder/priceposter/client.go (2 hunks)
- feeder/priceprovider/priceprovider.go (1 hunks)
- feeder/priceprovider/sources/tick_source.go (4 hunks)
- feeder/priceprovider/sources/tick_source_test.go (3 hunks)
- metrics/README.md (1 hunks)
- metrics/metrics.go (1 hunks)
Files skipped from review due to trivial changes (1)
- metrics/README.md
Additional comments: 11
feeder/priceposter/client.go (2)
7-13:
The import of themetrics
package is correctly placed and follows the convention of grouping third-party imports together.122-122:
The addition of the metric increment operation is correctly implemented and follows the logic described in the summary.feeder/priceprovider/priceprovider.go (1)
- 39-51:
The changes to the
NewPriceProvider
function correctly pass the source type as an additional argument to theNewTickSource
function for each case. This aligns with the implementation of observability features described in the summary.feeder/priceprovider/sources/tick_source.go (4)
4-10: The import of the
metrics
package is correctly added to support the new Prometheus metrics functionality.4-22: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [19-28]
The
NewTickSource
function has been correctly updated to accept a newsource
parameter and initialize thesource
field in theTickSource
struct.
43-47: The
source
field has been correctly added to theTickSource
struct to store the source identifier for the metrics.60-67: The metric recording for
PriceSourceLatency
is correctly implemented within theTickSource
loop, capturing the duration of thefetchPrices
call and observing it with the appropriate label.feeder/priceprovider/sources/tick_source_test.go (3)
29-32: The test case for
NewTickSource
correctly passes the "test_source" string identifier as per the changes described in the summary. This ensures that the test cases are aligned with the updated function signature.64-66: The test case for
NewTickSource
within the "price update dropped due to shutdown" scenario has been updated to include the "test_source" string identifier. This maintains consistency with the changes made to theNewTickSource
function.83-85: The test case for
NewTickSource
within the "logs on price update errors" scenario has been updated to include the "test_source" string identifier. This maintains consistency with the changes made to theNewTickSource
function.metrics/metrics.go (1)
- 1-17:
The implementation of Prometheus metrics using the
promauto
package is correct, and the metrics are well-defined with appropriate names and help descriptions. The use of default buckets for the histogram is acceptable for initial implementation but may need to be revisited for fine-tuning based on actual latency distributions observed.
cmd/feeder/main.go
Outdated
http.Handle("/metrics", promhttp.Handler()) | ||
http.ListenAndServe(":3000", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to start the HTTP server for Prometheus metrics is not wrapped in a goroutine, which means that the ListenAndServe
call will block the main
function from proceeding. This could prevent the handleInterrupt
function from working as intended since it's supposed to listen for an interrupt signal to gracefully shut down the feeder.
To fix this, the HTTP server should be started in a separate goroutine to allow the main program to continue running and be able to handle interrupts.
- http.ListenAndServe(":3000", nil)
+ go func() {
+ if err := http.ListenAndServe(":3000", nil); err != nil {
+ logger.Error().Err(err).Msg("Metrics HTTP server failed")
+ }
+ }()
Commitable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
http.Handle("/metrics", promhttp.Handler()) | |
http.ListenAndServe(":3000", nil) | |
http.Handle("/metrics", promhttp.Handler()) | |
go func() { | |
if err := http.ListenAndServe(":3000", nil); err != nil { | |
logger.Error().Err(err).Msg("Metrics HTTP server failed") | |
} | |
}() |
Wrap the `http.ListenAndServe` in a goroutine to prevent conflicts with the interrupt handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- cmd/feeder/main.go (2 hunks)
Additional comments: 2
cmd/feeder/main.go (2)
5-10:
The import statements for the HTTP server functionality and Prometheus client are correctly added.61-61:
Clarify the purpose of theselect{}
statement blocking indefinitely, as it may not be obvious to maintainers why this is needed.
http.Handle("/metrics", promhttp.Handler()) | ||
go func() { | ||
if err := http.ListenAndServe(":3000", nil); err != nil { | ||
logger.Error().Err(err).Msg("Metrics HTTP server failed") | ||
} | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider logging a message when the HTTP server for metrics starts successfully to provide clear feedback on the server status.
This PR defines two metrics that are used to monitor the performance and behavior of the pricefeeder application.
pricefeeder_voting_periods_total
This is a counter metric that keeps track of the total number of voting periods the pricefeeder has participated in. A voting period is a specific duration during which votes are collected. This metric is incremented each time the pricefeeder participates in a voting period.
pricefeeder_price_source_latency_seconds
This is a histogram metric that measures the latency of querying a price source in seconds. The latency is the amount of time it takes for the pricefeeder to receive a response after it has sent a request to the price source. This metric is useful for monitoring the performance of the price sources and identifying any potential issues or delays.
The source label is used to differentiate the latencies of different price sources.
Summary by CodeRabbit
New Features
/metrics
endpoint for Prometheus scraping.Enhancements
SendPrices
function to increment a counter for tracking voting periods.NewTickSource
function.Documentation
Tests
NewTickSource
function calls.