upfluence-utils 0.7.1 → 0.8.4

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: bf89bde520f3bb7e52d3b43d14a6e514a64ef00359acc7a83a8380487279be04
4
- data.tar.gz: bddf013280ab4620b7c96da45e47572b96aefe1bf6909b85be6e2c1281f9c06b
3
+ metadata.gz: d310a8621edea92a80becf4c98aff88eb475b0400433c0106f22e955ee2ff450
4
+ data.tar.gz: a54d85a72eff261b5d5365de804272fcd2a79a36e910bdb63256f0c882312f86
5
5
  SHA512:
6
- metadata.gz: 99694e5f48b6878ec4b47d0e1bbba0ca7b99e531e4224750ab9ebe7856d81dc902dc2026e99ea3c0d2dd17bc71e5c21a5ba906f092bf1fe2aa4e64d6413f7592
7
- data.tar.gz: 19f50f74f14cbcc531a769d66b248b266b50e091e37e60b1b4f48a49a8022d63ca57b903a84fd69ce16df6a7164f5b24a7839b31213d10602b1de9f546920237
6
+ metadata.gz: 0be0be14842252b5653b6e9f4026d60999a3814a940f80b09c2b4fe264fc484422252ce94a132409d40bd6c0df83c670536b3cf3bf5ad8759f8a4391be8a68f9
7
+ data.tar.gz: '087d9a21f297581df4b94134aa6bb964a5827bbd3abe71d95af2ce34f67aeee29d75366e768e5d667222aca2badb01f20f9d11a7a14b33fe9a4ef3e672ee1a9c'
@@ -0,0 +1,30 @@
1
+ ### What does this PR do?
2
+
3
+ <!-- A brief description of the context of this pull request and its purpose. -->
4
+
5
+ Fixes #<!-- enter issue number here -->
6
+
7
+ ### What are the observable changes?
8
+ <!-- This question could be adequate with multiple use cases, for example: -->
9
+
10
+ <!-- Frontend: explain the feature created / updated, give instructions telling how to see the change in staging -->
11
+ <!-- Performance: what metric should be impacted, link to the right graphana dashboard for exemple -->
12
+ <!-- Bug: a given issue trail on sentry should stop happening -->
13
+ <!-- Feature: Implements X thrift service / Z HTTP REST API added, provide instructions on how leverage your feature from staging or your workstation -->
14
+
15
+ ### Good PR checklist
16
+
17
+ - [ ] Title makes sense
18
+ - [ ] Is against the correct branch
19
+ - [ ] Only addresses one issue
20
+ - [ ] Properly assigned
21
+ - [ ] Added/updated tests
22
+ - [ ] Added/updated documentation
23
+ - [ ] Properly labeled
24
+
25
+ ### Additional Notes
26
+
27
+ <!--
28
+ You can add anything you want here, an explanation on the way you built your implementation,
29
+ precisions on the origin of the bug, gotchas you need to mention.
30
+ -->
@@ -3,3 +3,4 @@ require 'upfluence/endpoint/api_endpoint'
3
3
  require 'upfluence/mixin/strong_parameters'
4
4
  require 'upfluence/mixin/pagination'
5
5
  require 'upfluence/base/exceptions/validation_error'
6
+ require 'upfluence/resources'
@@ -1,4 +1,6 @@
1
1
  require 'sinatra'
2
+ require 'active_record'
3
+ require 'active_support/hash_with_indifferent_access'
2
4
 
3
5
  module Upfluence
4
6
  module HTTP
@@ -31,9 +33,9 @@ module Upfluence
31
33
  token = params[:access_token]
32
34
 
33
35
  unless token
34
- pattern = /^Bearer /
35
- header = request.env['HTTP_AUTHORIZATION']
36
- token = header.gsub(pattern, '') if header && header.match(pattern)
36
+ pattern = /^Bearer /
37
+ header = request.env['HTTP_AUTHORIZATION']
38
+ token = header.gsub(pattern, '') if header&.match(pattern)
37
39
  end
38
40
 
39
41
  token
@@ -50,13 +52,17 @@ module Upfluence
50
52
  opts = args.first || {}
51
53
 
52
54
  result = if resource.is_a? Enumerable
53
- USerializer::ArraySerializer.new(resource, *args).to_json
55
+ USerializer::ArraySerializer.new(
56
+ resource, *args
57
+ ).to_json
54
58
  elsif opts[:serializer]
55
59
  opts[:serializer].new(resource, *args).to_json
56
60
  elsif resource.respond_to?(:serialize)
57
61
  resource.serialize(*args).to_json
58
62
  else
59
- USerializer.serializer_for(resource).new(resource, *args).to_json
63
+ USerializer.serializer_for(resource).new(
64
+ resource, *args
65
+ ).to_json
60
66
  end
61
67
  end
62
68
 
@@ -64,7 +70,9 @@ module Upfluence
64
70
  end
65
71
 
66
72
  def json_params
67
- ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(request_body))
73
+ ActiveSupport::HashWithIndifferentAccess.new(
74
+ JSON.parse(request_body)
75
+ )
68
76
  end
69
77
  end
70
78
 
@@ -5,6 +5,8 @@ module Upfluence
5
5
  module HTTP
6
6
  module Middleware
7
7
  class Prometheus
8
+ LABELS = %i[path method env].freeze
9
+
8
10
  def initialize(app, registry = ::Prometheus::Client.registry)
9
11
  @registry = registry
10
12
 
@@ -12,14 +14,16 @@ module Upfluence
12
14
  :uhttp_handler_requests_total
13
15
  ) || @registry.counter(
14
16
  :uhttp_handler_requests_total,
15
- 'Histogram of processed items',
17
+ docstring: 'Histogram of processed items',
18
+ labels: LABELS + %i[status]
16
19
  )
17
20
 
18
21
  @request_histogram = @registry.get(
19
22
  :uhttp_handler_requests_duration_second
20
23
  ) || @registry.histogram(
21
24
  :uhttp_handler_requests_duration_second,
22
- 'Histogram of processing time',
25
+ docstring: 'Histogram of processing time',
26
+ labels: LABELS
23
27
  )
24
28
 
25
29
  @app = app
@@ -41,19 +45,21 @@ module Upfluence
41
45
 
42
46
  def record(env, code, duration)
43
47
  @request_total_count.increment(
44
- path: parse_route(env),
45
- method: env['REQUEST_METHOD'].downcase,
46
- status: code,
47
- env: Upfluence.env.to_s
48
+ labels: {
49
+ path: parse_route(env),
50
+ method: env['REQUEST_METHOD'].downcase,
51
+ status: code,
52
+ env: Upfluence.env.to_s
53
+ }
48
54
  )
49
55
 
50
56
  @request_histogram.observe(
51
- {
52
- path: parse_route(env),
57
+ duration,
58
+ labels: {
59
+ path: parse_route(env),
53
60
  method: env['REQUEST_METHOD'].downcase,
54
- env: Upfluence.env.to_s
55
- },
56
- duration
61
+ env: Upfluence.env.to_s
62
+ }
57
63
  )
58
64
  end
59
65
 
@@ -75,8 +81,8 @@ module Upfluence
75
81
 
76
82
  path = Rack::Request.new(env).path
77
83
 
78
- splitted_template = route.split(' ').last.split('/').select do |v|
79
- v != ''
84
+ splitted_template = route.split(' ').last.split('/').reject do |v|
85
+ v.eql?('')
80
86
  end.reverse
81
87
 
82
88
  path.split('/').reverse.map.with_index do |part, i|
@@ -0,0 +1,30 @@
1
+ module Upfluence
2
+ class Peer
3
+ attr_reader :environment, :authority, :instance_name, :project_name,
4
+ :app_name
5
+
6
+ def initialize(opts = {})
7
+ @authority = opts[:authority] || 'local'
8
+ @instance_name = opts[:instance_name] || 'unknown-server'
9
+ @app_name = opts[:app_name] || 'unknown-name'
10
+ @project_name = opts[:project_name] || 'unknown-app'
11
+ @environment = opts[:environment] || 'development'
12
+ end
13
+
14
+ def to_url
15
+ "peer://#{@environment}@#{@authority}/#{@instance_name}"
16
+ end
17
+
18
+ class << self
19
+ def from_env
20
+ Peer.new(
21
+ authority: ENV['AUTHORITY'],
22
+ instance_name: ENV['INSTANCE_NAME'],
23
+ app_name: ENV['APP_NAME'],
24
+ project_name: ENV['PROJECT_NAME'],
25
+ environment: ENV['ENV']
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ require 'upfluence/resources/countries'
@@ -0,0 +1,23 @@
1
+ module Upfluence
2
+ module Resources
3
+ COUNTRIES = %w[
4
+ US FR GB DE CH AF AL DZ AS AD AO AI
5
+ AG AR AM AW AU AT AZ BS BH BD BB BY
6
+ BE BZ BJ BM BT BO BA BW BR BN BG BF
7
+ BI CV KH CM CA KY CF TD CL CN CO KM
8
+ CG CD CK CI HR CU CY CZ DK DJ DM DO
9
+ GW GY HT VA HN HK HU IS IN ID IR IQ
10
+ IE IM IL IT JM JP JE JO KZ KE KI KP
11
+ KR KW KG LA LV LB LI LS LR LY LT LU
12
+ MO MK MG MW MY MV ML MT MH MQ MR MU
13
+ MX FM MD MC MN ME MS MA MZ MM NA NR
14
+ NP NL NC NZ NI NE NG NO OM PK PW PS
15
+ PA PG PY PE PH PL PT PR QA RE RO RU
16
+ RW KN LC VC WS SM ST SA SN RS SC SL
17
+ SG SK SI SB SO ZA ES LK SD SR SZ SE
18
+ SY TW TJ TZ TH TL TG TO TT TN TR TM
19
+ TC TV UG UA AE GB UY UZ VU VE VN VG
20
+ VI EH YE ZM ZW CR
21
+ ].freeze
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.7.1'.freeze
3
+ VERSION = '0.8.4'.freeze
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.12"
20
- spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency "rake", ">= 12.3.3"
21
21
  spec.add_development_dependency "rspec", "~> 3.0"
22
22
  spec.add_runtime_dependency 'upfluence-thrift', '~> 2.1'
23
23
  spec.add_runtime_dependency 'base-thrift', '>= 0.1.0'
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency 'puma'
30
30
  spec.add_runtime_dependency 'rack'
31
31
  spec.add_runtime_dependency 'stackprof'
32
- spec.add_runtime_dependency 'prometheus-client', '~> 0.9.0'
32
+ spec.add_runtime_dependency 'prometheus-client', '~> 2.1'
33
33
  spec.add_runtime_dependency 'userializer'
34
+ spec.add_runtime_dependency 'activerecord'
34
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2020-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 0.9.0
201
+ version: '2.1'
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: 0.9.0
208
+ version: '2.1'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: userializer
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -220,13 +220,28 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
- description:
223
+ - !ruby/object:Gem::Dependency
224
+ name: activerecord
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ description:
224
238
  email:
225
239
  - dev@upfluence.com
226
240
  executables: []
227
241
  extensions: []
228
242
  extra_rdoc_files: []
229
243
  files:
244
+ - ".github/pull_request_template.md"
230
245
  - ".gitignore"
231
246
  - ".rspec"
232
247
  - ".travis.yml"
@@ -256,7 +271,10 @@ files:
256
271
  - lib/upfluence/logger.rb
257
272
  - lib/upfluence/mixin/pagination.rb
258
273
  - lib/upfluence/mixin/strong_parameters.rb
274
+ - lib/upfluence/peer.rb
259
275
  - lib/upfluence/pool.rb
276
+ - lib/upfluence/resources.rb
277
+ - lib/upfluence/resources/countries.rb
260
278
  - lib/upfluence/utils.rb
261
279
  - lib/upfluence/utils/http/middleware/null.rb
262
280
  - lib/upfluence/utils/semaphore.rb
@@ -273,7 +291,7 @@ homepage: https://github.com/upfluence/rbutils
273
291
  licenses:
274
292
  - MIT
275
293
  metadata: {}
276
- post_install_message:
294
+ post_install_message:
277
295
  rdoc_options: []
278
296
  require_paths:
279
297
  - lib
@@ -288,8 +306,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
306
  - !ruby/object:Gem::Version
289
307
  version: '0'
290
308
  requirements: []
291
- rubygems_version: 3.0.3
292
- signing_key:
309
+ rubygems_version: 3.1.4
310
+ signing_key:
293
311
  specification_version: 4
294
312
  summary: Upfluence common utils for Ruby projects
295
313
  test_files: []