Class: Percy::Stats

Inherits:
Datadog::Statsd
  • Object
show all
Defined in:
lib/percy/stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil, opts = {}, max_buffer_size = 50) ⇒ Stats



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/percy/stats.rb', line 6

def initialize(host = nil, port = nil, opts = {}, max_buffer_size = 50)
  host ||= ENV.fetch('DATADOG_AGENT_HOST', ::Datadog::Statsd::DEFAULT_HOST)
  port ||= Integer(ENV.fetch('DATADOG_AGENT_PORT', ::Datadog::Statsd::DEFAULT_PORT))
  opts[:tags] ||= []
  opts[:tags] << "env:#{ENV['PERCY_ENV'] || 'development'}"
  retry_delay = opts[:retry_delay] || 1
  retry_count = opts[:retry_count] || 3
  retries = 0

  begin
    super(host, port, opts, max_buffer_size)
  rescue SocketError
    host = 'localhost' if retries >= retry_count
    sleep retry_delay
    retries += 1
    retry
  end
end

Instance Method Details

#start_timingObject

Equivalent to stats.time, but without wrapping in blocks and dealing with var scoping issues.

Examples:

Report the time taken to activate an account.

stats.start_timing
.activate!
stats.stop_timing('account.activate')


31
32
33
34
# File 'lib/percy/stats.rb', line 31

def start_timing
  @_timing_start = Time.now
  true
end

#stop_timing(stat, options = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/percy/stats.rb', line 36

def stop_timing(stat, options = {})
  raise 'no timing started' unless @_timing_start # Programmer mistake, so raise an error.
  time_since(stat, @_timing_start, options)
  @_timing_start = nil
  true
end