brainzlab 0.1.2 → 0.1.3
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/LICENSE +6 -21
- data/README.md +16 -2
- data/lib/brainzlab/beacon/client.rb +38 -40
- data/lib/brainzlab/beacon/provisioner.rb +1 -1
- data/lib/brainzlab/beacon.rb +15 -15
- data/lib/brainzlab/configuration.rb +92 -90
- data/lib/brainzlab/context.rb +2 -3
- data/lib/brainzlab/cortex/client.rb +29 -31
- data/lib/brainzlab/cortex/provisioner.rb +1 -1
- data/lib/brainzlab/cortex.rb +7 -11
- data/lib/brainzlab/dendrite/client.rb +42 -44
- data/lib/brainzlab/dendrite/provisioner.rb +1 -1
- data/lib/brainzlab/dendrite.rb +4 -4
- data/lib/brainzlab/devtools/data/collector.rb +22 -22
- data/lib/brainzlab/devtools/middleware/asset_server.rb +14 -14
- data/lib/brainzlab/devtools/middleware/database_handler.rb +52 -55
- data/lib/brainzlab/devtools/middleware/debug_panel.rb +19 -19
- data/lib/brainzlab/devtools/middleware/error_page.rb +45 -44
- data/lib/brainzlab/devtools/renderers/debug_panel_renderer.rb +39 -35
- data/lib/brainzlab/devtools/renderers/error_page_renderer.rb +13 -9
- data/lib/brainzlab/devtools.rb +11 -11
- data/lib/brainzlab/flux/buffer.rb +3 -3
- data/lib/brainzlab/flux/client.rb +14 -16
- data/lib/brainzlab/flux/provisioner.rb +13 -13
- data/lib/brainzlab/flux.rb +8 -8
- data/lib/brainzlab/instrumentation/action_mailer.rb +14 -13
- data/lib/brainzlab/instrumentation/active_record.rb +13 -15
- data/lib/brainzlab/instrumentation/aws.rb +43 -39
- data/lib/brainzlab/instrumentation/dalli.rb +20 -20
- data/lib/brainzlab/instrumentation/delayed_job.rb +27 -29
- data/lib/brainzlab/instrumentation/elasticsearch.rb +23 -24
- data/lib/brainzlab/instrumentation/excon.rb +27 -27
- data/lib/brainzlab/instrumentation/faraday.rb +3 -4
- data/lib/brainzlab/instrumentation/good_job.rb +28 -28
- data/lib/brainzlab/instrumentation/grape.rb +24 -24
- data/lib/brainzlab/instrumentation/graphql.rb +24 -23
- data/lib/brainzlab/instrumentation/httparty.rb +13 -14
- data/lib/brainzlab/instrumentation/mongodb.rb +7 -7
- data/lib/brainzlab/instrumentation/net_http.rb +6 -6
- data/lib/brainzlab/instrumentation/redis.rb +14 -21
- data/lib/brainzlab/instrumentation/resque.rb +23 -24
- data/lib/brainzlab/instrumentation/sidekiq.rb +29 -28
- data/lib/brainzlab/instrumentation/solid_queue.rb +37 -41
- data/lib/brainzlab/instrumentation/stripe.rb +36 -37
- data/lib/brainzlab/instrumentation/typhoeus.rb +19 -17
- data/lib/brainzlab/instrumentation.rb +20 -20
- data/lib/brainzlab/nerve/client.rb +38 -40
- data/lib/brainzlab/nerve/provisioner.rb +1 -1
- data/lib/brainzlab/nerve.rb +6 -6
- data/lib/brainzlab/pulse/client.rb +15 -11
- data/lib/brainzlab/pulse/instrumentation.rb +61 -57
- data/lib/brainzlab/pulse/propagation.rb +28 -28
- data/lib/brainzlab/pulse/provisioner.rb +12 -12
- data/lib/brainzlab/pulse/tracer.rb +3 -3
- data/lib/brainzlab/pulse.rb +13 -13
- data/lib/brainzlab/rails/log_formatter.rb +127 -121
- data/lib/brainzlab/rails/log_subscriber.rb +70 -76
- data/lib/brainzlab/rails/railtie.rb +66 -89
- data/lib/brainzlab/recall/buffer.rb +1 -1
- data/lib/brainzlab/recall/client.rb +14 -10
- data/lib/brainzlab/recall/logger.rb +16 -18
- data/lib/brainzlab/recall/provisioner.rb +16 -16
- data/lib/brainzlab/recall.rb +11 -13
- data/lib/brainzlab/reflex/breadcrumbs.rb +2 -2
- data/lib/brainzlab/reflex/client.rb +14 -10
- data/lib/brainzlab/reflex/provisioner.rb +12 -12
- data/lib/brainzlab/reflex.rb +29 -29
- data/lib/brainzlab/sentinel/client.rb +40 -42
- data/lib/brainzlab/sentinel/provisioner.rb +1 -1
- data/lib/brainzlab/sentinel.rb +5 -5
- data/lib/brainzlab/signal/client.rb +12 -14
- data/lib/brainzlab/signal/provisioner.rb +12 -12
- data/lib/brainzlab/signal.rb +7 -7
- data/lib/brainzlab/synapse/client.rb +42 -44
- data/lib/brainzlab/synapse/provisioner.rb +1 -1
- data/lib/brainzlab/synapse.rb +6 -6
- data/lib/brainzlab/utilities/circuit_breaker.rb +37 -41
- data/lib/brainzlab/utilities/health_check.rb +53 -55
- data/lib/brainzlab/utilities/log_formatter.rb +38 -40
- data/lib/brainzlab/utilities/rate_limiter.rb +5 -5
- data/lib/brainzlab/utilities.rb +4 -4
- data/lib/brainzlab/vault/cache.rb +1 -1
- data/lib/brainzlab/vault/client.rb +39 -41
- data/lib/brainzlab/vault/provisioner.rb +1 -1
- data/lib/brainzlab/vault.rb +19 -25
- data/lib/brainzlab/version.rb +1 -1
- data/lib/brainzlab/vision/client.rb +20 -20
- data/lib/brainzlab/vision/provisioner.rb +21 -21
- data/lib/brainzlab/vision.rb +17 -19
- data/lib/brainzlab-sdk.rb +1 -1
- data/lib/brainzlab.rb +22 -24
- data/lib/generators/brainzlab/install/install_generator.rb +29 -27
- metadata +1 -1
|
@@ -58,138 +58,138 @@ module BrainzLab
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def install_net_http!
|
|
61
|
-
require_relative
|
|
61
|
+
require_relative 'instrumentation/net_http'
|
|
62
62
|
NetHttp.install!
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def install_faraday!
|
|
66
66
|
return unless defined?(::Faraday)
|
|
67
67
|
|
|
68
|
-
require_relative
|
|
68
|
+
require_relative 'instrumentation/faraday'
|
|
69
69
|
FaradayMiddleware.install!
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def install_httparty!
|
|
73
73
|
return unless defined?(::HTTParty)
|
|
74
74
|
|
|
75
|
-
require_relative
|
|
75
|
+
require_relative 'instrumentation/httparty'
|
|
76
76
|
HTTPartyInstrumentation.install!
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def install_active_record!
|
|
80
|
-
require_relative
|
|
80
|
+
require_relative 'instrumentation/active_record'
|
|
81
81
|
ActiveRecord.install!
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def install_redis!
|
|
85
85
|
return unless defined?(::Redis)
|
|
86
86
|
|
|
87
|
-
require_relative
|
|
87
|
+
require_relative 'instrumentation/redis'
|
|
88
88
|
RedisInstrumentation.install!
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def install_sidekiq!
|
|
92
92
|
return unless defined?(::Sidekiq)
|
|
93
93
|
|
|
94
|
-
require_relative
|
|
94
|
+
require_relative 'instrumentation/sidekiq'
|
|
95
95
|
SidekiqInstrumentation.install!
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def install_graphql!
|
|
99
99
|
return unless defined?(::GraphQL)
|
|
100
100
|
|
|
101
|
-
require_relative
|
|
101
|
+
require_relative 'instrumentation/graphql'
|
|
102
102
|
GraphQLInstrumentation.install!
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def install_mongodb!
|
|
106
106
|
return unless defined?(::Mongo) || defined?(::Mongoid)
|
|
107
107
|
|
|
108
|
-
require_relative
|
|
108
|
+
require_relative 'instrumentation/mongodb'
|
|
109
109
|
MongoDBInstrumentation.install!
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def install_elasticsearch!
|
|
113
113
|
return unless defined?(::Elasticsearch) || defined?(::OpenSearch)
|
|
114
114
|
|
|
115
|
-
require_relative
|
|
115
|
+
require_relative 'instrumentation/elasticsearch'
|
|
116
116
|
ElasticsearchInstrumentation.install!
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def install_action_mailer!
|
|
120
120
|
return unless defined?(::ActionMailer)
|
|
121
121
|
|
|
122
|
-
require_relative
|
|
122
|
+
require_relative 'instrumentation/action_mailer'
|
|
123
123
|
ActionMailerInstrumentation.install!
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
def install_delayed_job!
|
|
127
127
|
return unless defined?(::Delayed::Job) || defined?(::Delayed::Backend)
|
|
128
128
|
|
|
129
|
-
require_relative
|
|
129
|
+
require_relative 'instrumentation/delayed_job'
|
|
130
130
|
DelayedJobInstrumentation.install!
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def install_grape!
|
|
134
134
|
return unless defined?(::Grape::API)
|
|
135
135
|
|
|
136
|
-
require_relative
|
|
136
|
+
require_relative 'instrumentation/grape'
|
|
137
137
|
GrapeInstrumentation.install!
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def install_solid_queue!
|
|
141
141
|
return unless defined?(::SolidQueue)
|
|
142
142
|
|
|
143
|
-
require_relative
|
|
143
|
+
require_relative 'instrumentation/solid_queue'
|
|
144
144
|
SolidQueueInstrumentation.install!
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def install_good_job!
|
|
148
148
|
return unless defined?(::GoodJob)
|
|
149
149
|
|
|
150
|
-
require_relative
|
|
150
|
+
require_relative 'instrumentation/good_job'
|
|
151
151
|
GoodJobInstrumentation.install!
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
def install_resque!
|
|
155
155
|
return unless defined?(::Resque)
|
|
156
156
|
|
|
157
|
-
require_relative
|
|
157
|
+
require_relative 'instrumentation/resque'
|
|
158
158
|
ResqueInstrumentation.install!
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
def install_excon!
|
|
162
162
|
return unless defined?(::Excon)
|
|
163
163
|
|
|
164
|
-
require_relative
|
|
164
|
+
require_relative 'instrumentation/excon'
|
|
165
165
|
ExconInstrumentation.install!
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
def install_typhoeus!
|
|
169
169
|
return unless defined?(::Typhoeus)
|
|
170
170
|
|
|
171
|
-
require_relative
|
|
171
|
+
require_relative 'instrumentation/typhoeus'
|
|
172
172
|
TyphoeusInstrumentation.install!
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
def install_dalli!
|
|
176
176
|
return unless defined?(::Dalli::Client)
|
|
177
177
|
|
|
178
|
-
require_relative
|
|
178
|
+
require_relative 'instrumentation/dalli'
|
|
179
179
|
DalliInstrumentation.install!
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
def install_aws!
|
|
183
183
|
return unless defined?(::Aws)
|
|
184
184
|
|
|
185
|
-
require_relative
|
|
185
|
+
require_relative 'instrumentation/aws'
|
|
186
186
|
AWSInstrumentation.install!
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
def install_stripe!
|
|
190
190
|
return unless defined?(::Stripe)
|
|
191
191
|
|
|
192
|
-
require_relative
|
|
192
|
+
require_relative 'instrumentation/stripe'
|
|
193
193
|
StripeInstrumentation.install!
|
|
194
194
|
end
|
|
195
195
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'uri'
|
|
6
6
|
|
|
7
7
|
module BrainzLab
|
|
8
8
|
module Nerve
|
|
9
9
|
class Client
|
|
10
10
|
def initialize(config)
|
|
11
11
|
@config = config
|
|
12
|
-
@base_url = config.nerve_url ||
|
|
12
|
+
@base_url = config.nerve_url || 'https://nerve.brainzlab.ai'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# Report a job execution
|
|
16
16
|
def report_job(job_class:, job_id:, queue:, status:, started_at:, ended_at:, **attributes)
|
|
17
17
|
response = request(
|
|
18
18
|
:post,
|
|
19
|
-
|
|
19
|
+
'/api/v1/jobs',
|
|
20
20
|
body: {
|
|
21
21
|
job_class: job_class,
|
|
22
22
|
job_id: job_id,
|
|
@@ -31,7 +31,7 @@ module BrainzLab
|
|
|
31
31
|
|
|
32
32
|
response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
|
|
33
33
|
rescue StandardError => e
|
|
34
|
-
log_error(
|
|
34
|
+
log_error('report_job', e)
|
|
35
35
|
false
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -39,7 +39,7 @@ module BrainzLab
|
|
|
39
39
|
def report_failure(job_class:, job_id:, queue:, error_class:, error_message:, backtrace: nil, **attributes)
|
|
40
40
|
response = request(
|
|
41
41
|
:post,
|
|
42
|
-
|
|
42
|
+
'/api/v1/jobs/failures',
|
|
43
43
|
body: {
|
|
44
44
|
job_class: job_class,
|
|
45
45
|
job_id: job_id,
|
|
@@ -54,23 +54,23 @@ module BrainzLab
|
|
|
54
54
|
|
|
55
55
|
response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
|
|
56
56
|
rescue StandardError => e
|
|
57
|
-
log_error(
|
|
57
|
+
log_error('report_failure', e)
|
|
58
58
|
false
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# Get job statistics
|
|
62
|
-
def stats(queue: nil, job_class: nil, period:
|
|
62
|
+
def stats(queue: nil, job_class: nil, period: '1h')
|
|
63
63
|
params = { period: period }
|
|
64
64
|
params[:queue] = queue if queue
|
|
65
65
|
params[:job_class] = job_class if job_class
|
|
66
66
|
|
|
67
|
-
response = request(:get,
|
|
67
|
+
response = request(:get, '/api/v1/stats', params: params)
|
|
68
68
|
|
|
69
69
|
return nil unless response.is_a?(Net::HTTPSuccess)
|
|
70
70
|
|
|
71
71
|
JSON.parse(response.body, symbolize_names: true)
|
|
72
72
|
rescue StandardError => e
|
|
73
|
-
log_error(
|
|
73
|
+
log_error('stats', e)
|
|
74
74
|
nil
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -80,27 +80,27 @@ module BrainzLab
|
|
|
80
80
|
params[:queue] = queue if queue
|
|
81
81
|
params[:status] = status if status
|
|
82
82
|
|
|
83
|
-
response = request(:get,
|
|
83
|
+
response = request(:get, '/api/v1/jobs', params: params)
|
|
84
84
|
|
|
85
85
|
return [] unless response.is_a?(Net::HTTPSuccess)
|
|
86
86
|
|
|
87
87
|
data = JSON.parse(response.body, symbolize_names: true)
|
|
88
88
|
data[:jobs] || []
|
|
89
89
|
rescue StandardError => e
|
|
90
|
-
log_error(
|
|
90
|
+
log_error('list_jobs', e)
|
|
91
91
|
[]
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
# List queues
|
|
95
95
|
def list_queues
|
|
96
|
-
response = request(:get,
|
|
96
|
+
response = request(:get, '/api/v1/queues')
|
|
97
97
|
|
|
98
98
|
return [] unless response.is_a?(Net::HTTPSuccess)
|
|
99
99
|
|
|
100
100
|
data = JSON.parse(response.body, symbolize_names: true)
|
|
101
101
|
data[:queues] || []
|
|
102
102
|
rescue StandardError => e
|
|
103
|
-
log_error(
|
|
103
|
+
log_error('list_queues', e)
|
|
104
104
|
[]
|
|
105
105
|
end
|
|
106
106
|
|
|
@@ -112,7 +112,7 @@ module BrainzLab
|
|
|
112
112
|
|
|
113
113
|
JSON.parse(response.body, symbolize_names: true)
|
|
114
114
|
rescue StandardError => e
|
|
115
|
-
log_error(
|
|
115
|
+
log_error('get_queue', e)
|
|
116
116
|
nil
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -121,7 +121,7 @@ module BrainzLab
|
|
|
121
121
|
response = request(:post, "/api/v1/jobs/#{job_id}/retry")
|
|
122
122
|
response.is_a?(Net::HTTPSuccess)
|
|
123
123
|
rescue StandardError => e
|
|
124
|
-
log_error(
|
|
124
|
+
log_error('retry_job', e)
|
|
125
125
|
false
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -130,7 +130,7 @@ module BrainzLab
|
|
|
130
130
|
response = request(:delete, "/api/v1/jobs/#{job_id}")
|
|
131
131
|
response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPNoContent)
|
|
132
132
|
rescue StandardError => e
|
|
133
|
-
log_error(
|
|
133
|
+
log_error('delete_job', e)
|
|
134
134
|
false
|
|
135
135
|
end
|
|
136
136
|
|
|
@@ -138,7 +138,7 @@ module BrainzLab
|
|
|
138
138
|
def report_metrics(queue:, size:, latency_ms: nil, workers: nil)
|
|
139
139
|
response = request(
|
|
140
140
|
:post,
|
|
141
|
-
|
|
141
|
+
'/api/v1/metrics',
|
|
142
142
|
body: {
|
|
143
143
|
queue: queue,
|
|
144
144
|
size: size,
|
|
@@ -150,21 +150,21 @@ module BrainzLab
|
|
|
150
150
|
|
|
151
151
|
response.is_a?(Net::HTTPSuccess)
|
|
152
152
|
rescue StandardError => e
|
|
153
|
-
log_error(
|
|
153
|
+
log_error('report_metrics', e)
|
|
154
154
|
false
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
def provision(project_id:, app_name:)
|
|
158
158
|
response = request(
|
|
159
159
|
:post,
|
|
160
|
-
|
|
160
|
+
'/api/v1/projects/provision',
|
|
161
161
|
body: { project_id: project_id, app_name: app_name },
|
|
162
162
|
use_service_key: true
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
|
|
166
166
|
rescue StandardError => e
|
|
167
|
-
log_error(
|
|
167
|
+
log_error('provision', e)
|
|
168
168
|
false
|
|
169
169
|
end
|
|
170
170
|
|
|
@@ -173,34 +173,32 @@ module BrainzLab
|
|
|
173
173
|
def request(method, path, headers: {}, body: nil, params: nil, use_service_key: false)
|
|
174
174
|
uri = URI.parse("#{@base_url}#{path}")
|
|
175
175
|
|
|
176
|
-
if params
|
|
177
|
-
uri.query = URI.encode_www_form(params)
|
|
178
|
-
end
|
|
176
|
+
uri.query = URI.encode_www_form(params) if params
|
|
179
177
|
|
|
180
178
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
181
|
-
http.use_ssl = uri.scheme ==
|
|
179
|
+
http.use_ssl = uri.scheme == 'https'
|
|
182
180
|
http.open_timeout = 5
|
|
183
181
|
http.read_timeout = 10
|
|
184
182
|
|
|
185
183
|
request = case method
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
request[
|
|
197
|
-
request[
|
|
184
|
+
when :get
|
|
185
|
+
Net::HTTP::Get.new(uri)
|
|
186
|
+
when :post
|
|
187
|
+
Net::HTTP::Post.new(uri)
|
|
188
|
+
when :put
|
|
189
|
+
Net::HTTP::Put.new(uri)
|
|
190
|
+
when :delete
|
|
191
|
+
Net::HTTP::Delete.new(uri)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
request['Content-Type'] = 'application/json'
|
|
195
|
+
request['Accept'] = 'application/json'
|
|
198
196
|
|
|
199
197
|
if use_service_key
|
|
200
|
-
request[
|
|
198
|
+
request['X-Service-Key'] = @config.nerve_master_key || @config.secret_key
|
|
201
199
|
else
|
|
202
200
|
auth_key = @config.nerve_api_key || @config.secret_key
|
|
203
|
-
request[
|
|
201
|
+
request['Authorization'] = "Bearer #{auth_key}" if auth_key
|
|
204
202
|
end
|
|
205
203
|
|
|
206
204
|
headers.each { |k, v| request[k] = v }
|
data/lib/brainzlab/nerve.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
3
|
+
require_relative 'nerve/client'
|
|
4
|
+
require_relative 'nerve/provisioner'
|
|
5
5
|
|
|
6
6
|
module BrainzLab
|
|
7
7
|
module Nerve
|
|
@@ -32,7 +32,7 @@ module BrainzLab
|
|
|
32
32
|
job_class: job_class,
|
|
33
33
|
job_id: job_id,
|
|
34
34
|
queue: queue,
|
|
35
|
-
status:
|
|
35
|
+
status: 'completed',
|
|
36
36
|
started_at: started_at,
|
|
37
37
|
ended_at: ended_at,
|
|
38
38
|
**attributes
|
|
@@ -69,7 +69,7 @@ module BrainzLab
|
|
|
69
69
|
job_class: job_class,
|
|
70
70
|
job_id: job_id,
|
|
71
71
|
queue: queue,
|
|
72
|
-
status:
|
|
72
|
+
status: 'running',
|
|
73
73
|
started_at: Time.now,
|
|
74
74
|
ended_at: Time.now,
|
|
75
75
|
**attributes
|
|
@@ -80,7 +80,7 @@ module BrainzLab
|
|
|
80
80
|
# @param queue [String] Filter by queue (optional)
|
|
81
81
|
# @param job_class [String] Filter by job class (optional)
|
|
82
82
|
# @param period [String] Time period: "1h", "24h", "7d", "30d"
|
|
83
|
-
def stats(queue: nil, job_class: nil, period:
|
|
83
|
+
def stats(queue: nil, job_class: nil, period: '1h')
|
|
84
84
|
return nil unless enabled?
|
|
85
85
|
|
|
86
86
|
ensure_provisioned!
|
|
@@ -160,7 +160,7 @@ module BrainzLab
|
|
|
160
160
|
# # job work
|
|
161
161
|
# end
|
|
162
162
|
#
|
|
163
|
-
def track(job_class:, job_id:, queue:
|
|
163
|
+
def track(job_class:, job_id:, queue: 'default', **attributes)
|
|
164
164
|
started_at = Time.now
|
|
165
165
|
|
|
166
166
|
begin
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
6
|
|
|
7
7
|
module BrainzLab
|
|
8
8
|
module Pulse
|
|
@@ -23,7 +23,7 @@ module BrainzLab
|
|
|
23
23
|
if @config.pulse_buffer_size > 1
|
|
24
24
|
buffer_trace(payload)
|
|
25
25
|
else
|
|
26
|
-
post(
|
|
26
|
+
post('/api/v1/traces', payload)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -31,13 +31,13 @@ module BrainzLab
|
|
|
31
31
|
return unless @config.pulse_enabled && @config.pulse_valid?
|
|
32
32
|
return if payloads.empty?
|
|
33
33
|
|
|
34
|
-
post(
|
|
34
|
+
post('/api/v1/traces/batch', { traces: payloads })
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def send_metric(payload)
|
|
38
38
|
return unless @config.pulse_enabled && @config.pulse_valid?
|
|
39
39
|
|
|
40
|
-
post(
|
|
40
|
+
post('/api/v1/metrics', payload)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def flush
|
|
@@ -79,9 +79,9 @@ module BrainzLab
|
|
|
79
79
|
def post(path, body)
|
|
80
80
|
uri = URI.join(@config.pulse_url, path)
|
|
81
81
|
request = Net::HTTP::Post.new(uri)
|
|
82
|
-
request[
|
|
83
|
-
request[
|
|
84
|
-
request[
|
|
82
|
+
request['Content-Type'] = 'application/json'
|
|
83
|
+
request['Authorization'] = "Bearer #{@config.pulse_auth_key}"
|
|
84
|
+
request['User-Agent'] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
|
|
85
85
|
request.body = JSON.generate(body)
|
|
86
86
|
|
|
87
87
|
execute_with_retry(uri, request)
|
|
@@ -94,7 +94,7 @@ module BrainzLab
|
|
|
94
94
|
retries = 0
|
|
95
95
|
begin
|
|
96
96
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
97
|
-
http.use_ssl = uri.scheme ==
|
|
97
|
+
http.use_ssl = uri.scheme == 'https'
|
|
98
98
|
http.open_timeout = 5
|
|
99
99
|
http.read_timeout = 10
|
|
100
100
|
|
|
@@ -102,7 +102,11 @@ module BrainzLab
|
|
|
102
102
|
|
|
103
103
|
case response.code.to_i
|
|
104
104
|
when 200..299
|
|
105
|
-
|
|
105
|
+
begin
|
|
106
|
+
JSON.parse(response.body)
|
|
107
|
+
rescue StandardError
|
|
108
|
+
{}
|
|
109
|
+
end
|
|
106
110
|
when 429, 500..599
|
|
107
111
|
raise RetryableError, "Server error: #{response.code}"
|
|
108
112
|
else
|