salestation 3.3.0 → 3.7.0
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/.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/extractors.rb +4 -0
- data/lib/salestation/web/responses.rb +4 -4
- data/lib/salestation/web/statsd_middleware.rb +22 -6
- data/salestation.gemspec +3 -3
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c1c39aa648194b22cc8f4e75bccddaa3d51992c5fcd6c85facadb6960f52db0
|
|
4
|
+
data.tar.gz: 9d2132d9c51921bec0146a5a22c7cc7f6c5dbbf3ef5a044cd1f405d4e4953e78
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f6ba6c35d4e30f10ee547b484457948602d19fcc91da64912bda45ed8043378bea84ceb29d2a5a6912be5c85eb4dc3bf4520b4c96b93e50e4a4e1bebeaf1c57
|
|
7
|
+
data.tar.gz: c116c954f2a544fb5d100718f27c1a599aa1b83b7efa0d0216f365e1137af64d8811a5da362f0652497eb949816bb50e0e1276be0acef67b9caac4b55fefad6f
|
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,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 =
|
|
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.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", "~>
|
|
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.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-
|
|
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: '
|
|
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,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.
|
|
161
|
+
rubygems_version: 3.0.3
|
|
162
162
|
signing_key:
|
|
163
163
|
specification_version: 4
|
|
164
164
|
summary: ''
|