statsd_test_harness 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c3392016a57b7f0f12fea1613979dc2fccda5ff
4
+ data.tar.gz: 645e94680fadf32fb0c041ad949c51f2058610d1
5
+ SHA512:
6
+ metadata.gz: 47288d2658834bdfe3d556015867e20ae1fab16ec9e8de79b2a141cd0726129341aa5abfc9f9efb4a6a26a9efdc6a4e984dd87df4a1d2072dff19273de19aad5
7
+ data.tar.gz: fb71cce422a069f7ff6a6e490b33ba965bd292b8a1d046f9657fc54996533379f618f54eb51bd8725583133ab3161ca69fc7464903eeb1e9d6892a867c54b715
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statsd_test_harness.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Instructure Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # StatsdTestHarness
2
+
3
+ A test harness that captures output of various testing frameworks to post to statsd.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'statsd_test_harness'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install statsd_test_harness
20
+
21
+ ## Configuration
22
+
23
+ Set the following environment variables for statsd integration:
24
+
25
+ STATSD_HOST=192.168.42.10
26
+ STATSD_PORT=2003
27
+ APP_NAME=my_app_name
28
+
29
+ ## Usage
30
+
31
+ Run at command line:
32
+
33
+ wrap run_suite
34
+
35
+ If you don't have a configuration in config/statsd_test_harness.rb, you can specify a config file at runtime:
36
+
37
+ wrap run_suite --config path/to/config/file.rb
38
+
39
+ ## Development
40
+
41
+ To add support for a new test suite, create a file in statsd_test_harness/postprocessors that will match the duration output
42
+ by the testing framework. Follow rspec.rb for an example.
43
+
44
+ To register the postprocessor, add it to the `config.tools` array the config file, e.g.
45
+
46
+ {
47
+ name: 'my_framework',
48
+ command: 'test',
49
+ label: 'my_framework',
50
+ options: '',
51
+ ignore_return_value: true,
52
+ postprocessor: StatsdTestHarness::Postprocessors::MyPostProcessor
53
+ }
54
+
55
+ Set the `ignore_return_value` flag to false if you don't want to report an unsuccessful test run (based on exit status).
56
+
57
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/statsd_test_harness/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "statsd_test_harness"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/wrap ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'statsd_test_harness/cli'
3
+ require 'dotenv'
4
+ Dotenv.load
5
+ require_relative '../config/config'
6
+
7
+ StatsdTestHarness::CLI.start
data/config/config.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ StatsdTestHarness.configure do |config|
5
+ config.statsd_host = ENV['STATSD_HOST']
6
+ config.statsd_port = ENV['STATSD_PORT']
7
+ config.app_name = ENV['APP_NAME']
8
+
9
+ config.tools = [
10
+ {
11
+ name: 'rspec',
12
+ command: 'rspec',
13
+ label: 'rspec',
14
+ options: '',
15
+ ignore_return_value: true,
16
+ postprocessor: StatsdTestHarness::Postprocessors::RSpec
17
+ }
18
+ ]
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ require "require_all"
2
+
3
+ require_all "lib/statsd_test_harness"
4
+
5
+ module StatsdTestHarness
6
+
7
+ def self.new(path_to_config)
8
+ StatsdTestHarness::Processor.new(path_to_config)
9
+ end
10
+
11
+ class << self
12
+ attr_accessor :config
13
+ end
14
+
15
+ def self.configure(&block)
16
+ @config = Configuration.new
17
+ yield(config)
18
+ end
19
+
20
+ def self.config
21
+ @config || Configuration.new
22
+ end
23
+
24
+ class Configuration
25
+ attr_accessor :tools, :statsd_host, :statsd_port, :app_name
26
+ end
27
+
28
+ end
@@ -0,0 +1,17 @@
1
+ require "thor"
2
+ require "statsd_test_harness"
3
+
4
+ module StatsdTestHarness
5
+
6
+ class CLI < Thor
7
+
8
+ desc "wrap run_suite [--config PATH_TO_CONFIG]", ""
9
+ method_option :config, type: :string, default: '', aliases: "-c"
10
+
11
+ def run_suite
12
+ StatsdTestHarness.new(options['config']).run
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
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
+ /Finished in ([0-9\.]+) seconds/.match(self.output)[1]
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ module StatsdTestHarness
2
+
3
+ class Processor
4
+
5
+ require 'graphite-api'
6
+
7
+ attr_reader :path_to_config
8
+
9
+ def initialize(path_to_config=nil)
10
+ @path_to_config = path_to_config
11
+ end
12
+
13
+ def run
14
+ load_external_config
15
+ StatsdTestHarness.config.tools.each do |tool_harness|
16
+ tool = Tool.new(tool_harness)
17
+ puts "Executing #{tool.label} test suite..."
18
+ if data = tool.run
19
+ post_to_statsd(data, tool.label)
20
+ end
21
+ puts "Test suite run complete."
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def load_external_config
28
+ return if self.path_to_config.empty?
29
+ begin
30
+ load self.path_to_config
31
+ rescue Exception => e
32
+ puts "-- Unable to read custom config file: #{e}"
33
+ end
34
+ end
35
+
36
+ def post_to_statsd(data, label)
37
+ puts "Sending test data from #{label} suite for app #{StatsdTestHarness.config.app_name}..."
38
+ GraphiteAPI.new(graphite: endpoint).metrics(
39
+ {"stats.timers.#{StatsdTestHarness.config.app_name}.#{label}.duration" => data.duration},
40
+ Time.now
41
+ )
42
+ end
43
+
44
+ def endpoint
45
+ "http://#{StatsdTestHarness.config.statsd_host}:#{StatsdTestHarness.config.statsd_port}"
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,28 @@
1
+ module StatsdTestHarness
2
+
3
+ class Tool
4
+
5
+ attr_reader :name, :label, :command, :options, :ignore_return_value, :postprocessor
6
+
7
+ def initialize(attrs={})
8
+ @name = attrs[:name]
9
+ @command = attrs[:command]
10
+ @options = attrs[:options]
11
+ @label = attrs[:label]
12
+ @postprocessor = attrs[:postprocessor]
13
+ @ignore_return_value = attrs[:ignore_return_value]
14
+ end
15
+
16
+ def run
17
+ output = `#{self.command} #{self.options}`
18
+ puts output
19
+ data = self.postprocessor.new(output)
20
+ if $?.to_i > 0 && ! ignore_return_value
21
+ raise "Test run returned non-zero status, results not submitted."
22
+ end
23
+ data
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module StatsdTestHarness
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statsd_test_harness/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statsd_test_harness"
8
+ spec.version = StatsdTestHarness::VERSION
9
+ spec.authors = ["CoralineAda"]
10
+ spec.email = ["coraline@idolhands.com"]
11
+
12
+ spec.summary = %q{Test harness for reporting to statsd.}
13
+ spec.description = %q{Captures output of various testing frameworks to post to statsd.}
14
+ spec.homepage = "https://github.com/CoralineAda/statsd_test_harness"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor", "~> 0.19"
22
+ spec.add_dependency "require_all", "~> 1.3"
23
+ spec.add_dependency "graphite-api", "~> 0.1"
24
+ spec.add_dependency "dotenv", "~> 2.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.9"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.3"
29
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsd_test_harness
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CoralineAda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: require_all
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: graphite-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ description: Captures output of various testing frameworks to post to statsd.
112
+ email:
113
+ - coraline@idolhands.com
114
+ executables:
115
+ - console
116
+ - setup
117
+ - wrap
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - bin/wrap
130
+ - config/config.rb
131
+ - lib/statsd_test_harness.rb
132
+ - lib/statsd_test_harness/cli.rb
133
+ - lib/statsd_test_harness/postprocessors/rspec.rb
134
+ - lib/statsd_test_harness/processor.rb
135
+ - lib/statsd_test_harness/test_data.rb
136
+ - lib/statsd_test_harness/tool.rb
137
+ - lib/statsd_test_harness/version.rb
138
+ - statsd_test_harness.gemspec
139
+ homepage: https://github.com/CoralineAda/statsd_test_harness
140
+ licenses: []
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.6
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Test harness for reporting to statsd.
162
+ test_files: []
163
+ has_rdoc: