-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add Prometheus metrics for GTFS processing monitoring #49
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
base: main
Are you sure you want to change the base?
Conversation
Implements comprehensive monitoring metrics for GTFS feed processing to enable observability of the real-time transit data pipeline. Changes: - Added django-prometheus integration with /metrics endpoint - Defined 7 custom GTFS metrics (counters, gauges, histograms) - Instrumented Celery tasks (schedule, vehicle positions, trip updates) - Added automatic metrics initialization via AppConfig.ready() - Implemented test suite for metrics validation Resolves: #16
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.
Pull request overview
This PR adds Prometheus metrics instrumentation to monitor GTFS (General Transit Feed Specification) data processing in real-time. The implementation enables observability for schedule updates, vehicle position tracking, trip updates, and error monitoring through a comprehensive set of counters, gauges, and histograms.
- Integration of django-prometheus library with middleware and metrics endpoint
- Definition of 7 GTFS-specific metrics (counters, gauges, histograms) for monitoring feed processing
- Instrumentation of three Celery tasks (schedule, vehicle positions, trip updates) with metrics recording and improved error handling
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Added django-prometheus>=2.3.1 dependency |
| uv.lock | Updated lock file with django-prometheus 2.4.1 and gtfs-realtime-bindings wheel |
| datahub/settings.py | Configured PrometheusBeforeMiddleware and PrometheusAfterMiddleware in MIDDLEWARE list and added django_prometheus to INSTALLED_APPS |
| datahub/urls.py | Exposed Prometheus metrics endpoint at root path via django_prometheus.urls |
| feed/apps.py | Added ready() method to auto-import metrics module on Django startup |
| feed/metrics.py | New file defining 7 Prometheus metrics for GTFS processing monitoring |
| feed/tasks.py | Instrumented get_schedule(), get_vehicle_positions(), and get_trip_updates() tasks with metrics recording, histogram timers, and enhanced error handling |
| feed/test_metrics.py | New unit test suite verifying metric definitions and basic increment/update functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove duplicate timestamp update in get_schedule - Improved error handling consistency - Code cleanup per review recommendations
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@BrandonTrigueros I've opened a new pull request, #50, to work on those changes. Once the pull request is ready, I'll request review from you. |
[WIP] Add Prometheus metrics for GTFS processing monitoring
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.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@BrandonTrigueros I've opened a new pull request, #51, to work on those changes. Once the pull request is ready, I'll request review from you. |
…nbounded cardinality, and security issues Co-authored-by: BrandonTrigueros <[email protected]>
Co-authored-by: BrandonTrigueros <[email protected]>
fix: Resolve syntax errors, unbounded cardinality, and security issues in GTFS metrics
Co-authored-by: Copilot <[email protected]>
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.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@BrandonTrigueros I've opened a new pull request, #52, to work on those changes. Once the pull request is ready, I'll request review from you. |
… labels Co-authored-by: BrandonTrigueros <[email protected]>
fix: Improve GTFS metrics reliability and test accuracy
Pull Request: GTFS Monitoring Metrics Implementation
Issue: #16 - Definición de métricas de monitoreo de GTFS
Resumen
Implementación de métricas de Prometheus para monitorear el procesamiento de feeds GTFS en tiempo real. Esta solución permite observabilidad completa del sistema de ingesta de datos de transporte público.
Cambios Realizados
1. Integración de django-prometheus
django-prometheus>=2.3.1apyproject.tomldatahub/settings.py/metricsexpuesto endatahub/urls.py2. Definición de Métricas GTFS
Creado módulo
feed/metrics.pycon 7 métricas específicas para GTFS:Counters (acumuladores)
gtfs_schedule_updates_total: Total de actualizaciones de horarios procesadasgtfs_vehicle_positions_updates_total: Total de actualizaciones de posiciones de vehículosgtfs_trip_updates_total: Total de actualizaciones de viajes procesadasgtfs_entities_processed_total: Total de entidades procesadas (por tipo y proveedor)gtfs_processing_errors_total: Total de errores encontrados durante el procesamientoGauge (valores actuales)
gtfs_last_update_timestamp: Timestamp de la última actualización exitosaHistogram (distribución temporal)
gtfs_processing_duration_seconds: Tiempo de procesamiento de cada feed3. Instrumentación de Tareas Celery
Modificado
feed/tasks.pypara registrar métricas en:get_schedule(): Procesamiento de horarios GTFS Scheduleget_vehicle_positions(): Procesamiento de posiciones de vehículos GTFS-RTget_trip_updates(): Procesamiento de actualizaciones de viajes GTFS-RT4. Inicialización Automática
Modificado
feed/apps.pypara cargar métricas al inicio de Django usandoAppConfig.ready()5. Suite de Tests
Creado
feed/test_metrics.pycon tests unitarios para validar:Testing
Ejemplo de Output de Métricas
Uso en Producción
Integración con Grafana
Estas métricas pueden ser scrapeadas por Prometheus y visualizadas en Grafana:
Queries Útiles
Archivos Modificados
pyproject.toml- Dependencia django-prometheusdatahub/settings.py- Middleware de Prometheusdatahub/urls.py- Endpoint /metricsfeed/apps.py- Carga automática de métricasfeed/metrics.py- NUEVO - Definiciones de métricasfeed/tasks.py- Instrumentación de tareasfeed/test_metrics.py- NUEVO - Suite de testsChecklist
Próximos Pasos (Opcional)