Class: RailsPerformance::Models::GrapeRecord

Inherits:
BaseRecord
  • Object
show all
Defined in:
lib/rails_performance/models/grape_record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#duration, #value

Constructor Details

#initialize(request_id:, datetime: nil, datetimei: nil, format: nil, path: nil, status: nil, method: nil, endpoint_render_grape: nil, endpoint_run_grape: nil, format_response_grape: nil, json: "{}") ⇒ GrapeRecord

Returns a new instance of GrapeRecord.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails_performance/models/grape_record.rb', line 24

def initialize(request_id:, datetime: nil, datetimei: nil, format: nil, path: nil, status: nil, method: nil, endpoint_render_grape: nil, endpoint_run_grape: nil, format_response_grape: nil, json: "{}")
  @datetime = datetime
  @datetimei = datetimei.to_i unless datetimei.nil?
  @format = format
  @path = path
  @status = status
  @method = method
  @request_id = request_id

  @endpoint_render_grape = endpoint_render_grape
  @endpoint_run_grape = endpoint_run_grape
  @format_response_grape = format_response_grape

  @json = json
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def datetimei
  @datetimei
end

#endpoint_render_grapeObject

Returns the value of attribute endpoint_render_grape.



5
6
7
# File 'lib/rails_performance/models/grape_record.rb', line 5

def endpoint_render_grape
  @endpoint_render_grape
end

#endpoint_run_grapeObject

Returns the value of attribute endpoint_run_grape.



5
6
7
# File 'lib/rails_performance/models/grape_record.rb', line 5

def endpoint_run_grape
  @endpoint_run_grape
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def format
  @format
end

#format_response_grapeObject

Returns the value of attribute format_response_grape.



5
6
7
# File 'lib/rails_performance/models/grape_record.rb', line 5

def format_response_grape
  @format_response_grape
end

#jsonObject

Returns the value of attribute json.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def json
  @json
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def method
  @method
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def path
  @path
end

#request_idObject

Returns the value of attribute request_id.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def request_id
  @request_id
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/rails_performance/models/grape_record.rb', line 4

def status
  @status
end

Class Method Details

.from_db(key, value) ⇒ Object

key = grape|datetime|20210409T1115|datetimei|1617992134|format|json|path|/api/users|status|200|method|GET|request_id|1122|END|1.0.0 value = “endpoint_run.grape”=>0.002000907, “format_response.grape”=>0.0348967



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails_performance/models/grape_record.rb', line 9

def self.from_db(key, value)
  items = key.split("|")

  GrapeRecord.new(
    datetime: items[2],
    datetimei: items[4],
    format: items[6],
    path: items[8],
    status: items[10],
    method: items[12],
    request_id: items[14],
    json: value
  )
end

Instance Method Details

#record_hashObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_performance/models/grape_record.rb', line 40

def record_hash
  {
    format: self.format,
    status: status,
    method: method,
    path: path,
    datetime: Time.at(datetimei.to_i),
    datetimei: datetimei.to_i,
    request_id: request_id
  }.merge(value)
end

#saveObject



52
53
54
55
56
57
# File 'lib/rails_performance/models/grape_record.rb', line 52

def save
  key = "grape|datetime|#{datetime}|datetimei|#{datetimei}|format|#{format}|path|#{path}|status|#{status}|method|#{method}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}"
  value = {"endpoint_render.grape" => endpoint_render_grape, "endpoint_run.grape" => endpoint_run_grape, "format_response.grape" => format_response_grape}

  Utils.save_to_redis(key, value)
end