@@ -767,114 +767,13 @@ Workers package - all worker modules auto-discovered
767767
768768## Metrics & Monitoring
769769
770- The SDK provides comprehensive Prometheus metrics collection with two deployment modes:
770+ This design document describes how worker events flow through the SDK. The
771+ current user-facing metrics setup, legacy and canonical metric catalogs,
772+ ` WORKER_CANONICAL_METRICS ` behavior, Prometheus examples, and migration guidance
773+ are maintained in [ ` ../../METRICS.md ` ] ( ../../METRICS.md ) .
771774
772- ### Configuration
773-
774- ** HTTP Mode (Recommended - Metrics served from memory):**
775- ``` python
776- from conductor.client.configuration.settings.metrics_settings import MetricsSettings
777-
778- metrics_settings = MetricsSettings(
779- directory = " /tmp/conductor-metrics" , # .db files for multiprocess coordination
780- update_interval = 0.1 , # Update every 100ms
781- http_port = 8000 # Expose metrics via HTTP
782- )
783-
784- with TaskHandler(
785- configuration = config,
786- metrics_settings = metrics_settings
787- ) as handler:
788- handler.start_processes()
789- ```
790-
791- ** File Mode (Metrics written to file):**
792- ``` python
793- metrics_settings = MetricsSettings(
794- directory = " /tmp/conductor-metrics" ,
795- file_name = " metrics.prom" ,
796- update_interval = 1.0 ,
797- http_port = None # No HTTP server - write to file instead
798- )
799- ```
800-
801- ### Modes
802-
803- | Mode | HTTP Server | File Writes | Use Case |
804- | ------| -------------| -------------| ----------|
805- | HTTP (` http_port ` set) | ✅ Built-in | ❌ Disabled | Prometheus scraping, production |
806- | File (` http_port=None ` ) | ❌ Disabled | ✅ Enabled | File-based monitoring, testing |
807-
808- ** HTTP Mode Benefits:**
809- - Metrics served directly from memory (no file I/O)
810- - Built-in HTTP server with ` /metrics ` and ` /health ` endpoints
811- - Automatic aggregation across worker processes (no PID labels)
812- - Ready for Prometheus scraping out-of-the-box
813-
814- ### Key Metrics
815-
816- ** Task Metrics:**
817- - ` task_poll_time_seconds{taskType,quantile} ` - Poll latency (includes batch polling)
818- - ` task_execute_time_seconds{taskType,quantile} ` - Actual execution time (async tasks: from submission to completion)
819- - ` task_execute_error_total{taskType,exception} ` - Execution errors by type
820- - ` task_poll_total{taskType} ` - Total poll count
821- - ` task_result_size_bytes{taskType,quantile} ` - Task output size
822-
823- ** API Metrics:**
824- - ` http_api_client_request{method,uri,status,quantile} ` - API request latency
825- - ` http_api_client_request_count{method,uri,status} ` - Request count by endpoint
826- - ` http_api_client_request_sum{method,uri,status} ` - Total request time
827-
828- ** Labels:**
829- - ` taskType ` : Task definition name
830- - ` method ` : HTTP method (GET, POST, PUT)
831- - ` uri ` : API endpoint path
832- - ` status ` : HTTP status code
833- - ` exception ` : Exception type (for errors)
834- - ` quantile ` : 0.5, 0.75, 0.9, 0.95, 0.99
835-
836- ** Important Notes:**
837- - ** No PID labels** : Metrics are automatically aggregated across processes
838- - ** Async execution time** : Includes actual execution time, not just coroutine submission time
839- - ** Multiprocess safe** : Uses SQLite .db files in ` directory ` for coordination
840-
841- ### Prometheus Integration
842-
843- ** Scrape Config:**
844- ``` yaml
845- scrape_configs :
846- - job_name : ' conductor-workers'
847- static_configs :
848- - targets : ['localhost:8000']
849- scrape_interval : 15s
850- ` ` `
851-
852- **Accessing Metrics:**
853- ` ` ` bash
854- # Metrics endpoint
855- curl http://localhost:8000/metrics
856-
857- # Health check
858- curl http://localhost:8000/health
859-
860- # Watch specific metric
861- watch -n 1 'curl -s http://localhost:8000/metrics | grep task_execute_time_seconds'
862- ```
863-
864- ** PromQL Examples:**
865- ``` promql
866- # Average execution time
867- rate(task_execute_time_seconds_sum[5m]) / rate(task_execute_time_seconds_count[5m])
868-
869- # Success rate
870- sum(rate(task_execute_time_seconds_count{status="SUCCESS"}[5m])) / sum(rate(task_execute_time_seconds_count[5m]))
871-
872- # p95 latency
873- task_execute_time_seconds{quantile="0.95"}
874-
875- # Error rate
876- sum(rate(task_execute_error_total[5m])) by (taskType)
877- ```
775+ Keep metric names and PromQL examples out of this design document so the SDK has
776+ one source of truth for legacy and canonical metrics.
878777
879778---
880779
@@ -1264,8 +1163,8 @@ class CostTracker(TaskRunnerEventsListener):
12641163``` python
12651164handler = TaskHandler(
12661165 configuration = config,
1166+ metrics_settings = metrics_settings,
12671167 event_listeners = [
1268- PrometheusMetricsCollector(),
12691168 SLAMonitor(threshold_ms = 5000 ),
12701169 CostTracker(cost_per_second = {' ml_task' : 0.05 }),
12711170 CustomAuditLogger()
0 commit comments