metrics_adapter 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6525fffc00cde5df061ba6ce5621b9db422ddd5d09393b754ce5919b7c536f87
4
- data.tar.gz: 0663ee07b6c96170f4b4050e90821b64093ff9fe9e784d14b28c2478139ceda7
3
+ metadata.gz: d7d1968699aa29c1905c1c244a71b9099a16cfccb66e9395ffa8c59b1332440d
4
+ data.tar.gz: 7f96f6eb51f45b679a845d1d42fd25d2fa1ca7672f3427b256d952bcf8e3a7bb
5
5
  SHA512:
6
- metadata.gz: 4ccad7b481311aaa2b2bc79eac01993f466e0a842ca5428d63b87aa53554da2a44148e08f5dec0305b374ee187272d64c21137becf530cde6e85c129fb4c46e4
7
- data.tar.gz: 3f6bd8da506014433441d190aed87607800e2bd1d1a21ad2cb2c07bf9bba1b72349980db823fef09d8a38730c8bff39772b5736ef8fda57459ae1e859550315a
6
+ metadata.gz: 705ae7487d7d3ba8969fa0f06f34d32849b1b897d912c5083f7ba37d2dc64a595e93fe98e28e6d0abcdad5dd30cc9fba0b656f785f0355337e839fbc53c6143c
7
+ data.tar.gz: a650442ffb4ff0bac4307b502a785c98b3addb38069f70888fac2ef2fcb0884f363cae0b489a0a5b06d089823f65fcccdd66326863043783ff4caba28a61328c
data/README.md CHANGED
@@ -60,6 +60,8 @@ Below we setup the Keen service using the slow request tracker:
60
60
  config.extra_attributes = { app: 'My-App' }
61
61
  config.logger = Rails.logger
62
62
  config.trackers = %i(slow_request)
63
+ block = -> { ENV['SOME_ENVIRONMENT_VARIABLE'] == 'production' }
64
+ config.conditionals = { slow_request: block }
63
65
  config.thresholds = { slow_request: 1_000 }
64
66
  end
65
67
  ```
@@ -1,7 +1,7 @@
1
1
  require 'mixpanel-ruby'
2
2
 
3
3
  class MetricsAdapter::Adapters::Mixpanel
4
- attr_reader :tracker
4
+ attr_reader :tracker, :logger
5
5
 
6
6
  def initialize(options)
7
7
  @tracker = ::Mixpanel::Tracker.new(options.fetch(:secret))
@@ -2,12 +2,7 @@
2
2
  ## 1. Tracks slow request given a threshold
3
3
  ##
4
4
  ActiveSupport::Notifications.subscribe('process_action.action_controller') do |event|
5
- trackers = MetricsAdapter.trackers
6
- conditional = MetricsAdapter.conditionals[:slow_request]
7
-
8
- if conditional.present? && conditional.call.blank?
9
- Rails.logger.info('Metrics Adapter wont publish slow request metric.')
10
- else
11
- MetricsAdapter::Trackers::SlowRequest.new(event).call if trackers.include?(:slow_request)
5
+ if MetricsAdapter.trackers.include?(:slow_request)
6
+ MetricsAdapter::Trackers::SlowRequest.new(event).call
12
7
  end
13
8
  end
@@ -2,6 +2,7 @@ module MetricsAdapter
2
2
  module Trackers
3
3
  class Base
4
4
  attr_reader :adapter,
5
+ :conditional,
5
6
  :event,
6
7
  :extra_attributes,
7
8
  :logger,
@@ -16,6 +17,7 @@ module MetricsAdapter
16
17
  @extra_attributes = ::MetricsAdapter.extra_attributes
17
18
  @logger = ::MetricsAdapter.logger
18
19
  @metric_name = self.class.name.demodulize.underscore
20
+ @conditional = ::MetricsAdapter.conditionals[@metric_name.to_sym]
19
21
  end
20
22
 
21
23
  def call
@@ -9,6 +9,8 @@ module MetricsAdapter
9
9
  end
10
10
 
11
11
  def call
12
+ return if conditional.present? && conditional.call.blank?
13
+
12
14
  if event.duration > slow_request_threshold
13
15
  data = {
14
16
  id: event.transaction_id,
@@ -19,6 +21,9 @@ module MetricsAdapter
19
21
  idle_time_in_ms: event.idle_time,
20
22
  path: event.payload[:path]
21
23
  }.merge(extra_attributes)
24
+ logger.info(
25
+ "Slow request detected. Sending data to #{adapter.class.name}"
26
+ ) if logger
22
27
  adapter.publish(data)
23
28
  end
24
29
  end
@@ -1,3 +1,3 @@
1
1
  module MetricsAdapter
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'bundler', '~> 1.17'
30
30
  spec.add_development_dependency 'rake'
31
31
  spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'byebug'
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrics_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Form builder developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Collect custom metrics from your application.
98
112
  email:
99
113
  - form-builder-team@digital.justice.gov.uk