Class: Tasker::Telemetry::Plugins::CsvExporter

Inherits:
BaseExporter
  • Object
show all
Defined in:
lib/tasker/telemetry/plugins/csv_exporter.rb

Overview

CSV format exporter for metrics data

Exports metrics in CSV format with configurable columns and headers. Flattens metric labels into separate columns for tabular representation.

Examples:

Basic Usage

exporter = Tasker::Telemetry::Plugins::CsvExporter.new
result = exporter.export(metrics_data, include_headers: true)

With Custom Columns

exporter = Tasker::Telemetry::Plugins::CsvExporter.new(
  columns: %w[timestamp name type value status]
)

Constant Summary collapse

VERSION =
'1.0.0'
DESCRIPTION =
'CSV format exporter with configurable columns and label flattening'
DEFAULT_COLUMNS =
%w[
  timestamp
  name
  type
  value
  labels
].freeze

Constants included from Concerns::StructuredLogging

Concerns::StructuredLogging::CORRELATION_ID_KEY

Instance Attribute Summary

Attributes inherited from BaseExporter

#description, #name, #version

Instance Method Summary collapse

Methods inherited from BaseExporter

#log_plugin_event, #log_plugin_exception, #log_plugin_performance, #metadata, #on_cache_sync, #on_export_complete, #on_export_request, #safe_export

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(options = {}) ⇒ CsvExporter

Returns a new instance of CsvExporter.

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options

Options Hash (options):

  • :columns (Array<String>)

    Column names to include

  • :separator (String)

    CSV field separator

  • :flatten_labels (Boolean)

    Flatten labels into separate columns



38
39
40
41
42
43
# File 'lib/tasker/telemetry/plugins/csv_exporter.rb', line 38

def initialize(options = {})
  super()
  @columns = options.fetch(:columns, DEFAULT_COLUMNS)
  @separator = options.fetch(:separator, ',')
  @flatten_labels = options.fetch(:flatten_labels, true)
end

Instance Method Details

#export(metrics_data, options = {}) ⇒ Hash

Export metrics data as CSV

Parameters:

  • metrics_data (Hash)

    Metrics data from MetricsBackend

  • options (Hash) (defaults to: {})

    Export options

Options Hash (options):

  • :include_headers (Boolean)

    Include CSV headers

  • :row_separator (String)

    Row separator character

Returns:

  • (Hash)

    Export result with CSV string



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tasker/telemetry/plugins/csv_exporter.rb', line 52

def export(metrics_data, options = {})
  include_headers = options.fetch(:include_headers, true)
  row_separator = options.fetch(:row_separator, "\n")

  metrics = metrics_data[:metrics] || {}
  timestamp = metrics_data[:timestamp]

  return empty_export if metrics.empty?

  # Build CSV data
  csv_data = build_csv_data(metrics, timestamp, include_headers, row_separator)

  {
    success: true,
    format: 'csv',
    data: csv_data,
    size_bytes: csv_data.bytesize,
    metrics_count: metrics.size,
    rows: metrics.size + (include_headers ? 1 : 0)
  }
end

#supported_formatsArray<String>

Get supported formats

Returns:

  • (Array<String>)

    List of supported formats



85
86
87
# File 'lib/tasker/telemetry/plugins/csv_exporter.rb', line 85

def supported_formats
  %w[csv]
end

#supports_format?(format) ⇒ Boolean

Check if format is supported

Parameters:

  • format (String, Symbol)

    Format to check

Returns:

  • (Boolean)

    True if CSV format is supported



78
79
80
# File 'lib/tasker/telemetry/plugins/csv_exporter.rb', line 78

def supports_format?(format)
  %w[csv].include?(format.to_s.downcase)
end