lita-metrics 0.1.0 → 0.1.1

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: f4dd851e5cdba74c0ed101f678eb7e047bc51c6f
4
- data.tar.gz: 719ed64a1e3a628884b9a66e73b968bbfe5d7463
3
+ metadata.gz: d5810f0ec2581b26528e22e670b620434b16c654
4
+ data.tar.gz: 117fcf410d0e14dc77173e0e9c516e8453b14500
5
5
  SHA512:
6
- metadata.gz: 36d77bf75181b61bbf202136c4b75628ce66827b258a16b615b15161ec620d1302741af174b38cf97d6f1ec596c5c41ca17727872496bc5c5543c8043bf85e52
7
- data.tar.gz: e5799ba8e53eff76198b1c8f4cae47dc7bee400a2859f9204dc384304900de36eb087cc956353449045881e7e1cd04c574d0065d6d1cd8fb6fcad58e76921eee
6
+ metadata.gz: 60c2efa99e09277b5474dc64b846d5f9a571aaf36063beb1994e3d399b432d496e6399e8c0da7a11ac51646a67172d84870c6c2036493397557f444dd1d96fab
7
+ data.tar.gz: 338da017d948282a05202195ce68b9eb16f5da5a53f6312cf5bcf9ece7b9b377601580b7390c4ebb2216b62f6ce0a387b2e8e4dac8def65f578b4645cf142d3c
@@ -0,0 +1,13 @@
1
+ AbcSize:
2
+ Max: 22
3
+
4
+ Documentation:
5
+ Exclude:
6
+ - lib/lita/handlers/metrics.rb
7
+
8
+ FileName:
9
+ Exclude:
10
+ - lib/lita-metrics.rb
11
+
12
+ LineLength:
13
+ Max: 120
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
4
- script: bundle exec rake
5
- before_install:
6
- - gem update --system
3
+ - 2.1
4
+ - 2.2
7
5
  services:
8
6
  - redis-server
7
+ sudo: false
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "lita", github: "jimmycuadra/lita", ref: "d15f6f0ca95be03a4c76802af19b1a532c61eabc"
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # lita-metrics
2
2
 
3
- [![Build Status](https://travis-ci.org/PagerDuty/lita-metrics.png?branch=master)](https://travis-ci.org/PagerDuty/lita-metrics)
4
- [![Coverage Status](https://coveralls.io/repos/PagerDuty/lita-metrics/badge.png)](https://coveralls.io/r/PagerDuty/lita-metrics)
3
+ [![Build Status](https://img.shields.io/travis/PagerDuty/lita-metrics/master.svg)](https://travis-ci.org/PagerDuty/lita-metrics)
4
+ [![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://tldrlegal.com/license/mit-license)
5
+ [![RubyGems :: RMuh Gem Version](http://img.shields.io/gem/v/lita-metrics.svg)](https://rubygems.org/gems/lita-metrics)
6
+ [![Coveralls Coverage](https://img.shields.io/coveralls/PagerDuty/lita-metrics/master.svg)](https://coveralls.io/r/PagerDuty/lita-metrics)
7
+ [![Code Climate](https://img.shields.io/codeclimate/github/PagerDuty/lita-metrics.svg)](https://codeclimate.com/github/PagerDuty/lita-metrics)
8
+ [![Gemnasium](https://img.shields.io/gemnasium/PagerDuty/lita-metrics.svg)](https://gemnasium.com/PagerDuty/lita-metrics)
5
9
 
6
10
  **lita-metrics** is a handler for [Lita](https://github.com/jimmycuadra/lita) that keeps track of Lita usage metrics (e.g. users, rooms, handlers and methods triggered) using [Datadog](http://www.datadoghq.com/). It also logs messages that match valid chat routes, as well as attempted commands that failed to trigger any handlers.
7
11
 
@@ -29,6 +33,7 @@ gem "lita-metrics"
29
33
  * `:command` - A boolean indicating whether the message was a command
30
34
  * `:handler` - The name of the handler invoked. Not available for invalid commands
31
35
  * `:method` - The name of the handler method invoked. Not available for invalid commands
36
+ * `ignored_methods` - An array of methods that should be ignored. Useful for handler methods that "overhear" messages not necessarily directed at the bot. Default: `[]`
32
37
 
33
38
  ``` ruby
34
39
  Lita.configure do |config|
@@ -39,6 +44,7 @@ Lita.configure do |config|
39
44
  config.handlers.metrics.valid_command_metric = 'lita.messages.all'
40
45
  config.handlers.metrics.invalid_command_metric = 'lita.messages.failed'
41
46
  config.handlers.metrics.log_fields = [:user, :handler, :message]
47
+ config.handlers.metrics.ignored_methods = ['Jira#ambient']
42
48
  end
43
49
  ```
44
50
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
5
7
 
6
- task default: :spec
8
+ task default: [:spec, :rubocop]
@@ -12,5 +12,5 @@ require 'lita/handlers/metrics'
12
12
 
13
13
  Lita::Handlers::Metrics.template_root File.expand_path(
14
14
  File.join('..', '..', 'templates'),
15
- __FILE__
15
+ __FILE__
16
16
  )
@@ -14,6 +14,7 @@ module Lita
14
14
  config :valid_command_metric, type: String, default: 'lita.commands.valid'
15
15
  config :invalid_command_metric, type: String, default: 'lita.commands.invalid'
16
16
  config :log_fields, default: [:user, :room, :message]
17
+ config :ignored_methods, type: Array, default: []
17
18
 
18
19
  on :loaded, :setup
19
20
  on :message_dispatched, :valid_command
@@ -28,9 +29,11 @@ module Lita
28
29
  def valid_command(payload)
29
30
  fields = extract_fields(payload)
30
31
 
32
+ return if ignore?(fields)
33
+
31
34
  self.class.statsd.increment(
32
35
  config.valid_command_metric,
33
- tags: fields.each.select { |k, v| k != :message }.map { |k, v| "#{k}:#{v}" }
36
+ tags: fields.each.select { |k, _v| k != :message }.map { |k, v| "#{k}:#{v}" }
34
37
  )
35
38
 
36
39
  self.class.valid_command_log.info(format_log(fields)) unless fields[:private_message]
@@ -43,7 +46,7 @@ module Lita
43
46
 
44
47
  self.class.statsd.increment(
45
48
  config.invalid_command_metric,
46
- tags: fields.each.select { |k, v| k != :message }.map { |k, v| "#{k}:#{v}" }
49
+ tags: fields.each.select { |k, _v| k != :message }.map { |k, v| "#{k}:#{v}" }
47
50
  )
48
51
 
49
52
  self.class.invalid_command_log.info(format_log(fields)) unless fields[:private_message]
@@ -55,6 +58,8 @@ module Lita
55
58
  arg.is_a?(Array) ? arg : [arg]
56
59
  end
57
60
 
61
+ # rubocop:disable Metrics/MethodLength
62
+ # Note: This could be refactored into smaller functions at some point
58
63
  def extract_fields(payload)
59
64
  m = payload[:message]
60
65
 
@@ -77,10 +82,22 @@ module Lita
77
82
 
78
83
  fields
79
84
  end
85
+ # rubocop:enable Metrics/MethodLength
80
86
 
81
87
  def format_log(fields)
82
88
  CSV.generate_line(arrayize(config.log_fields).each.map { |x| fields[x] }).chomp
83
89
  end
90
+
91
+ def ignore?(fields)
92
+ config.ignored_methods.map { |string| string.split('#') }.each do |handler, method|
93
+ return true if same?(fields[:handler], "Lita::Handlers::#{handler}") && same?(fields[:method], method)
94
+ end
95
+ false
96
+ end
97
+
98
+ def same?(a, b)
99
+ a.to_s.downcase == b.to_s.downcase
100
+ end
84
101
  end
85
102
 
86
103
  Lita.register_handler(Metrics)
@@ -1,27 +1,28 @@
1
1
  Gem::Specification.new do |spec|
2
- spec.name = "lita-metrics"
3
- spec.version = "0.1.0"
4
- spec.authors = ["Tristan Chong"]
5
- spec.email = ["tristan@pagerduty.com"]
6
- spec.description = "A Lita handler that tracks Lita usage metrics."
7
- spec.summary = "A Lita handler that tracks Lita usage metrics."
8
- spec.homepage = "https://github.com/PagerDuty/lita-metrics"
9
- spec.license = "MIT"
10
- spec.metadata = { "lita_plugin_type" => "handler" }
2
+ spec.name = 'lita-metrics'
3
+ spec.version = '0.1.1'
4
+ spec.authors = ['Tristan Chong']
5
+ spec.email = ['tristan@pagerduty.com']
6
+ spec.description = 'A Lita handler that tracks Lita usage metrics.'
7
+ spec.summary = spec.description
8
+ spec.homepage = 'https://github.com/PagerDuty/lita-metrics'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
11
 
12
- spec.files = `git ls-files`.split($/)
12
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
13
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
- spec.require_paths = ["lib"]
15
+ spec.require_paths = ['lib']
16
16
 
17
- spec.add_runtime_dependency "lita", ">= 4.5"
18
- spec.add_runtime_dependency "dogstatsd-ruby", "~> 1.5.0"
17
+ spec.add_runtime_dependency 'lita', '>= 4.6'
18
+ spec.add_runtime_dependency 'dogstatsd-ruby', '~> 1.5.0'
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.3"
21
- spec.add_development_dependency "pry-byebug"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rack-test"
24
- spec.add_development_dependency "rspec", ">= 3.0.0"
25
- spec.add_development_dependency "simplecov"
26
- spec.add_development_dependency "coveralls"
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'pry-byebug'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rack-test'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'simplecov'
26
+ spec.add_development_dependency 'coveralls'
27
+ spec.add_development_dependency 'rubocop'
27
28
  end
@@ -11,30 +11,27 @@ describe Lita::Handlers::Metrics, lita_handler: true do
11
11
 
12
12
  route(/message/, :test_message)
13
13
  route(/command/, :test_command, command: true)
14
+ route(/ignore/, :test_ignore)
14
15
 
15
- def test_message(response)
16
- response.reply('message')
16
+ def test_message(_response)
17
17
  end
18
18
 
19
- def test_command(response)
20
- response.reply('command')
19
+ def test_command(_response)
21
20
  end
22
21
 
23
- route(/block/) do |response|
24
- response.reply('block')
22
+ def test_ignore(_response)
23
+ end
24
+
25
+ route(/block/) do |_response|
25
26
  end
26
27
  end
27
28
  end
28
29
 
29
- let(:john) do
30
- Lita::User.create('U1234ABCD', name: 'John', mention_name: 'john')
31
- end
30
+ let(:john) { Lita::User.create('U1234ABCD', name: 'John', mention_name: 'john') }
32
31
 
33
- let(:general) do
34
- Lita::Room.create_or_update('C1234567890', name: 'general')
35
- end
32
+ let(:general) { Lita::Room.create_or_update('C1234567890', name: 'general') }
36
33
 
37
- before do
34
+ before(:each) do
38
35
  robot.trigger(:loaded)
39
36
  registry.register_handler(test_handler)
40
37
  end
@@ -82,6 +79,12 @@ describe Lita::Handlers::Metrics, lita_handler: true do
82
79
  )
83
80
  send_command('command', as: john, from: general)
84
81
  end
82
+
83
+ it 'ignores methods specified in the configuration' do
84
+ registry.config.handlers.metrics.ignored_methods = %w(Test#test_ignore)
85
+ expect(described_class.statsd).not_to receive(:increment)
86
+ send_message('ignore')
87
+ end
85
88
  end
86
89
 
87
90
  describe 'logger' do
@@ -1,14 +1,12 @@
1
- require "simplecov"
2
- require "coveralls"
3
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ SimpleCov.formatters = [
4
4
  SimpleCov::Formatter::HTMLFormatter,
5
5
  Coveralls::SimpleCov::Formatter
6
6
  ]
7
- SimpleCov.start { add_filter "/spec/" }
7
+ SimpleCov.start { add_filter '/spec/' }
8
8
 
9
- require "lita-metrics"
10
- require "lita/rspec"
9
+ require 'lita-metrics'
10
+ require 'lita/rspec'
11
11
 
12
- # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
- # was generated with Lita 4, the compatibility mode should be left disabled.
14
12
  Lita.version_3_compatibility_mode = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Chong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-25 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.5'
19
+ version: '4.6'
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: '4.5'
26
+ version: '4.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dogstatsd-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
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: '1.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 3.0.0
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 3.0.0
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: A Lita handler that tracks Lita usage metrics.
140
154
  email:
141
155
  - tristan@pagerduty.com
@@ -145,6 +159,7 @@ extra_rdoc_files: []
145
159
  files:
146
160
  - ".coveralls.yml"
147
161
  - ".gitignore"
162
+ - ".rubocop.yml"
148
163
  - ".travis.yml"
149
164
  - Gemfile
150
165
  - LICENSE