salestation 3.4.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -3
- data/README.md +11 -2
- data/lib/salestation/app.rb +1 -1
- data/lib/salestation/app/errors.rb +1 -1
- data/lib/salestation/web.rb +1 -1
- data/lib/salestation/web/responses.rb +14 -6
- data/lib/salestation/web/statsd_middleware.rb +22 -6
- data/salestation.gemspec +3 -3
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2fe9755ef3152c1d5e9821aa2a7be920245b35f7ee95f26fd1e0fe3fb5934468
|
4
|
+
data.tar.gz: f9b1e080731f605cfe7f3ccd2194b923fe70b668757198b105c5ee697ca29637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5988265e60fdfa3f8dc7fe1915e38cd6d3afc1aabeca923de08bf9726c21db355d04ce6d9047bfda8d7b8fa4773104fdacbd169a12de6c75ce702aafbd5e6dd
|
7
|
+
data.tar.gz: 1f3351524846ddea69d54281ab5262ffaa138a4fdf83092614030ca7d60bcb99d44a4944aa1690c04ecf88e41e39cf1d3209588e6730bd92566cf25e66393cec
|
data/.travis.yml
CHANGED
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: '
|
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.
|
data/lib/salestation/app.rb
CHANGED
@@ -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
|
|
data/lib/salestation/web.rb
CHANGED
@@ -32,19 +32,27 @@ 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}
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class UnprocessableEntityError < Error
|
45
|
+
attribute :form_errors, Types::Hash.default({}.freeze)
|
46
|
+
|
47
|
+
def body
|
48
|
+
super.merge(form_errors: errors)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
44
52
|
class Success < Response
|
45
53
|
attribute :status, Types::Strict::Integer
|
46
54
|
attribute :body, Types::Strict::Hash | Types::Strict::Array
|
47
|
-
attribute :headers, Types::Hash.default({})
|
55
|
+
attribute :headers, Types::Hash.default({}.freeze)
|
48
56
|
end
|
49
57
|
|
50
58
|
class UnprocessableEntityFromSchemaErrors
|
@@ -52,7 +60,7 @@ module Salestation
|
|
52
60
|
message = parse_errors(errors)
|
53
61
|
debug_message = parse_hints(hints)
|
54
62
|
|
55
|
-
UnprocessableEntity.new(message: message, debug_message: debug_message)
|
63
|
+
UnprocessableEntity.new(message: message, debug_message: debug_message, form_errors: errors)
|
56
64
|
end
|
57
65
|
|
58
66
|
def self.parse_errors(errors)
|
@@ -99,7 +107,7 @@ module Salestation
|
|
99
107
|
Conflict = Error.with_code(409)
|
100
108
|
RequestEntityTooLarge = Error.with_code(413)
|
101
109
|
UnsupportedMediaType = Error.with_code(415)
|
102
|
-
UnprocessableEntity =
|
110
|
+
UnprocessableEntity = UnprocessableEntityError.with_code(422)
|
103
111
|
|
104
112
|
InternalError = Error.with_code(500)
|
105
113
|
ServiceUnavailable = Error.with_code(503)
|
@@ -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 =
|
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
|
-
|
27
|
-
"path:#{
|
28
|
-
"method:#{
|
29
|
-
"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
|
data/salestation.gemspec
CHANGED
@@ -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.
|
7
|
+
spec.version = "3.8.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", "~>
|
23
|
-
spec.add_development_dependency "rake", "~>
|
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.
|
4
|
+
version: 3.8.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-
|
11
|
+
date: 2020-09-03 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: '
|
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: '
|
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: '
|
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: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,8 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.6.14.4
|
161
|
+
rubygems_version: 3.0.3
|
163
162
|
signing_key:
|
164
163
|
specification_version: 4
|
165
164
|
summary: ''
|