Repository navigation
feat(metrics): track vehicle reporting frequency - #70
Conversation
|
Currently working on adding tests for the newly introduced function. |
There was a problem hiding this comment.
Pull Request Overview
Adds metrics and utilities to track GTFS-RT vehicle reporting frequency and unmatched stop locations, and integrates these into the existing metrics collection workflow.
- Introduce
vehicle_report_totalandvehicle_position_report_interval_secondsmetrics and expose unmatched stops - Add GTFS bundle utilities (
FetchGTFSRTFeed,ParseGTFSFromCache,GetStopLocationsByIDs) and tests for them - Integrate
TrackVehicleReportingFrequencyinto the application’s metrics collector
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/metrics/oba_rest_api_metrics.go | Extended FetchObaAPIMetrics to record unmatched stops |
| internal/metrics/metrics.go | Registered new vehicle reporting and unmatched stop metrics |
| internal/metrics/gtfs-realtime-bindings.go | Added TrackVehicleReportingFrequency for GTFS-RT feed parsing |
| internal/metrics/oba_rest_api_metrics_test.go | Updated tests to include the new serverID parameter |
| internal/gtfs/gtfs_bundles.go | Added GTFS cache parsing and feed fetching utilities |
| internal/gtfs/gtfs_bundles_test.go | Added tests for parsing and stop lookup functions |
| internal/app/metrics_collector.go | Wire up the new tracking functionality in the collector |
Comments suppressed due to low confidence (6)
internal/metrics/gtfs-realtime-bindings.go:149
- There are no tests covering
TrackVehicleReportingFrequency. Add unit tests to verify metric updates and map behavior under different feed scenarios.
func TrackVehicleReportingFrequency(server models.ObaServer) error {
internal/gtfs/gtfs_bundles.go:156
- The new
FetchGTFSRTFeedutility is not tested. Consider adding a test to simulate HTTP responses and ensure headers and error handling work correctly.
func FetchGTFSRTFeed(server models.ObaServer) (*http.Response, error) {
internal/metrics/metrics.go:64
- [nitpick] The variable
VehicleReportIntervalcould be renamed toVehiclePositionReportIntervalto clearly match the metric name and purpose.
VehicleReportInterval = promauto.NewGaugeVec(prometheus.GaugeOpts{
internal/metrics/oba_rest_api_metrics.go:169
- The call to
fmt.Sprintfwill fail to compile becausefmtis not imported. Addimport "fmt"to your imports.
fmt.Sprintf("%.6f", *stop.Latitude),
internal/metrics/gtfs-realtime-bindings.go:156
- You're calling
io.ReadAllbutiois not imported. Addimport "io"to the top of this file.
data, err := io.ReadAll(resp.Body)
internal/metrics/gtfs-realtime-bindings.go:143
- The global
vehicleLastSeenmap is accessed and modified without synchronization and could cause race conditions if called concurrently. Consider protecting it with a mutex or using a concurrent map.
var vehicleLastSeen = make(map[int]map[string]time.Time)
|
@Abo-Omar-74 don't worry about the decrease in code coverage. just get that copilot-recommended change made, rebase and we'll get this merged. |
@aaronbrethorst I have applied the Copilot suggestion, and it's ready to be merged. Since these changes are built on top of the previous PR, I will rebase this after the previous one gets merged. |
7821531 to
926435d
Compare
|
@Abo-Omar-74 this is ready to rebase! |
…port_total metrics
…n metrics collector function
926435d to
6a0d415
Compare
vehicle_report_totalcounter to track total number of GTFS-RT messages received per vehiclevehicle_position_report_interval_secondsgauge to track time since each vehicle last reportedFetchGTFSRTFeedutility ingtfs_bundles.goto retrieve GTFS-RT feedsmetrics.goand integrated into the existing metrics collection funcitonTrackVehicleReportingFrequencyfunction.