Class: XRay::ServiceConnector

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/aws-xray-sdk/sampling/connector.rb

Overview

Connector class that translates Sampling poller functions to actual X-Ray back-end APIs and communicates with X-Ray daemon as the signing proxy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Constructor Details

#initializeServiceConnector

Returns a new instance of ServiceConnector.



13
14
15
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 13

def initialize
  update_xray_client
end

Instance Attribute Details

#xray_clientObject

Returns the value of attribute xray_client.



11
12
13
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 11

def xray_client
  @xray_client
end

Instance Method Details

#client_idObject



48
49
50
51
52
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 48

def client_id
  @client_id ||= begin
    SecureRandom.hex(12) 
  end
end

#daemon_config=(v) ⇒ Object



44
45
46
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 44

def daemon_config=(v)
  update_xray_client ip: v.tcp_ip, port: v.tcp_port
end

#fetch_sampling_rulesObject



17
18
19
20
21
22
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 17

def fetch_sampling_rules
  rules = []
  records = @xray_client.get_sampling_rules.sampling_rule_records
  records.each { |record| rules << SamplingRule.new(record.sampling_rule) if rule_valid?(record.sampling_rule) }
  rules
end

#fetch_sampling_targets(rules) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 24

def fetch_sampling_targets(rules)
  now = Time.now.to_i
  reports = generate_reports(rules, now)
  resp = @xray_client.get_sampling_targets({ sampling_statistics_documents: reports })
  {
    last_modified: resp.last_rule_modification,
    documents: resp.sampling_target_documents
  }
end

#update_xray_client(ip: '127.0.0.1', port: 2000) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/aws-xray-sdk/sampling/connector.rb', line 34

def update_xray_client(ip: '127.0.0.1', port: 2000)
  require 'aws-sdk-xray'
  @xray_client = Aws::XRay::Client.new(
    endpoint: %(http://#{ip}:#{port}),
    access_key_id: 'dummy', # AWS Ruby SDK doesn't support unsigned request
    secret_access_key: 'dummy',
    region: 'us-west-2' # not used
  )
end