Skip to content

feat(metrics): track vehicle reporting frequency - #70

Merged
aaronbrethorst merged 5 commits into
OneBusAway:mainfrom
0xaboomar:feature/vehicle-report-frequency
Jul 9, 2025
Merged

aaronbrethorst merged 5 commits into
OneBusAway:mainfrom
0xaboomar:feature/vehicle-report-frequency

Conversation

@0xaboomar

Copy link
Copy Markdown
Member
  • Added vehicle_report_total counter to track total number of GTFS-RT messages received per vehicle
  • Added vehicle_position_report_interval_seconds gauge to track time since each vehicle last reported
  • Added FetchGTFSRTFeed utility in gtfs_bundles.go to retrieve GTFS-RT feeds
  • Registered new metrics in metrics.go and integrated into the existing metrics collection funciton
  • Implemented TrackVehicleReportingFrequency function.

@coveralls

coveralls commented Jun 29, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 58.844% (-4.3%) from 63.104%
when pulling 6a0d415 on Abo-Omar-74:feature/vehicle-report-frequency
into 4d9a08a on OneBusAway:main.

@0xaboomar

Copy link
Copy Markdown
Member Author

Currently working on adding tests for the newly introduced function.
This PR is dependent on the previous one and will be rebased once that is merged.

@aaronbrethorst
aaronbrethorst requested a review from Copilot July 2, 2025 05:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_total and vehicle_position_report_interval_seconds metrics and expose unmatched stops
  • Add GTFS bundle utilities (FetchGTFSRTFeed, ParseGTFSFromCache, GetStopLocationsByIDs) and tests for them
  • Integrate TrackVehicleReportingFrequency into 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 FetchGTFSRTFeed utility 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 VehicleReportInterval could be renamed to VehiclePositionReportInterval to clearly match the metric name and purpose.
	VehicleReportInterval = promauto.NewGaugeVec(prometheus.GaugeOpts{

internal/metrics/oba_rest_api_metrics.go:169

  • The call to fmt.Sprintf will fail to compile because fmt is not imported. Add import "fmt" to your imports.
					fmt.Sprintf("%.6f", *stop.Latitude),

internal/metrics/gtfs-realtime-bindings.go:156

  • You're calling io.ReadAll but io is not imported. Add import "io" to the top of this file.
	data, err := io.ReadAll(resp.Body)

internal/metrics/gtfs-realtime-bindings.go:143

  • The global vehicleLastSeen map 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)

Comment thread internal/metrics/oba_rest_api_metrics.go
@aaronbrethorst

Copy link
Copy Markdown
Member

@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.

@0xaboomar

Copy link
Copy Markdown
Member Author

@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.

@0xaboomar
0xaboomar force-pushed the feature/vehicle-report-frequency branch from 7821531 to 926435d Compare July 5, 2025 15:48
@aaronbrethorst

Copy link
Copy Markdown
Member

@Abo-Omar-74 this is ready to rebase!

@0xaboomar
0xaboomar force-pushed the feature/vehicle-report-frequency branch from 926435d to 6a0d415 Compare July 9, 2025 23:58
@aaronbrethorst
aaronbrethorst merged commit 5c4d101 into OneBusAway:main Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants