salestation 3.3.0 → 3.7.0

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: 9b02a58d20a83f0b3cf88032b0d36b101f2e37fbae8b92393b2d087dc52f004d
4
- data.tar.gz: 851f1eb6a3edfe57edecf51a41d2ee7dd4762577ef3e42c6a3b9343a163c3418
3
+ metadata.gz: 7c1c39aa648194b22cc8f4e75bccddaa3d51992c5fcd6c85facadb6960f52db0
4
+ data.tar.gz: 9d2132d9c51921bec0146a5a22c7cc7f6c5dbbf3ef5a044cd1f405d4e4953e78
5
5
  SHA512:
6
- metadata.gz: e5d3870a03be8ad6f4f6861c5c5879f8e16267be6086da08a1de7253881b0ed7e88484db5ce1167700b71769b4b76124f83d9eabf0275e5d62015b101ff28dfa
7
- data.tar.gz: 295578db7f08c01ac68aa84484a5fc7de7984c74a1517677f4a63d7f69cd93cf1ec2e94d2dfff0e1908325c401c642dfd7c72204089761c9ec2a8870a14a9739
6
+ metadata.gz: 3f6ba6c35d4e30f10ee547b484457948602d19fcc91da64912bda45ed8043378bea84ceb29d2a5a6912be5c85eb4dc3bf4520b4c96b93e50e4a4e1bebeaf1c57
7
+ data.tar.gz: c116c954f2a544fb5d100718f27c1a599aa1b83b7efa0d0216f365e1137af64d8811a5da362f0652497eb949816bb50e0e1276be0acef67b9caac4b55fefad6f
@@ -1,6 +1,4 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4
5
- - 2.5
6
- before_install: gem install bundler -v 1.17.3
4
+ - 2.7
data/README.md CHANGED
@@ -142,17 +142,26 @@ end
142
142
 
143
143
  Salestation provides a StatsD middleware which can be used record request
144
144
  execution time. A `timing` call with elapsed seconds is made to the provided
145
- StatsD instance with `path`, `method`, `status` tags.
145
+ StatsD instance with `path`, `method`, `status` and `status_class` tags.
146
146
 
147
147
  ```ruby
148
148
  class Webapp < Sinatra::Base
149
149
  # ...
150
150
  use Salestation::Web::StatsdMiddleware,
151
151
  Statsd.new(host, port),
152
- metric: 'my-metric'
152
+ metric: 'my_service.response.time'
153
153
  end
154
154
  ```
155
155
 
156
+ You can configure per-request tags by defining `salestation.statsd.tags` in sinatra `env`:
157
+
158
+ ```ruby
159
+ def my_handler(env)
160
+ env['salestation.statsd.tags'] = ['foo:bar']
161
+ # ...
162
+ end
163
+ ```
164
+
156
165
  ## Development
157
166
 
158
167
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,7 +7,7 @@ require 'dry-types'
7
7
  module Salestation
8
8
  class App
9
9
  module Types
10
- include Dry::Types.module
10
+ include Dry::Types()
11
11
  end
12
12
 
13
13
  def initialize(env:, hooks: {})
@@ -5,7 +5,7 @@ module Salestation
5
5
  module Errors
6
6
  class InvalidInput < Dry::Struct
7
7
  attribute :errors, Types::Strict::Hash
8
- attribute :hints, Types::Coercible::Hash.default({})
8
+ attribute :hints, Types::Coercible::Hash.default({}.freeze)
9
9
  attribute? :debug_message, Types::Strict::String
10
10
  end
11
11
 
@@ -8,7 +8,7 @@ require 'json'
8
8
  module Salestation
9
9
  class Web < Module
10
10
  module Types
11
- include Dry::Types.module
11
+ include Dry::Types()
12
12
  end
13
13
 
14
14
  def initialize(errors: {})
@@ -82,6 +82,10 @@ module Salestation
82
82
  end
83
83
  Deterministic::Result::Success(input)
84
84
  end
85
+
86
+ def merge(other)
87
+ CombinedInputExtractor.new([self, other])
88
+ end
85
89
  end
86
90
 
87
91
  class HeadersExtractor
@@ -32,9 +32,9 @@ module Salestation
32
32
  class Error < Response
33
33
  attribute :status, Types::Strict::Integer
34
34
  attribute :message, Types::Strict::String
35
- attribute :debug_message, Types::String.default('')
36
- attribute :context, Types::Hash.default({})
37
- attribute :headers, Types::Hash.default({})
35
+ attribute :debug_message, Types::Coercible::String.default('')
36
+ attribute :context, Types::Hash.default({}.freeze)
37
+ attribute :headers, Types::Hash.default({}.freeze)
38
38
 
39
39
  def body
40
40
  {message: message, debug_message: debug_message}
@@ -44,7 +44,7 @@ module Salestation
44
44
  class Success < Response
45
45
  attribute :status, Types::Strict::Integer
46
46
  attribute :body, Types::Strict::Hash | Types::Strict::Array
47
- attribute :headers, Types::Hash.default({})
47
+ attribute :headers, Types::Hash.default({}.freeze)
48
48
  end
49
49
 
50
50
  class UnprocessableEntityFromSchemaErrors
@@ -3,6 +3,9 @@
3
3
  module Salestation
4
4
  class Web < Module
5
5
  class StatsdMiddleware
6
+ EXTRA_TAGS_ENV_KEY = 'salestation.statsd.tags'
7
+
8
+ DURATION_MILLISECOND_PRECISION = 3
6
9
 
7
10
  def initialize(app, statsd, metric:)
8
11
  @app = app
@@ -11,7 +14,7 @@ module Salestation
11
14
  end
12
15
 
13
16
  def call(env)
14
- start = Time.now
17
+ start = system_monotonic_time
15
18
 
16
19
  status, header, body = @app.call env
17
20
 
@@ -23,14 +26,27 @@ module Salestation
23
26
  'unknown-route'
24
27
  end
25
28
 
26
- @statsd.timing(@metric, (Time.now - start) * 1000, tags: [
27
- "path:#{ path }",
28
- "method:#{ method }",
29
- "status:#{ status }"
30
- ])
29
+ tags = [
30
+ "path:#{path}",
31
+ "method:#{method}",
32
+ "status:#{status}",
33
+ "status_class:#{status / 100}xx"
34
+ ] + env.fetch(EXTRA_TAGS_ENV_KEY, [])
35
+
36
+ @statsd.timing(@metric, duration_ms(from: start), tags: tags)
31
37
 
32
38
  [status, header, body]
33
39
  end
40
+
41
+ private
42
+
43
+ def duration_ms(from:)
44
+ ((system_monotonic_time - from) * 1000).round(DURATION_MILLISECOND_PRECISION)
45
+ end
46
+
47
+ def system_monotonic_time
48
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
49
+ end
34
50
  end
35
51
  end
36
52
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "salestation"
7
- spec.version = "3.3.0"
7
+ spec.version = "3.7.0"
8
8
  spec.authors = ["Glia TechMovers"]
9
9
  spec.email = ["techmovers@glia.com"]
10
10
 
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "bundler", "~> 2.0"
23
+ spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "pry", "~> 0.10.4"
26
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salestation
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
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: '13.0'
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: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.0.6
161
+ rubygems_version: 3.0.3
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: ''