Class: CloudwatchQuery::Parsers::SidekiqParser

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudwatch_query/parsers/sidekiq_parser.rb

Constant Summary collapse

BUILT_IN_SUB_PARSERS =

Built-in sub-parsers mapped to symbols

{
  start: Sidekiq::StartSubParser,
  done: Sidekiq::DoneSubParser,
  fail: Sidekiq::FailSubParser
}.freeze
SIDEKIQ_PATTERN =

Matches Sidekiq log format: "2026-02-04T20:46:15.201Z pid=123 tid=abc class=Job jid=xyz"

/^\d{4}-\d{2}-\d{2}T[\d:.]+Z\s+pid=\d+\s+tid=\w+\s+class=/
BASE_REGEX =
/^(?<timestamp>\d{4}-\d{2}-\d{2}T[\d:.]+Z)\s+pid=(?<pid>\d+)\s+tid=(?<tid>\w+)\s+class=(?<job_class>[\w:]+)\s+jid=(?<jid>\w+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SidekiqParser

Initialize with specific sub-parsers or use all defaults

Examples:

Use all defaults

SidekiqParser.new

Use only specific built-in sub-parsers

SidekiqParser.new(:start, :done)

Mix built-in and custom sub-parsers

SidekiqParser.new(:start, :done, MyCustomSubParser)

All defaults plus custom

SidekiqParser.new(:all, MyCustomSubParser)


36
37
38
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 36

def initialize(*args)
  @sub_parsers = resolve_sub_parsers(args)
end

Instance Attribute Details

#sub_parsers ⇒ Object (readonly)

Returns the value of attribute sub_parsers.



20
21
22
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 20

def sub_parsers
  @sub_parsers
end

Class Method Details

.available_sub_parsers ⇒ Object

List available built-in sub-parser names



81
82
83
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 81

def available_sub_parsers
  BUILT_IN_SUB_PARSERS.keys
end

.matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 68

def matches?(message)
  new.matches?(message)
end

.parse(message) ⇒ Object



72
73
74
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 72

def parse(message)
  new.parse(message)
end

.parser_name ⇒ Object



76
77
78
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 76

def parser_name
  "sidekiq"
end

Instance Method Details

#matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 40

def matches?(message)
  message.match?(SIDEKIQ_PATTERN)
end

#parse(message) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cloudwatch_query/parsers/sidekiq_parser.rb', line 44

def parse(message)
  return nil unless matches?(message)

  base_data = extract_base_data(message)
  return nil if base_data.empty?

  # Try each sub-parser until one matches
  sub_parser_data = {}
  @sub_parsers.each do |parser|
    if parser.matches?(message)
      sub_parser_data = parser.parse(message, base_data)
      break if sub_parser_data[:line_type]
    end
  end

  # If no sub-parser matched, mark as unknown
  sub_parser_data[:line_type] ||= :unknown
  sub_parser_data[:raw_message] = message if sub_parser_data[:line_type] == :unknown

  Sidekiq::SidekiqLog.new(base_data.merge(sub_parser_data))
end