i18n-backend-http 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d1eb9b82080729ea52cde7a2e1987a395d20199
4
- data.tar.gz: e99fa542ce7b71b3aeee58a5dd59628438fd69e6
3
+ metadata.gz: f8ea78a7b0a0e7dfdccc20ca06d46666f58af4db
4
+ data.tar.gz: c799bc4abac23b88bc5528fb6d583c7d54e0c5ef
5
5
  SHA512:
6
- metadata.gz: 0ea3783a6db398e466e610568783dea70db114024537a74509f6398475594829757339715f470af82aea24c6babfdd50729a1c45cfb42696da4801cfcb07b304
7
- data.tar.gz: d06c457e634aec821fba7130451b5535ad908764e388678a9eabc4a144eba3ff00290e398b293caca49310dcceac1bc3b75200c823398afd2d3fbd22bae12e5b
6
+ metadata.gz: 8e5fa2fbeea4b8fc93edaa301cee223f62cc281124f1ff20adc1338a9371da95461034f5519627a54ba8e99af09241b7e8c06e6f7f8f4405a5788dec70b2d6e1
7
+ data.tar.gz: 7584730604387ed2f9fce284cce34edf7f389b1940d13c5085166546cb678221244eb3f27f2e44d554856f45c9a616c9557faea705e58ea98ca6d8da13e02395
@@ -4,26 +4,56 @@ module I18n
4
4
  module Backend
5
5
  class Http
6
6
  class I18n::Backend::Http::EtagHttpClient
7
+ STATS_NAMESPACE = 'i18n-backend-http.etag_client'.freeze
8
+
7
9
  def initialize(options)
8
10
  @options = options
9
11
  end
10
12
 
11
13
  def download(path, etag:)
12
14
  @client ||= Faraday.new(@options[:host])
15
+ start = Time.now
16
+
13
17
  response = @client.get(path) do |request|
14
18
  request.headers.merge!(@options[:headers]) if @options[:headers]
15
19
  request.headers["If-None-Match"] = etag if etag
16
- request.options[:timeout] = @options[:http_read_timeout]
17
- request.options[:open_timeout] = @options[:http_open_timeout]
20
+ request.options[:timeout] = @options[:http_read_timeout]
21
+ request.options[:open_timeout] = @options[:http_open_timeout]
18
22
  end
19
23
 
24
+ tags = {status_code: response.status, path: path}
25
+
26
+ record :timing, time: (Time.now - start).to_f * 1000, tags: tags
27
+
20
28
  case response.status
21
- when 200 then [response.body, response['ETag']]
22
- when 304 then nil
29
+ when 200
30
+ record :success, tags: tags
31
+ [response.body, response['ETag']]
32
+ when 304
33
+ record :success, tags: tags
34
+ nil
23
35
  else
36
+ record :failure, tags: tags
24
37
  raise "Failed request: #{response.inspect}"
25
38
  end
26
39
  end
40
+
41
+ private
42
+
43
+ def record(event, options = {})
44
+ return unless client = @options[:statsd_client]
45
+
46
+ case event
47
+ when :success
48
+ client.increment("#{STATS_NAMESPACE}.success", tags: options[:tags])
49
+ when :failure
50
+ client.increment("#{STATS_NAMESPACE}.failure", tags: options[:tags])
51
+ when :timing
52
+ client.histogram("#{STATS_NAMESPACE}.request_time", options[:time], tags: options[:tags])
53
+ else
54
+ raise "Unknown statsd event type to record"
55
+ end
56
+ end
27
57
  end
28
58
  end
29
59
  end
@@ -1,7 +1,7 @@
1
1
  module I18n
2
2
  module Backend
3
3
  class Http
4
- VERSION = Version = "0.3.1"
4
+ VERSION = Version = "0.3.2"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-backend-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n