Class: Flipper::Cloud::Telemetry::Submitter

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/cloud/telemetry/submitter.rb

Constant Summary collapse

PATH =
"/telemetry".freeze
SCHEMA_VERSION =
"V1".freeze
GZIP_ENCODING =
"gzip".freeze
Error =
Class.new(StandardError) do
  attr_reader :request_id, :response

  def initialize(request_id, response)
    @request_id = request_id
    @response = response
    super "Unexpected response code=#{response.code} request_id=#{request_id}"
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cloud_configuration, backoff_policy: nil) ⇒ Submitter

Returns a new instance of Submitter.



25
26
27
28
29
# File 'lib/flipper/cloud/telemetry/submitter.rb', line 25

def initialize(cloud_configuration, backoff_policy: nil)
  @cloud_configuration = cloud_configuration
  @backoff_policy = backoff_policy || BackoffPolicy.new
  @request_id = SecureRandom.uuid
end

Instance Attribute Details

#backoff_policyObject (readonly)

Returns the value of attribute backoff_policy.



23
24
25
# File 'lib/flipper/cloud/telemetry/submitter.rb', line 23

def backoff_policy
  @backoff_policy
end

#cloud_configurationObject (readonly)

Returns the value of attribute cloud_configuration.



23
24
25
# File 'lib/flipper/cloud/telemetry/submitter.rb', line 23

def cloud_configuration
  @cloud_configuration
end

#request_idObject (readonly)

Returns the value of attribute request_id.



23
24
25
# File 'lib/flipper/cloud/telemetry/submitter.rb', line 23

def request_id
  @request_id
end

Instance Method Details

#call(drained) ⇒ Object

Returns Array of [response, error]. response and error could be nil but usually one or the other will be present.



33
34
35
36
37
38
# File 'lib/flipper/cloud/telemetry/submitter.rb', line 33

def call(drained)
  return if drained.empty?
  body = to_body(drained)
  return if body.nil? || body.empty?
  retry_with_backoff(10) { submit(body) }
end