faraday-cdn-metrics 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/faraday-cdn-metrics.gemspec +16 -17
- data/lib/faraday_cdn_metrics.rb +14 -9
- data/lib/faraday_cdn_metrics/server_caches/fastly.rb +2 -1
- data/lib/faraday_cdn_metrics/version.rb +3 -1
- metadata +13 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e26a4774da98a6ac466a57081dac0fefff7eb886083b8c30273dc93f4ecf276c
|
4
|
+
data.tar.gz: 9b89c3c6128a8ddf9fd34f5657465f34cdf2d0af000beb970706eae90d598101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c6bebc2b6f14ed7851354035bee1e6fbb8a3fee9e52aece407fb42b6e112039a5dfd709c80fdfb7a6069bebb2e6fe500e2058b0e20536f7b3a1fbf80510731
|
7
|
+
data.tar.gz: 6a86e8a07585d3e3a223544283b73f5a68072cca7576dcaae36bad55cae3644503da8392a88544a595ba96553c77b9b4c3b8e2600bbe280d8d77d33e9cb6b4c9
|
data/faraday-cdn-metrics.gemspec
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
require "faraday_cdn_metrics/version"
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/faraday_cdn_metrics/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'faraday-cdn-metrics'
|
8
7
|
spec.version = FaradayCdnMetrics::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Anson Kelly']
|
9
|
+
spec.email = ['anson.kelly@carwow.co.uk']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'Metrics requests to a CDN like Fastly'
|
12
|
+
spec.description = 'Metrics requests to a CDN like Fastly'
|
13
|
+
spec.homepage = 'https://github.com/carwow/faraday-cdn-metrics'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
17
|
f.match(%r{^(test|spec|features)/})
|
19
18
|
end
|
20
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
21
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
23
22
|
|
24
|
-
spec.add_dependency
|
23
|
+
spec.add_dependency 'faraday', '~> 1'
|
25
24
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
28
|
end
|
data/lib/faraday_cdn_metrics.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_cdn_metrics/version'
|
3
5
|
require 'faraday_cdn_metrics/server_caches/fastly'
|
4
6
|
|
5
7
|
module FaradayCdnMetrics
|
6
8
|
class CdnMetrics < Faraday::Middleware
|
7
|
-
|
8
9
|
# Cache status' shamelessly copied from faraday-http-cache
|
9
10
|
CACHE_STATUSES = [
|
10
11
|
# The request was not cacheable.
|
@@ -29,9 +30,12 @@ module FaradayCdnMetrics
|
|
29
30
|
:bypass
|
30
31
|
].freeze
|
31
32
|
|
32
|
-
EVENT_NAME = 'cdn_metrics.http_cache'
|
33
|
+
EVENT_NAME = 'cdn_metrics.http_cache'
|
33
34
|
|
34
|
-
def initialize(app,
|
35
|
+
def initialize(app,
|
36
|
+
instrumenter: nil,
|
37
|
+
instrument_name: EVENT_NAME,
|
38
|
+
server_cache: FaradayCdnMetrics::ServerCaches::Fastly)
|
35
39
|
super(app)
|
36
40
|
|
37
41
|
@instrumenter = instrumenter
|
@@ -44,7 +48,11 @@ module FaradayCdnMetrics
|
|
44
48
|
client_cache_status = find_client_cache_status(response_env)
|
45
49
|
server_cache_status = find_server_cache_status(response_env)
|
46
50
|
|
47
|
-
@instrumenter.instrument(@instrument_name, {
|
51
|
+
@instrumenter.instrument(@instrument_name, {
|
52
|
+
env: response_env,
|
53
|
+
client_cache_status: client_cache_status,
|
54
|
+
server_cache_status: server_cache_status
|
55
|
+
})
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
@@ -62,13 +70,10 @@ module FaradayCdnMetrics
|
|
62
70
|
return :valid if server_cache.hit_while_revalidate?
|
63
71
|
return :fresh if server_cache.hit?
|
64
72
|
return :miss if server_cache.miss?
|
73
|
+
|
65
74
|
:unknown
|
66
75
|
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
70
|
-
|
71
|
-
Faraday.register_middleware cdn_metrics: FaradayCdnMetrics::CdnMetrics
|
72
|
-
elsif Faraday::Middleware.respond_to?(:register_middleware)
|
73
|
-
Faraday::Middleware.register_middleware cdn_metrics: FaradayCdnMetrics::CdnMetrics
|
74
|
-
end
|
79
|
+
Faraday::Middleware.register_middleware cdn_metrics: FaradayCdnMetrics::CdnMetrics
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-cdn-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anson Kelly
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1'
|
20
20
|
type: :runtime
|
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: '1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '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: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
108
|
-
rubygems_version: 2.5.2
|
107
|
+
rubygems_version: 3.1.2
|
109
108
|
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: Metrics requests to a CDN like Fastly
|