easy_server_timing 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/easy_server_timing.gemspec +34 -0
- data/lib/easy_server_timing.rb +19 -0
- data/lib/easy_server_timing/middleware.rb +34 -0
- data/lib/easy_server_timing/railtie.rb +26 -0
- data/lib/easy_server_timing/version.rb +5 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 611fbd68038d5f93dbf2ef9b1715a09c74864c38bfa56171806fd7b23d9e1fee
|
4
|
+
data.tar.gz: db3878cab2ab527b875b869947be20190d67518fa5ca112b0c3e5111d0ca7254
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a63a3834f327fa95eff8a7d1fbff0a5f0ecb51acb9b9ace6486ec394fb26cf74a7ab615828ac0cdaed6a573d2f57aedc0b919cee297e67cb106f772dc969343a
|
7
|
+
data.tar.gz: 1b78f328427aae81726b53203db95e4f3f29e48724c03711e7c75367c576a9113c5c4b53d2b58021da3babf828ee54a53332ca6dceb5b0a9a82c5cd4a7eb5869
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
|
4
|
+
|
5
|
+
## [0.1.1] - Unreleased
|
6
|
+
|
7
|
+
## [0.1.0] - 2020-02-09
|
8
|
+
### Added
|
9
|
+
- init
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Pavel Rosický
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# EasyServerTiming
|
2
|
+
based on https://github.com/rails/rails/pull/36289
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'easy_server_timing'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install easy_server_timing
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
options
|
22
|
+
```ruby
|
23
|
+
Rails.application.configure do
|
24
|
+
config.easy_server_timing.enabled = true
|
25
|
+
config.easy_server_timing.rails_environments = ['development']
|
26
|
+
config.easy_server_timing.notification_pattern = /.*/
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](https://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 "easy_server_timing"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'lib/easy_server_timing/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "easy_server_timing"
|
5
|
+
spec.version = EasyServerTiming::VERSION
|
6
|
+
spec.authors = ["Pavel Rosicky"]
|
7
|
+
spec.email = ["pavel.rosicky@easy.cz"]
|
8
|
+
|
9
|
+
spec.summary = %q{Server timing}
|
10
|
+
spec.description = %q{Server timing}
|
11
|
+
spec.homepage = "https://github.com/ahorek/easy_server_timing"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib", "lib/easy_server_timing"]
|
29
|
+
|
30
|
+
spec.add_dependency('rack')
|
31
|
+
spec.add_dependency('activesupport', '>= 5.2.0')
|
32
|
+
#spec.add_development_dependency('railties', '>= 5.2.0')
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyServerTiming
|
4
|
+
def self.notification_pattern
|
5
|
+
@notification_pattern || /^(?!request).*$/
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.notification_pattern=(pattern)
|
9
|
+
@notification_pattern = pattern
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.rails?
|
13
|
+
defined? Rails::Railtie
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "easy_server_timing/version"
|
18
|
+
require "easy_server_timing/middleware"
|
19
|
+
require "easy_server_timing/railtie" if EasyServerTiming.rails?
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/notifications"
|
4
|
+
require "active_support/core_ext/object/try"
|
5
|
+
|
6
|
+
module EasyServerTiming
|
7
|
+
class Middleware
|
8
|
+
SERVER_TIMING_HEADER = "Server-Timing"
|
9
|
+
|
10
|
+
def initialize(app)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
events = []
|
16
|
+
subscriber = ActiveSupport::Notifications.subscribe(EasyServerTiming.notification_pattern) do |*args|
|
17
|
+
events << ActiveSupport::Notifications::Event.new(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
status, headers, body = begin
|
21
|
+
@app.call(env)
|
22
|
+
ensure
|
23
|
+
ActiveSupport::Notifications.unsubscribe(subscriber)
|
24
|
+
end
|
25
|
+
|
26
|
+
header_info = events.group_by(&:name).map do |event_name, events_collection|
|
27
|
+
"#{event_name};dur=#{events_collection.sum { |e| e.duration.to_f }}"
|
28
|
+
end
|
29
|
+
headers[SERVER_TIMING_HEADER] = header_info.join(",")
|
30
|
+
|
31
|
+
[ status, headers, body ]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyServerTiming
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "easy_server_timing.configure_rails_initialization" do |app|
|
6
|
+
if correct_environment?(app) && app.config.easy_server_timing.enabled
|
7
|
+
EasyServerTiming.notification_pattern = app.config.easy_server_timing.notification_pattern
|
8
|
+
|
9
|
+
app.middleware.use EasyServerTiming::Middleware
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def correct_environment?(app)
|
14
|
+
if app.config.easy_server_timing.rails_environments
|
15
|
+
app.config.easy_server_timing.rails_environments.include?(Rails.env.to_s)
|
16
|
+
else
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
config.easy_server_timing = ActiveSupport::OrderedOptions.new
|
22
|
+
config.easy_server_timing.enabled = true
|
23
|
+
config.easy_server_timing.notification_pattern = EasyServerTiming.notification_pattern
|
24
|
+
config.easy_server_timing.rails_environments = nil
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_server_timing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Rosicky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Server timing
|
56
|
+
email:
|
57
|
+
- pavel.rosicky@easy.cz
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- easy_server_timing.gemspec
|
73
|
+
- lib/easy_server_timing.rb
|
74
|
+
- lib/easy_server_timing/middleware.rb
|
75
|
+
- lib/easy_server_timing/railtie.rb
|
76
|
+
- lib/easy_server_timing/version.rb
|
77
|
+
homepage: https://github.com/ahorek/easy_server_timing
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata:
|
81
|
+
homepage_uri: https://github.com/ahorek/easy_server_timing
|
82
|
+
source_code_uri: https://github.com/ahorek/easy_server_timing
|
83
|
+
changelog_uri: https://github.com/ahorek/easy_server_timing/CHANGELOG.md
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
- lib/easy_server_timing
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.3.0
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Server timing
|
104
|
+
test_files: []
|