pigeon-http 0.1.0 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pigeon/core.rb +24 -33
- data/lib/pigeon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d0a8d8356178871727e2d25a3b1a2a1a5fda626eecbe211ec490a5dd409d0d2
|
4
|
+
data.tar.gz: abf63f3e951ba0926eb9034c415c3d847a92d47dd49bfea3b8468e0ec2831865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afc39ba93e631f18c1be2e9f6d701d684e330a13aa53c877f990eb8707f2190869fb968751c3e8cf601abb4a234f738eee3d2c1febecc45acd448311d90ab472
|
7
|
+
data.tar.gz: f4478906d6e9c95e48e38276a2d5e679fa9851f9adcf9fc5f875279a95fc242bc0480f6cb2f60447f497e37baad1762665543904f30f1c5e0da0daa5f9389a70
|
data/Gemfile.lock
CHANGED
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[
|
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[
|
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[
|
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[
|
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
|
-
|
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[
|
90
|
+
@callbacks[:HttpError]&.call(e)
|
104
91
|
end
|
105
92
|
|
106
93
|
def put url, args = {}
|
107
|
-
|
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[
|
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[
|
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[
|
121
|
-
open_timeout: @options[
|
122
|
-
ssl_verify: @options[
|
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[
|
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[
|
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
|
|
data/lib/pigeon/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: circuitbox
|