pigeon-http 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2deb0f4d2617bd6cf6ddea9b246ae387ce73b22d78fc24f1e28214bd9b13d585
4
- data.tar.gz: a7414236e1b13b9010ac24acb770a75ba93c2461e8c6d31e020f4e005db85ea2
3
+ metadata.gz: 0d0a8d8356178871727e2d25a3b1a2a1a5fda626eecbe211ec490a5dd409d0d2
4
+ data.tar.gz: abf63f3e951ba0926eb9034c415c3d847a92d47dd49bfea3b8468e0ec2831865
5
5
  SHA512:
6
- metadata.gz: 28daabe5a3cbe2bf2e438c015225d97593123777b6e489bec0929f2a895948d393ba98f1cc7791620bb050c6fd9378b9bd52a9c06456d09f10244b3ad822562d
7
- data.tar.gz: 94ad058fa894c1df58496c4afe4beb1147f7a0868cdcc10b8abba527552d29143c06c4bc1a654ab41a9b44c61495fda0e20c8e106601b4cd5a36c2e565f02a98
6
+ metadata.gz: afc39ba93e631f18c1be2e9f6d701d684e330a13aa53c877f990eb8707f2190869fb968751c3e8cf601abb4a234f738eee3d2c1febecc45acd448311d90ab472
7
+ data.tar.gz: f4478906d6e9c95e48e38276a2d5e679fa9851f9adcf9fc5f875279a95fc242bc0480f6cb2f60447f497e37baad1762665543904f30f1c5e0da0daa5f9389a70
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pigeon-http (0.1.0)
4
+ pigeon-http (0.1.2)
5
5
  circuitbox
6
6
  ddtrace
7
7
  dogstatsd-ruby
data/lib/pigeon/core.rb CHANGED
@@ -3,13 +3,12 @@
3
3
  begin
4
4
  require 'circuitbox'
5
5
  require 'datadog/statsd'
6
- require 'ddtrace'
7
- require 'ddtrace/auto_instrument'
8
6
  require 'http'
9
7
  require 'http-cookie'
10
8
  require 'mime/types'
11
9
  require 'net/http'
12
10
  require 'openssl'
11
+ require 'retryable'
13
12
  require 'securerandom'
14
13
  require 'stringio'
15
14
  require 'uri'
@@ -32,7 +31,8 @@ module Pigeon
32
31
  time_window: 10,
33
32
  sleep_window: 10,
34
33
  retryable: true,
35
- retry_threshold: 3
34
+ retry_threshold: 3,
35
+ monitoring: false
36
36
  }
37
37
  DEFAULT_CALLBACKS = {
38
38
  CircuitBreakerOpen: nil,
@@ -50,85 +50,76 @@ module Pigeon
50
50
  @options = DEFAULT_OPTIONS
51
51
  @callbacks = DEFAULT_CALLBACKS
52
52
 
53
- @options['request_name'] = name
53
+ @options[:request_name] = name
54
54
 
55
55
  opts.each do |k, v|
56
56
  raise Error::Argument, "unknown option #{k}" unless VALID_OPTIONS.include?(k.to_s)
57
- @options[k] = v
57
+ @options[k.to_sym] = v
58
58
  end
59
59
 
60
60
  clbk.each do |k, v|
61
61
  raise Error::Argument, "unknown callback #{k}" unless VALID_CALLBACKS.include?(k.to_s)
62
- @callbacks[k] = v
62
+ @callbacks[k.to_sym] = v
63
63
  end
64
64
 
65
- if @options['retryable']
65
+ if @options[:retryable]
66
66
  Retryable.configure do |config|
67
67
  config.sleep = lambda { |n| 4**n }
68
68
  end
69
69
  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
70
  end
85
71
 
86
72
  def get url, args = {}
87
73
  start = Time.now
88
74
  response = http(:get, url, args)
89
- Pigeon::Statsd.new(@options['request_name'] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start))
75
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
90
76
 
91
77
  response
92
78
  rescue => e
93
- @callbacks['HttpError']&.call(e)
79
+ @callbacks[:HttpError]&.call(e)
94
80
  end
95
81
 
96
82
  def post url, args = {}
97
83
  start = Time.now
98
84
  response = http(:post, url, args)
99
- Pigeon::Statsd.new(@options['request_name'] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start))
85
+ puts @options
86
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
100
87
 
101
88
  response
102
89
  rescue => e
103
- @callbacks['HttpError']&.call(e)
90
+ @callbacks[:HttpError]&.call(e)
104
91
  end
105
92
 
106
93
  def put url, args = {}
107
- http(:put, url, args)
94
+ start = Time.now
95
+ response = http(:put, url, args)
96
+ Pigeon::Statsd.new(@options[:request_name] + '_latency', tags: [url]).capture(action: :histogram, count: (Time.now - start)) unless @options[:monitoring]
97
+
98
+ response
108
99
  rescue => e
109
- @callbacks['HttpError']&.call(e)
100
+ @callbacks[:HttpError]&.call(e)
110
101
  end
111
102
 
112
103
  def delete url, args = {}
113
104
  http(:delete, url, args)
114
105
  rescue => e
115
- @callbacks['HttpError']&.call(e)
106
+ @callbacks[:HttpError]&.call(e)
116
107
  end
117
108
 
118
109
  def http method, url, args = {}
119
110
  args.merge({
120
- read_timeout: @options['request_timeout'],
121
- open_timeout: @options['request_open_timeout'],
122
- ssl_verify: @options['ssl_verify']
111
+ read_timeout: @options[:request_timeout],
112
+ open_timeout: @options[:request_open_timeout],
113
+ ssl_verify: @options[:ssl_verify]
123
114
  })
124
115
  response = Pigeon::Http::Request.new(method, url, args).execute
125
- Pigeon::Statsd.new(@options['request_name'] + '_througput', tags: [url]).capture
116
+ Pigeon::Statsd.new(@options[:request_name] + '_througput', tags: [url]).capture
126
117
 
127
118
  response
128
119
  end
129
120
 
130
121
  def circuit
131
- Circuitbox.circuit(@options['request_name'], exceptions: [HTTP::ConnectionError, HTTP::HeaderError, HTTP::RequestError, HTTP::ResponseError, HTTP::TimeoutError])
122
+ Circuitbox.circuit(@options[:request_name], exceptions: [HTTP::ConnectionError, HTTP::HeaderError, HTTP::RequestError, HTTP::ResponseError, HTTP::TimeoutError])
132
123
  end
133
124
  end
134
125
 
@@ -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.2'
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.2
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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: circuitbox