Class: Tasker::Telemetry::MetricsExportService
- Inherits:
-
Object
- Object
- Tasker::Telemetry::MetricsExportService
- Includes:
- Concerns::StructuredLogging
- Defined in:
- lib/tasker/telemetry/metrics_export_service.rb
Overview
Service for exporting metrics in various formats with delivery coordination
Phase 4.2.2.3.3: Service handles the business logic of metrics export, including format conversion, delivery, and storage. This is called by MetricsExportJob but can also be used independently.
Key Features:
- Multiple export formats (Prometheus, JSON, CSV)
- Prometheus remote write integration
- Configurable storage backends
- Comprehensive error handling and logging
Constant Summary
Constants included from Concerns::StructuredLogging
Concerns::StructuredLogging::CORRELATION_ID_KEY
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#export_metrics(format:, metrics_data:, context: {}) ⇒ Hash
Export metrics in specified format.
-
#initialize(config = {}) ⇒ MetricsExportService
constructor
Initialize metrics export service.
Methods included from Concerns::StructuredLogging
#correlation_id, #correlation_id=, #log_exception, #log_orchestration_event, #log_performance_event, #log_step_event, #log_structured, #log_task_event, #with_correlation_id
Constructor Details
#initialize(config = {}) ⇒ MetricsExportService
Initialize metrics export service
34 35 36 |
# File 'lib/tasker/telemetry/metrics_export_service.rb', line 34 def initialize(config = {}) @config = default_config.merge(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
29 30 31 |
# File 'lib/tasker/telemetry/metrics_export_service.rb', line 29 def config @config end |
Instance Method Details
#export_metrics(format:, metrics_data:, context: {}) ⇒ Hash
Export metrics in specified format
Main entry point for exporting metrics. Handles format routing, data conversion, delivery, and comprehensive error handling.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tasker/telemetry/metrics_export_service.rb', line 47 def export_metrics(format:, metrics_data:, context: {}) @export_context = context start_time = Time.current log_export_started(format, metrics_data, context) case format.to_sym when :prometheus result = export_prometheus_metrics(metrics_data) when :json result = export_json_metrics(metrics_data) when :csv result = export_csv_metrics(metrics_data) else return unsupported_format_result(format) end duration = Time.current - start_time log_export_completed(format, result, duration) result.merge( format: format, duration: duration, exported_at: Time.current.iso8601, context: context ) rescue StandardError => e log_export_error(format, e, context) { success: false, format: format, error: e., error_type: e.class.name, context: context } end |