pigeon-http 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2deb0f4d2617bd6cf6ddea9b246ae387ce73b22d78fc24f1e28214bd9b13d585
4
- data.tar.gz: a7414236e1b13b9010ac24acb770a75ba93c2461e8c6d31e020f4e005db85ea2
3
+ metadata.gz: c699662309d55e55ceb5a23df18c8a821e922c10193fd4e4d98f37a9cf88a1d0
4
+ data.tar.gz: 7a8195ec37eaf370d75cb1c63d391bb10c71eff1b7d9c3c42c917000e1f380fa
5
5
  SHA512:
6
- metadata.gz: 28daabe5a3cbe2bf2e438c015225d97593123777b6e489bec0929f2a895948d393ba98f1cc7791620bb050c6fd9378b9bd52a9c06456d09f10244b3ad822562d
7
- data.tar.gz: 94ad058fa894c1df58496c4afe4beb1147f7a0868cdcc10b8abba527552d29143c06c4bc1a654ab41a9b44c61495fda0e20c8e106601b4cd5a36c2e565f02a98
6
+ metadata.gz: d257bd2395d023965a72f02cf1b3fc81b5283342a40e3d92f55a1bb8a3e09451103ecea81dc21c7d6b6faa1968fa4ac4018e9f329cd85a66e941917757b425ba
7
+ data.tar.gz: ea740c69523bf8b4d7e6385e26d650f8a1fa830ce2894d0817fff1e2938dea108f658f1ee5372b26e267ec965c33d49209c83fd541ea55a2198ed8abc8f17c14
data/lib/pigeon/core.rb CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  require 'mime/types'
11
11
  require 'net/http'
12
12
  require 'openssl'
13
+ require 'retryable'
13
14
  require 'securerandom'
14
15
  require 'stringio'
15
16
  require 'uri'
@@ -32,7 +33,8 @@ module Pigeon
32
33
  time_window: 10,
33
34
  sleep_window: 10,
34
35
  retryable: true,
35
- retry_threshold: 3
36
+ retry_threshold: 3,
37
+ monitoring: false
36
38
  }
37
39
  DEFAULT_CALLBACKS = {
38
40
  CircuitBreakerOpen: nil,
@@ -50,85 +52,76 @@ module Pigeon
50
52
  @options = DEFAULT_OPTIONS
51
53
  @callbacks = DEFAULT_CALLBACKS
52
54
 
53
- @options['request_name'] = name
55
+ @options[:request_name] = name
54
56
 
55
57
  opts.each do |k, v|
56
58
  raise Error::Argument, "unknown option #{k}" unless VALID_OPTIONS.include?(k.to_s)
57
- @options[k] = v
59
+ @options[k.to_sym] = v
58
60
  end
59
61
 
60
62
  clbk.each do |k, v|
61
63
  raise Error::Argument, "unknown callback #{k}" unless VALID_CALLBACKS.include?(k.to_s)
62
- @callbacks[k] = v
64
+ @callbacks[k.to_sym] = v
63
65
  end
64
66
 
65
- if @options['retryable']
67
+ if @options[:retryable]
66
68
  Retryable.configure do |config|
67
69
  config.sleep = lambda { |n| 4**n }
68
70
  end
69
71
  end
70
-
71
- Datadog.configure do |c|
72
- c.env = ENV['DD_ENV']
73
- c.service = ENV['DD_SERVICE']
74
- c.tracing.partial_flush.enabled = true
75
- c.profiling.enabled = false
76
- c.runtime_metrics.enabled = false
77
- c.runtime_metrics.statsd = Datadog::Statsd.new
78
- c.tracing.sampler = Datadog::Tracing::Sampling::PrioritySampler.new(
79
- post_sampler: Datadog::Tracing::Sampling::RuleSampler.new(
80
- [Datadog::Tracing::Sampling::SimpleRule.new(service: ENV['DD_SERVICE'], sample_rate: 1.0)]
81
- )
82
- )
83
- end
84
72
  end
85
73
 
86
74
  def get url, args = {}
87
75
  start = Time.now
88
76
  response = http(:get, url, args)
89
- Pigeon::Statsd.new(@options['request_name'] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start))
77
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
90
78
 
91
79
  response
92
80
  rescue => e
93
- @callbacks['HttpError']&.call(e)
81
+ @callbacks[:HttpError]&.call(e)
94
82
  end
95
83
 
96
84
  def post url, args = {}
97
85
  start = Time.now
98
86
  response = http(:post, url, args)
99
- Pigeon::Statsd.new(@options['request_name'] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start))
87
+ puts @options
88
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
100
89
 
101
90
  response
102
91
  rescue => e
103
- @callbacks['HttpError']&.call(e)
92
+ @callbacks[:HttpError]&.call(e)
104
93
  end
105
94
 
106
95
  def put url, args = {}
107
- http(:put, url, args)
96
+ start = Time.now
97
+ response = http(:put, url, args)
98
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
99
+
100
+ response
108
101
  rescue => e
109
- @callbacks['HttpError']&.call(e)
102
+ @callbacks[:HttpError]&.call(e)
110
103
  end
111
104
 
112
105
  def delete url, args = {}
113
106
  http(:delete, url, args)
114
107
  rescue => e
115
- @callbacks['HttpError']&.call(e)
108
+ @callbacks[:HttpError]&.call(e)
116
109
  end
117
110
 
118
111
  def http method, url, args = {}
119
112
  args.merge({
120
- read_timeout: @options['request_timeout'],
121
- open_timeout: @options['request_open_timeout'],
122
- ssl_verify: @options['ssl_verify']
113
+ read_timeout: @options[:request_timeout],
114
+ open_timeout: @options[:request_open_timeout],
115
+ ssl_verify: @options[:ssl_verify]
123
116
  })
124
117
  response = Pigeon::Http::Request.new(method, url, args).execute
125
- Pigeon::Statsd.new(@options['request_name'] + '_througput', tags: [url]).capture
118
+ Pigeon::Statsd.new(@options[:request_name] + '_througput', tags: [url]).capture
126
119
 
127
120
  response
128
121
  end
129
122
 
130
123
  def circuit
131
- Circuitbox.circuit(@options['request_name'], exceptions: [HTTP::ConnectionError, HTTP::HeaderError, HTTP::RequestError, HTTP::ResponseError, HTTP::TimeoutError])
124
+ Circuitbox.circuit(@options[:request_name], exceptions: [HTTP::ConnectionError, HTTP::HeaderError, HTTP::RequestError, HTTP::ResponseError, HTTP::TimeoutError])
132
125
  end
133
126
  end
134
127
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pigeon
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigeon-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fitra Aditya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-05 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: circuitbox