Class: CloudwatchQuery::Parsers::Rails::CompletedSubParser

Inherits:
Object
  • Object
show all
Includes:
SubParser
Defined in:
lib/cloudwatch_query/parsers/rails/sub_parsers.rb

Overview

Parses: "Completed 200 OK in 123ms"

Constant Summary collapse

COMPLETED_REGEX =
/Completed\s+(?<status>\d+)\s+\w+\s+in\s+(?<duration>[\d.]+)(?<unit>ms|s)/

Class Method Summary collapse

Methods included from SubParser

included

Class Method Details

.matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/cloudwatch_query/parsers/rails/sub_parsers.rb', line 156

def self.matches?(message)
  message.include?("Completed ")
end

.parse(message, _base_data) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/cloudwatch_query/parsers/rails/sub_parsers.rb', line 160

def self.parse(message, _base_data)
  match = message.match(COMPLETED_REGEX)
  return {} unless match

  duration_ms = match[:unit] == "s" ? match[:duration].to_f * 1000 : match[:duration].to_f

  {
    line_type: :completed,
    status_code: match[:status].to_i,
    duration_ms: duration_ms
  }
end