statsd_test_harness 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb076d5a472dc9b47e680b5d800f69d0bf9d2068
4
- data.tar.gz: 01d1a1b26c113be200a12198c86e2ea4342438bc
3
+ metadata.gz: 60ab01edf847abd342b0b97ea2b6756268193e86
4
+ data.tar.gz: 0e28cca62fab3ddfd4d65f38399029fffa703c7a
5
5
  SHA512:
6
- metadata.gz: e35b0f593d8bd4b4561b5358ac326f42000109da1a64b13f39d34e1c42058f476eca62321f94f9405def9914c2f8a7381a073d5819fd4a1ad926d992276d7c8c
7
- data.tar.gz: 59cc9da579d16e4515a0872850e20e4bb74f28d0990f48629584ffea1de5128377428288c4d43449d4fb8180bfe19de8c7c84dd16751b0994bedfc6e417394f3
6
+ metadata.gz: d1ee5426339c2e6275a8614503688bc5e643882bfb279f9f1d563fabe04075c233d93a8d7b2a54e6ae3c8c58714fb5ddb987a0f377470a474de0c14d086a63b3
7
+ data.tar.gz: 99d988e3db95a437f61a0e1df1919e32c68b3bf17e88a957fa7ea29c5056a1334e6e9a6d7df77a28d3fceacd019530753b4d0a8477d52909a1d432e2c1812691
data/.gitignore CHANGED
@@ -1,9 +1,2 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ pkg/*
2
+ .console_history
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ statsd_test_harness (0.2.1)
5
+ dotenv (~> 2.0)
6
+ require_all (~> 1.3)
7
+ statsd-ruby (~> 0.3.0)
8
+ thor (~> 0.19)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ diff-lcs (1.2.5)
14
+ dotenv (2.0.2)
15
+ rake (10.4.2)
16
+ require_all (1.3.2)
17
+ rspec (3.3.0)
18
+ rspec-core (~> 3.3.0)
19
+ rspec-expectations (~> 3.3.0)
20
+ rspec-mocks (~> 3.3.0)
21
+ rspec-core (3.3.2)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-expectations (3.3.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-mocks (3.3.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-support (3.3.0)
30
+ statsd-ruby (0.3.0)
31
+ thor (0.19.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.9)
38
+ rake (~> 10.0)
39
+ rspec (~> 3.3)
40
+ statsd_test_harness!
data/README.md CHANGED
@@ -22,35 +22,24 @@ Or install it yourself as:
22
22
 
23
23
  Set the following environment variables for statsd integration:
24
24
 
25
- STATSD_HOST=192.168.42.10
26
- STATSD_PORT=2003
27
- STATSD_APP_NAME=my_app_name
25
+ export STATSD_HOST=192.168.42.10
26
+ export STATSD_PORT=8125
27
+ export STATSD_NAMESPACE=statsd_test_harness
28
+ export STATSD_APP_NAME=my_app_name
28
29
 
29
30
  ## Usage
30
31
 
32
+ To start a graphite/statsd docker file:
33
+
34
+ docker run -d --name graphite --restart=always -p 80:80 -p 2003:2003 -p 8125:8125/udp hopsoft/graphite-statsd -e VIRTUAL_HOST=graphite.docker
35
+
31
36
  You must specify a config file at runtime:
32
37
 
33
38
  wrap run_suite --config path/to/config/file.rb
34
39
 
35
40
  For an example of what the config file should look like, refer to config/sample_config.rb
36
41
 
37
- ## Development
38
-
39
- To add support for a new test suite, create a file in statsd_test_harness/postprocessors/ that will extract the duration output
40
- from the testing framework. Follow statsd_test_harness/postprocessors/rspec.rb for an example.
41
-
42
- To register the postprocessor, add it to the `config.tools` array in your config file, e.g.
43
-
44
- {
45
- name: 'my_framework',
46
- command: 'test',
47
- label: 'my_framework',
48
- options: '',
49
- ignore_return_value: true,
50
- postprocessor: StatsdTestHarness::Postprocessors::MyPostProcessor
51
- }
52
-
53
- Set the `ignore_return_value` flag to false if you don't want to report an unsuccessful test run (based on exit status).
42
+ In your config file, set the `ignore_return_value` flag to false if you don't want to report an unsuccessful test run (based on exit status).
54
43
 
55
44
  ## Contributing
56
45
 
@@ -0,0 +1,20 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ StatsdTestHarness.configure do |config|
5
+ config.host = ENV['STATSD_HOST']
6
+ config.port = ENV['STATSD_PORT']
7
+ config.app_name = ENV['STATSD_APP_NAME']
8
+ config.namespace = ENV['STATSD_NAMESPACE']
9
+
10
+ config.tools = [
11
+ {
12
+ name: 'rspec',
13
+ command: 'rspec',
14
+ label: 'rspec',
15
+ options: 'spec/models/conversation_spec.rb',
16
+ ignore_return_value: false
17
+ }
18
+ ]
19
+
20
+ end
@@ -1,19 +1,18 @@
1
1
  require 'dotenv'
2
2
  Dotenv.load
3
3
 
4
- StatsdTestHarness.configure do |config|
5
- config.statsd_host = ENV['STATSD_HOST']
6
- config.statsd_port = ENV['STATSD_PORT']
7
- config.statsd_app_name = ENV['STATSD_APP_NAME']
4
+ StatsdTess.configure do |config|
5
+ config.host = ENV['STATSD_HOST']
6
+ config.port = ENV['STATSD_PORT']
7
+ config.app_name = ENV['STATSD_APP_NAME']
8
+ config.namespace = ENV['STATSD_NAMESPACE']
8
9
 
9
10
  config.tools = [
10
11
  {
11
12
  name: 'rspec',
12
13
  command: 'rspec',
13
- label: 'rspec',
14
14
  options: '',
15
- ignore_return_value: true,
16
- postprocessor: StatsdTestHarness::Postprocessors::RSpec
15
+ ignore_return_value: true
17
16
  }
18
17
  ]
19
18
 
@@ -2,16 +2,13 @@ require "thor"
2
2
  require "statsd_test_harness"
3
3
 
4
4
  module StatsdTestHarness
5
-
6
5
  class CLI < Thor
7
6
 
8
7
  desc "wrap run_suite --config PATH_TO_CONFIG", ""
9
8
  method_option :config, type: :string, default: '', aliases: "-c"
10
-
11
9
  def run_suite
12
10
  StatsdTestHarness.new(options['config']).run
13
11
  end
14
12
 
15
13
  end
16
-
17
14
  end
@@ -0,0 +1,19 @@
1
+ module StatsdTestHarness
2
+ class Client
3
+
4
+ def post(duration, label)
5
+ puts "Sending test data from #{label} suite for app #{StatsdTestHarness.config.app_name}..."
6
+ client.timing(
7
+ "#{StatsdTestHarness.config.namespace}.#{StatsdTestHarness.config.app_name}.#{label}.duration",
8
+ duration
9
+ )
10
+ end
11
+
12
+ private
13
+
14
+ def client
15
+ Statsd.new(StatsdTestHarness.config.host, StatsdTestHarness.config.port)
16
+ end
17
+
18
+ end
19
+ end
@@ -1,64 +1,56 @@
1
1
  module StatsdTestHarness
2
-
3
2
  class Processor
4
3
 
5
- require 'graphite-api'
4
+ require 'statsd'
6
5
 
7
6
  attr_reader :path_to_config
8
7
 
9
8
  def initialize(path_to_config)
10
9
  @path_to_config = path_to_config
10
+ load_config
11
11
  end
12
12
 
13
13
  def run
14
- load_external_config
15
14
  StatsdTestHarness.config.tools.each do |tool_harness|
16
15
  tool = Tool.new(tool_harness)
17
- puts "Executing #{tool.label} test suite..."
18
- if data = tool.run
19
- post_to_statsd(data, tool.label)
16
+ puts "Executing #{tool.label} test suite for #{StatsdTestHarness.config.app_name}..."
17
+ if duration = with_timing{tool.run}
18
+ StatsdTestHarness::Client.new.post(duration, tool.name)
19
+ puts "Test suite for #{tool.label} completed in #{duration} ms."
20
20
  end
21
- puts "Test suite run complete."
22
21
  end
23
22
  end
24
23
 
25
24
  private
26
25
 
27
- def load_external_config
26
+ def load_config
28
27
  begin
29
- load self.path_to_config
30
28
  validate_path_to_config
29
+ load self.path_to_config
31
30
  validate_env_variables
32
31
  rescue Exception => e
33
- puts "-- Unable to read config file: #{e}"
32
+ puts "-- Invalid configuration, exiting: #{e}"
33
+ exit
34
34
  end
35
35
  end
36
36
 
37
- def post_to_statsd(data, label)
38
- puts "Sending test data from #{label} suite for app #{StatsdTestHarness.config.statsd_app_name}..."
39
- GraphiteAPI.new(graphite: endpoint).metrics(
40
- {"stats.timers.#{StatsdTestHarness.config.statsd_app_name}.#{label}.duration" => data.duration},
41
- Time.now
42
- )
43
- end
44
-
45
- def endpoint
46
- "http://#{StatsdTestHarness.config.statsd_host}:#{StatsdTestHarness.config.statsd_port}"
37
+ def validate_env_variables
38
+ unless StatsdTestHarness.config.host && StatsdTestHarness.config.port
39
+ raise "No statsd environment variables defined."
40
+ end
47
41
  end
48
42
 
49
43
  def validate_path_to_config
50
44
  if self.path_to_config.empty?
51
- puts "No config file specified, exiting"
52
- exit
45
+ raise "No config file specified."
53
46
  end
54
47
  end
55
48
 
56
- def validate_env_variables
57
- unless StatsdTestHarness.config.statsd_host && StatsdTestHarness.config.statsd_port
58
- puts "No statsd environment variables defined, exiting"
59
- exit
60
- end
49
+ def with_timing
50
+ start_time = Time.now.to_f
51
+ yield
52
+ (Time.now.to_f - start_time) * 1000
61
53
  end
62
- end
63
54
 
55
+ end
64
56
  end
@@ -1,28 +1,24 @@
1
1
  module StatsdTestHarness
2
-
3
2
  class Tool
4
3
 
5
- attr_reader :name, :label, :command, :options, :ignore_return_value, :postprocessor
4
+ attr_reader :name, :command, :options, :label, :ignore_return_value
6
5
 
7
6
  def initialize(attrs={})
8
- @name = attrs[:name]
9
- @command = attrs[:command]
10
- @options = attrs[:options]
11
- @label = attrs[:label]
12
- @postprocessor = attrs[:postprocessor]
7
+ @name = attrs[:name]
8
+ @command = attrs[:command]
9
+ @options = attrs[:options]
10
+ @label = attrs[:label]
13
11
  @ignore_return_value = attrs[:ignore_return_value]
14
12
  end
15
13
 
16
14
  def run
17
15
  output = `#{self.command} #{self.options}`
18
16
  puts output
19
- data = self.postprocessor.new(output)
20
17
  if $?.to_i > 0 && ! ignore_return_value
21
18
  raise "Test run returned non-zero status, results not submitted."
22
19
  end
23
- data
20
+ true
24
21
  end
25
22
 
26
23
  end
27
-
28
24
  end
@@ -1,3 +1,3 @@
1
1
  module StatsdTestHarness
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -21,7 +21,7 @@ module StatsdTestHarness
21
21
  end
22
22
 
23
23
  class Configuration
24
- attr_accessor :tools, :statsd_host, :statsd_port, :statsd_app_name
24
+ attr_accessor :tools, :host, :port, :app_name, :namespace
25
25
  end
26
26
 
27
27
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "thor", "~> 0.19"
22
22
  spec.add_dependency "require_all", "~> 1.3"
23
- spec.add_dependency "graphite-api", "~> 0.1"
23
+ spec.add_dependency "statsd-ruby", "~> 0.3.0"
24
24
  spec.add_dependency "dotenv", "~> 2.0"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsd_test_harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CoralineAda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-06 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: graphite-api
42
+ name: statsd-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.1'
47
+ version: 0.3.0
48
48
  type: :runtime
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: '0.1'
54
+ version: 0.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dotenv
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -121,18 +121,19 @@ files:
121
121
  - ".gitignore"
122
122
  - CODE_OF_CONDUCT.md
123
123
  - Gemfile
124
+ - Gemfile.lock
124
125
  - LICENSE
125
126
  - README.md
126
127
  - Rakefile
127
128
  - bin/console
128
129
  - bin/setup
129
130
  - bin/wrap
131
+ - config/config_custom.rb
130
132
  - config/sample_config.rb
131
133
  - lib/statsd_test_harness.rb
132
134
  - lib/statsd_test_harness/cli.rb
133
- - lib/statsd_test_harness/postprocessors/rspec.rb
135
+ - lib/statsd_test_harness/client.rb
134
136
  - lib/statsd_test_harness/processor.rb
135
- - lib/statsd_test_harness/test_data.rb
136
137
  - lib/statsd_test_harness/tool.rb
137
138
  - lib/statsd_test_harness/version.rb
138
139
  - statsd_test_harness.gemspec
@@ -1,21 +0,0 @@
1
- module StatsdTestHarness
2
- module Postprocessors
3
- class RSpec
4
-
5
- attr_reader :output
6
-
7
- def initialize(output)
8
- @output = output
9
- end
10
-
11
- def duration
12
- duration_string = /^real(.+)/.match(self.output).to_a.last
13
- hours = /([0-9\.]+)h/.match(duration_string).to_a.last.to_f || 0
14
- minutes = /([0-9\.]+)m/.match(duration_string).to_a.last.to_f || 0
15
- seconds = /([0-9\.]+)s/.match(duration_string).to_a.last.to_f || 0
16
- (hours * 60 * 60) + (minutes * 60) + seconds
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- module StatsdTestHarness
2
-
3
- class TestData
4
-
5
- attr_reader :raw_output
6
-
7
- def self.from(output)
8
- new(output)
9
- end
10
-
11
- def initialize(raw_output)
12
- @raw_output = raw_output
13
- end
14
-
15
- # FIXME parse output for duration
16
- def duration
17
- 12
18
- end
19
-
20
- end
21
-
22
- end