overall_request_times 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/overall_request_times/faraday_middleware.rb +19 -0
- data/lib/overall_request_times/generic_timer.rb +9 -0
- data/lib/overall_request_times/rails_middleware.rb +12 -0
- data/lib/overall_request_times/railtie.rb +7 -0
- data/lib/overall_request_times/timer.rb +33 -0
- data/lib/overall_request_times/version.rb +3 -0
- data/lib/overall_request_times.rb +39 -0
- data/overall_request_times.gemspec +28 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21db3bfd26c2c2cebb6b344e468704450133544a
|
4
|
+
data.tar.gz: e675a9386b2aa8f9d2c69378afe201e834c959a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00e5b953fa78e1835a292108f983e06ac0af827a688a538966f8d782b3a239ef7757d139f7388597395e4da0b2a16af266cd1a046ca427f2e620a50f60f91a04
|
7
|
+
data.tar.gz: d8ad75c0158ef47116dc8622674916a9c0096a6c2c26335673fa8819984f1fdad4a9ca92f573f459ca8077154914772b9bc4f62baa4459ecf3149d0d2028a528
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Donald Plummer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# OverallRequestTimes
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dplummer/overall_request_times.svg?branch=master)](https://travis-ci.org/dplummer/overall_request_times)
|
4
|
+
|
5
|
+
A library for recording the total time spent each request on the HTTP request
|
6
|
+
for a given service. Useful if you use several HTTP backends in each request
|
7
|
+
and want to log the total time spent in each in your Rails log, like the db
|
8
|
+
time.
|
9
|
+
|
10
|
+
Includes a [Faraday](https://github.com/lostisland/faraday) middleware and
|
11
|
+
generic implimentation.
|
12
|
+
|
13
|
+
## WARNING
|
14
|
+
|
15
|
+
I do not know if this is threadsafe yet. Assume it is not.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'overall_request_times'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install overall_request_times
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
RemoteService.connection do |conn|
|
37
|
+
conn.use OverallRequestTimes::FaradayMiddleware, :remote_service_name
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
or just
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
OverallRequestTimes.bm(:remote_service_name) do
|
45
|
+
# remote service call
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Then to extract the totals to log:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
OverallRequestTimes.total_for(:remote_service_name)
|
53
|
+
```
|
54
|
+
|
55
|
+
And reset the totals at the start of your request cycle:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
OverallRequestTimes.reset!
|
59
|
+
```
|
60
|
+
|
61
|
+
If you're using Rails, the reset call isn't needed, since there's a Railtie
|
62
|
+
that adds a middleware to do that.
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
67
|
+
`rake rspec` to run the tests. You can also run `bin/console` for an
|
68
|
+
interactive prompt that will allow you to experiment.
|
69
|
+
|
70
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
71
|
+
release a new version, update the version number in `version.rb`, and then run
|
72
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
73
|
+
git commits and tags, and push the `.gem` file to
|
74
|
+
[rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at
|
79
|
+
https://github.com/[USERNAME]/faraday_overall_request_times.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT
|
84
|
+
License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "overall_request_times"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module OverallRequestTimes
|
4
|
+
class FaradayMiddleware < ::Faraday::Middleware
|
5
|
+
include Timer
|
6
|
+
|
7
|
+
def initialize(app, remote_app_name)
|
8
|
+
super(app)
|
9
|
+
timer_setup(remote_app_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(request_env)
|
13
|
+
start
|
14
|
+
@app.call(request_env).on_complete do |response_env|
|
15
|
+
stop
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module OverallRequestTimes
|
2
|
+
module Timer
|
3
|
+
attr_reader :remote_app_name
|
4
|
+
|
5
|
+
def timer_setup(remote_app_name)
|
6
|
+
@remote_app_name = remote_app_name
|
7
|
+
reset!
|
8
|
+
OverallRequestTimes.register(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def total
|
12
|
+
@total
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset!
|
16
|
+
@total = 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(some_time)
|
20
|
+
@total += some_time
|
21
|
+
end
|
22
|
+
|
23
|
+
def start
|
24
|
+
@started_at = Time.now
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
return unless @started_at
|
29
|
+
ended_at = Time.now
|
30
|
+
add(ended_at - @started_at)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "overall_request_times/version"
|
2
|
+
require "overall_request_times/timer"
|
3
|
+
require "overall_request_times/faraday_middleware"
|
4
|
+
require "overall_request_times/generic_timer"
|
5
|
+
require "overall_request_times/rails_middleware"
|
6
|
+
require "overall_request_times/railtie" if defined?(Rails)
|
7
|
+
|
8
|
+
module OverallRequestTimes
|
9
|
+
def self.wipeout_registry
|
10
|
+
@registry = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.registry
|
14
|
+
@registry ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.reset!
|
18
|
+
registry.each { |_, timer| timer.reset! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.register(timer)
|
22
|
+
registry[timer.remote_app_name] ||= timer
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.total_for(remote_app_name)
|
26
|
+
timer = registry[remote_app_name]
|
27
|
+
timer ? timer.total : 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bm(remote_app_name, &block)
|
31
|
+
registry[remote_app_name] ||= GenericTimer.new(remote_app_name)
|
32
|
+
registry[remote_app_name].start
|
33
|
+
begin
|
34
|
+
block.call
|
35
|
+
ensure
|
36
|
+
registry[remote_app_name].stop
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'overall_request_times/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "overall_request_times"
|
8
|
+
spec.version = OverallRequestTimes::VERSION
|
9
|
+
spec.authors = ["Donald Plummer"]
|
10
|
+
spec.email = ["donald.plummer@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{For recording overall times using remote services.}
|
13
|
+
spec.homepage = "https://github.com/dplummer/overall_request_times"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 0.8.9"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "timecop"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: overall_request_times
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Donald Plummer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.9
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.9
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- donald.plummer@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/overall_request_times.rb
|
114
|
+
- lib/overall_request_times/faraday_middleware.rb
|
115
|
+
- lib/overall_request_times/generic_timer.rb
|
116
|
+
- lib/overall_request_times/rails_middleware.rb
|
117
|
+
- lib/overall_request_times/railtie.rb
|
118
|
+
- lib/overall_request_times/timer.rb
|
119
|
+
- lib/overall_request_times/version.rb
|
120
|
+
- overall_request_times.gemspec
|
121
|
+
homepage: https://github.com/dplummer/overall_request_times
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.4.6
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: For recording overall times using remote services.
|
145
|
+
test_files: []
|