hastur 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ # For now, just don't start a background thread.
2
+ # Eventually we'll want a real EventMachine implementation.
3
+
4
+ require "hastur/api"
5
+ Hastur.register_process Hastur.app_name, {}
6
+ Hastur.no_background_thread!
@@ -0,0 +1,20 @@
1
+ require "rubygems"
2
+
3
+ # Gems on load path
4
+ # http://stackoverflow.com/questions/2747990
5
+ gem_versions = Gem.loaded_specs.values.map { |x| [ x.name, x.version] }
6
+ loaded_gems = {}
7
+ gem_versions.each do |name, version|
8
+ loaded_gems[name] = version
9
+ end
10
+
11
+ Hastur.info_process "loaded_gems", loaded_gems
12
+
13
+ # http://stackoverflow.com/questions/7190015
14
+ loaded_features = $LOADED_FEATURES.
15
+ select { |feature| feature.include? 'gems' }.
16
+ map { |feature| File.dirname(feature) }.
17
+ map { |feature| feature.split("/").last }.
18
+ uniq.sort
19
+
20
+ Hastur.info_process "loaded_features", loaded_features
@@ -0,0 +1,3 @@
1
+ module Hastur
2
+ VERSION = "1.2.8"
3
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ require "mocha"
4
+ require "hastur"
5
+
6
+ class HasturAppNameTest < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ ENV.delete('HASTUR_APP_NAME')
10
+ Object.class_eval do
11
+ remove_const('HASTUR_APP_NAME') rescue nil
12
+ remove_const('Ecology') rescue nil
13
+ end
14
+
15
+ $0 = "fake_app"
16
+
17
+ Hastur.reset
18
+ end
19
+
20
+ def teardown
21
+ end
22
+
23
+ def test_app_name_env
24
+ ENV['HASTUR_APP_NAME'] = "foo"
25
+
26
+ assert_equal "foo", Hastur.app_name
27
+ end
28
+
29
+ def test_app_name_constant
30
+ Object.class_eval { const_set('HASTUR_APP_NAME', 'warble') }
31
+
32
+ assert_equal "warble", Hastur.app_name
33
+ end
34
+
35
+ def test_app_name_ecology
36
+ eco = mock("Ecology")
37
+ Object.class_eval { const_set("Ecology", eco) }
38
+ eco.expects(:application).returns("mordecai")
39
+
40
+ assert_equal "mordecai", Hastur.app_name
41
+ end
42
+
43
+ def test_app_name_first_arg
44
+ $0 = "bobolicious"
45
+
46
+ assert_equal "bobolicious", Hastur.app_name
47
+ end
48
+
49
+ end
@@ -0,0 +1,225 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ require "mocha"
4
+ require "hastur"
5
+ require "multi_json"
6
+
7
+ # This is a hack to allow sorting symbols below in Ruby 1.8.
8
+ # Ruby 1.9 actually already has this.
9
+ class Symbol
10
+ define_method("<=>") do |obj|
11
+ self.to_s <=> obj.to_s
12
+ end
13
+ end
14
+
15
+ class HasturApiTest < MiniTest::Unit::TestCase
16
+
17
+ def setup
18
+ @test_messages = []
19
+ Hastur.deliver_with { |msg|
20
+ @test_messages << msg
21
+ }
22
+ end
23
+
24
+ def test_messages
25
+ @test_messages
26
+ end
27
+
28
+ def teardown
29
+ end
30
+
31
+ def test_timestamp_nil
32
+ ts = Hastur.timestamp(nil)
33
+ ts2 = Hastur.timestamp(Time.now)
34
+
35
+ assert ts2 - ts < 1_000_000, "nil should work as a timestamp!"
36
+ end
37
+
38
+ def test_timestamp_now
39
+ ts = Hastur.timestamp(:now)
40
+ ts2 = Hastur.timestamp(Time.now)
41
+
42
+ assert ts2 - ts < 1_000_000, ":now should work as a timestamp!"
43
+ end
44
+
45
+ def test_counter
46
+ curr_time = Time.now.to_i
47
+ Hastur.counter("name", 1, curr_time)
48
+ msgs = test_messages
49
+ hash = msgs[-1]
50
+ assert_equal("counter", hash[:type].to_s)
51
+ assert_equal("name", hash[:name])
52
+ assert_equal(curr_time*1000000, hash[:timestamp])
53
+ assert_equal(1, hash[:value])
54
+ assert_equal("counter", hash[:type].to_s)
55
+ assert hash[:labels].keys.sort == [:app, :pid, :tid],
56
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
57
+ end
58
+
59
+ def test_gauge
60
+ curr_time = Time.now.to_i
61
+ Hastur.gauge("name", 9, curr_time)
62
+ msgs = test_messages
63
+ hash = msgs[-1]
64
+ assert_equal("gauge", hash[:type].to_s)
65
+ assert_equal("name", hash[:name])
66
+ assert_equal(curr_time * 1000000, hash[:timestamp])
67
+ assert_equal(9, hash[:value])
68
+ assert_equal("gauge", hash[:type].to_s)
69
+ assert hash[:labels].keys.sort == [:app, :pid, :tid],
70
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
71
+ end
72
+
73
+ def test_mark
74
+ curr_time = Time.now.to_i
75
+ Hastur.mark("myName", nil, curr_time)
76
+ msgs = test_messages
77
+ hash = msgs[-1]
78
+ assert_equal("mark", hash[:type].to_s)
79
+ assert_equal("myName", hash[:name])
80
+ assert_equal(curr_time*1000000, hash[:timestamp])
81
+ assert hash[:labels].keys.sort == [:app, :pid, :tid],
82
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
83
+ end
84
+
85
+ def test_compound
86
+ curr_time = Time.now.to_i
87
+ # compound is currently protected as it is not for public consumption
88
+ Hastur.send :compound, "myName", [1, 2, 3], curr_time
89
+ msgs = test_messages
90
+ hash = msgs[-1]
91
+ assert_equal("compound", hash[:type].to_s)
92
+ assert_equal("myName", hash[:name])
93
+ assert_equal(curr_time*1000000, hash[:timestamp])
94
+ assert_equal([1, 2, 3], hash[:value])
95
+ end
96
+
97
+ def test_heartbeat
98
+ Hastur.heartbeat(nil, nil, nil, :now, :app => "myApp")
99
+ msgs = test_messages
100
+ hash = msgs[-1]
101
+ assert_equal("myApp", hash[:labels][:app])
102
+ assert_equal("hb_process", hash[:type].to_s)
103
+ assert hash[:labels].keys.sort == [:app, :pid, :tid],
104
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
105
+ end
106
+
107
+ def test_process_heartbeat
108
+ Hastur.kill_background_thread
109
+ Hastur.start_background_thread
110
+
111
+ # Make the "every" background thread think it's later than it is
112
+ tn = Time.now
113
+ Time.stubs(:now).returns(tn + 65)
114
+ sleep 2 # Then sleep long enough that it woke up and ran
115
+
116
+ msgs = test_messages
117
+ hash = msgs[-1]
118
+ assert hash != nil, "Hash cannot be nil"
119
+ assert_equal("hb_process", hash[:type].to_s)
120
+ assert_equal("process_heartbeat", hash[:name].to_s)
121
+ assert hash[:labels].keys.sort == [:app, :pid, :tid],
122
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
123
+ end
124
+
125
+ def test_event
126
+ event_name = "bad.log.line"
127
+ subject = "Got a bad log line: '@@@@@@@@@'"
128
+ body = "a\nb\nc\nd\ne\nf"
129
+ attn = [ "backlot", "helios", "analytics-helios-api" ]
130
+ Hastur.event(event_name, subject, body, attn, :now, {:foo => "foo", :bar => "bar"})
131
+ msgs = test_messages
132
+ hash = msgs[-1]
133
+ assert_equal("event", hash[:type].to_s)
134
+ assert_equal(event_name, hash[:name])
135
+ assert_equal(subject, hash[:subject])
136
+ assert_equal(attn, hash[:attn])
137
+ assert hash[:labels].keys.sort == [:app, :bar, :foo, :pid, :tid],
138
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
139
+ end
140
+
141
+ def test_log
142
+ subject = "Got a bad\nlog line: '@@\n@@@@@\n@@'"
143
+ Hastur.log(subject, {:data => "data", :beta => "beta"}, :now, {:foo => "foo", :bar => "bar"})
144
+ msgs = test_messages
145
+ hash = msgs[-1]
146
+ assert_equal("log", hash[:type].to_s)
147
+ assert_equal(subject, hash[:subject])
148
+ assert hash[:labels].keys.sort == [:app, :bar, :foo, :pid, :tid],
149
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
150
+ assert hash[:data].keys.sort == [:beta, :data],
151
+ "Wrong keys #{hash[:data].keys.inspect} in data!"
152
+ end
153
+
154
+ def test_long_log
155
+ subject = "Got a bad\nlog line: '@@\n@@@@@\n@@'" + "*" * 20_000
156
+ Hastur.log(subject, {:data => "data", :beta => "beta"}, :now, {:foo => "foo", :bar => "bar"})
157
+ msgs = test_messages
158
+ hash = msgs[-1]
159
+ assert_equal("log", hash[:type].to_s)
160
+ assert_equal(subject[0...7_168], hash[:subject])
161
+ assert hash[:labels].keys.sort == [:app, :bar, :foo, :pid, :tid],
162
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
163
+ assert hash[:data].keys.sort == [:beta, :data],
164
+ "Wrong keys #{hash[:data].keys.inspect} in data!"
165
+ end
166
+
167
+ def test_register_plugin
168
+ plugin_path = "plugin_path"
169
+ plugin_args = "plugin_args"
170
+ plugin_name = "plugin_name"
171
+ interval = :five_minutes
172
+ labels = {:foo => "foo"}
173
+ Hastur.register_plugin(plugin_name, plugin_path, plugin_args, interval, nil, labels)
174
+ msgs = test_messages
175
+ hash = msgs[-1]
176
+ assert_equal("reg_pluginv1", hash[:type].to_s)
177
+ assert_equal(plugin_path, hash[:plugin_path])
178
+ assert_equal(plugin_args, hash[:plugin_args])
179
+ assert_equal(plugin_name, hash[:plugin])
180
+ assert_equal(interval, hash[:interval])
181
+ assert hash[:labels].keys.sort == [:app, :foo, :pid, :tid],
182
+ "Wrong keys #{hash[:labels].keys.inspect} in default labels!"
183
+ end
184
+
185
+ def test_time
186
+ name = "example.block.time"
187
+ Hastur.time name do Math.sqrt(100) end
188
+ msg = test_messages.pop
189
+ assert_equal name, msg[:name]
190
+ assert_kind_of Numeric, msg[:value]
191
+ assert msg[:value].between?(0.0, 1.0)
192
+ t = Time.now
193
+ Hastur.time name, t, :foo => "bar" do Math.sqrt(100) end
194
+ msg = test_messages.pop
195
+ assert msg[:labels].keys.sort == [:app, :foo, :pid, :tid]
196
+ assert_equal "bar", msg[:labels][:foo]
197
+
198
+ # make sure it's returning the return of the block
199
+ val = Hastur.time name do
200
+ 1.upto(10).map { 100 }
201
+ end
202
+ assert_kind_of Array, val
203
+ assert_equal 10, val.length
204
+ end
205
+
206
+ def test_every
207
+ Hastur.kill_background_thread
208
+ Hastur.start_background_thread
209
+
210
+ Hastur.every :minute do
211
+ Hastur.mark("test_every")
212
+ end
213
+
214
+ # Make the "every" background thread think it's later than it is
215
+ tn = Time.now
216
+ Time.stubs(:now).returns(tn + 65)
217
+ sleep 2 # Then sleep long enough that it woke up and ran
218
+
219
+ msgs = test_messages
220
+ hash = msgs[-1]
221
+ assert hash != nil, "Hash cannot be nil"
222
+ assert_equal("test_every", hash[:name])
223
+ end
224
+
225
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ class ApiInclusionTest < MiniTest::Unit::TestCase
4
+ def test_inclusion
5
+ require "hastur/api"
6
+
7
+ assert !Hastur.background_thread?, "hastur/api must not start a background thread!"
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ require "mocha"
4
+
5
+ module Hastur
6
+ end
7
+
8
+ class DefaultInclusionTest < MiniTest::Unit::TestCase
9
+ def test_inclusion
10
+ Hastur.expects(:register_process)
11
+ Hastur.expects(:start_background_thread)
12
+
13
+ require "hastur"
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ class EventMachineInclusionTest < MiniTest::Unit::TestCase
4
+ def test_inclusion
5
+ require "hastur/eventmachine"
6
+
7
+ assert !Hastur.background_thread?, "hastur/eventmachine must not start a background thread!"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # Use local Hastur version *first*
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+
4
+ if ENV['COVERAGE'] && RUBY_VERSION[/^1.9/]
5
+ require "simplecov"
6
+ SimpleCov.start
7
+ end
8
+
9
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hastur
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.8
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Viet Nguyen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: multi_json
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.2
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: chronic
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Hastur API client gem
127
+ email:
128
+ - viet@ooyala.com
129
+ executables:
130
+ - hastur
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .yardopts
136
+ - Gemfile
137
+ - README
138
+ - Rakefile
139
+ - bin/hastur
140
+ - ci_jobs/hastur-api-libs/run.sh
141
+ - examples/Gemfile
142
+ - examples/README
143
+ - examples/get_proxy.rb
144
+ - hastur.gemspec
145
+ - lib/hastur.rb
146
+ - lib/hastur/api.rb
147
+ - lib/hastur/eventmachine.rb
148
+ - lib/hastur/gems_loaded.rb
149
+ - lib/hastur/version.rb
150
+ - test/app_name_test.rb
151
+ - test/hastur_test.rb
152
+ - test/inclusion/api_test.rb
153
+ - test/inclusion/default_test.rb
154
+ - test/inclusion/eventmachine_test.rb
155
+ - test/test_helper.rb
156
+ homepage: http://www.ooyala.com
157
+ licenses: []
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project: hastur
176
+ rubygems_version: 1.8.23
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: A gem used to communicate with the Hastur Client through UDP.
180
+ test_files: []
181
+ has_rdoc: