fnordmetric 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +6 -0
  2. data/Gemfile.lock +21 -0
  3. data/Procfile +1 -2
  4. data/VERSION +1 -1
  5. data/_spec/app_spec.rb +178 -0
  6. data/{spec → _spec}/cache_spec.rb +0 -0
  7. data/{spec → _spec}/combine_metric_spec.rb +0 -0
  8. data/{spec → _spec}/core_spec.rb +0 -0
  9. data/{spec → _spec}/count_metric_spec.rb +0 -0
  10. data/_spec/dashboard_spec.rb +67 -0
  11. data/_spec/event_spec.rb +46 -0
  12. data/{spec → _spec}/metric_spec.rb +0 -0
  13. data/{spec → _spec}/report_spec.rb +0 -0
  14. data/{spec → _spec}/sum_metric_spec.rb +0 -0
  15. data/_spec/widget_spec.rb +107 -0
  16. data/doc/import_dump.rb +26 -0
  17. data/em_runner.rb +33 -0
  18. data/fnordmetric.gemspec +59 -20
  19. data/haml/app.haml +26 -12
  20. data/lib/fnordmetric.rb +150 -15
  21. data/lib/fnordmetric/app.rb +70 -11
  22. data/lib/fnordmetric/cache.rb +4 -4
  23. data/lib/fnordmetric/context.rb +65 -0
  24. data/lib/fnordmetric/dashboard.rb +16 -12
  25. data/lib/fnordmetric/event.rb +65 -15
  26. data/lib/fnordmetric/gauge.rb +46 -0
  27. data/lib/fnordmetric/gauge_calculations.rb +43 -0
  28. data/lib/fnordmetric/gauge_modifiers.rb +43 -0
  29. data/lib/fnordmetric/inbound_stream.rb +66 -0
  30. data/lib/fnordmetric/logger.rb +38 -0
  31. data/lib/fnordmetric/namespace.rb +120 -0
  32. data/lib/fnordmetric/numbers_widget.rb +29 -11
  33. data/lib/fnordmetric/session.rb +131 -0
  34. data/lib/fnordmetric/standalone.rb +31 -0
  35. data/lib/fnordmetric/timeline_widget.rb +29 -9
  36. data/lib/fnordmetric/widget.rb +50 -45
  37. data/lib/fnordmetric/worker.rb +80 -0
  38. data/pub/fnordmetric/fnordmetric.css +76 -9
  39. data/pub/fnordmetric/fnordmetric.js +541 -42
  40. data/pub/raphael-min.js +8 -0
  41. data/pub/raphael-utils.js +221 -0
  42. data/readme.rdoc +172 -27
  43. data/server.rb +22 -0
  44. data/spec/app_spec.rb +359 -117
  45. data/spec/context_spec.rb +42 -0
  46. data/spec/dashboard_spec.rb +7 -47
  47. data/spec/event_spec.rb +114 -33
  48. data/spec/gauge_modifiers_spec.rb +276 -0
  49. data/spec/gauge_spec.rb +128 -0
  50. data/spec/namespace_spec.rb +104 -0
  51. data/spec/session_spec.rb +231 -0
  52. data/spec/spec_helper.rb +27 -4
  53. data/spec/widget_spec.rb +81 -75
  54. data/spec/worker_spec.rb +37 -0
  55. data/test_stream.sh +187 -0
  56. data/ulm_stats.rb +198 -0
  57. metadata +114 -35
  58. data/lib/fnordmetric/core.rb +0 -66
  59. data/lib/fnordmetric/engine.rb +0 -3
data/spec/app_spec.rb CHANGED
@@ -1,178 +1,420 @@
1
1
  require ::File.expand_path('../spec_helper.rb', __FILE__)
2
2
 
3
3
  include Rack::Test::Methods
4
+ include FnordMetric
4
5
 
5
6
  describe "app" do
6
7
 
7
- before(:each) do
8
- FnordMetric::Event.destroy_all
8
+ before(:all) do
9
+ redis = Redis.new
10
+ @redis = RedisWrap.new(redis, false)
11
+ @opts = {
12
+ :redis_prefix => "fnordmetric",
13
+ :session_data_ttl => 120,
14
+ }
15
+ @now = Time.utc(1992,01,13,5,23,23).to_i
16
+ @namespace = Namespace.new(:foospace, @opts)
17
+ @redis_wrap = RedisWrap.new(@redis)
9
18
  end
10
19
 
11
20
  def app
12
- @app ||= FnordMetric::App
21
+ @app ||= FnordMetric::App.new({
22
+ :foospace => proc{
23
+ widget 'Blubb', nil
24
+ }
25
+ }, @opts)
13
26
  end
14
27
 
15
- it "should redirect to the default dashboard" do
28
+ it "should redirect to the first namespace" do
16
29
  get "/"
17
30
  last_response.status.should == 302
18
- last_response.location.should == "http://example.org/dashboard/default"
31
+ last_response.location.should == "http://example.org/foospace"
19
32
  end
20
33
 
21
- it "should render the dashboard" do
22
- FnordMetric.dashboard("Deine Mama"){|dash|}
23
- get "/dashboard/default"
24
- last_response.status.should == 200
25
- last_response.body.should include("Deine Mama")
26
- end
27
-
28
- it "should render the right dashboard" do
29
- FnordMetric.dashboard("Deine Mama"){|dash|}
30
- FnordMetric.dashboard("My Dashboard"){|dash|}
31
- get "/dashboard/DeineMama"
32
- last_response.status.should == 200
33
- last_response.body.should include("Deine Mama")
34
- get "/dashboard/MyDashboard"
34
+ it "should render the namespace" do
35
+ get "/foospace"
35
36
  last_response.status.should == 200
36
- last_response.body.should include("My Dashboard")
37
37
  end
38
38
 
39
- it "should track an event without auth" do
40
- post "/events", :type => "myevent", :fnord => "foobar"
39
+ it "should render the dashboards" do
40
+ @app ||= FnordMetric::App.new({
41
+ :foospace => proc{
42
+ widget 'Blubb', nil
43
+ }
44
+ }, @opts)
45
+ get "/foospace"
41
46
  last_response.status.should == 200
42
- FnordMetric::Event.last.type.should == "myevent"
43
- FnordMetric::Event.last.fnord.should == "foobar"
47
+ last_response.body.should include("Blubb")
44
48
  end
45
49
 
46
- it "should return 400 if no type is provided" do
47
- post "/events", :fnord => "foobar"
48
- last_response.status.should == 400
49
- last_response.body.should == "please specify the event_type"
50
- end
51
-
52
- it "should track an event in the past" do
53
- my_time = (Time.now-3.years).to_i
54
- post "/events", :type => "myevent", :time => my_time
55
- last_response.status.should == 200
56
- FnordMetric::Event.last.type.should == "myevent"
57
- FnordMetric::Event.last.time.should == my_time
50
+ it "should render the dashboards" do
51
+ @app ||= FnordMetric::App.new({
52
+ :foospace => proc{
53
+ widget 'Blubb', nil
54
+ widget 'Fnord', nil
55
+ }
56
+ }, @opts)
57
+ get "/foospace"
58
+ last_response.status.should == 200
59
+ last_response.body.should include("Blubb")
60
+ last_response.body.should include("Fnord")
58
61
  end
59
62
 
60
- it "should track an event with integer data" do
61
- post "/events", :type => "myevent", :blubb => "123"
62
- last_response.status.should == 200
63
- FnordMetric::Event.last.type.should == "myevent"
64
- FnordMetric::Event.last.blubb.should == 123
65
- end
63
+ describe "sessions api" do
66
64
 
67
- it "should track an event with float data" do
68
- post "/events", :type => "myevent", :blubb => "42.23"
69
- last_response.status.should == 200
70
- FnordMetric::Event.last.type.should == "myevent"
71
- FnordMetric::Event.last.blubb.should == 42.23
72
- end
65
+ before(:each) do
66
+ @redis.keys("fnordmetric-foospace*").each { |k| @redis.del(k) }
67
+ end
73
68
 
69
+ it "should render a list of all active sessions" do
70
+ @namespace.ready!(@redis_wrap).announce(
71
+ :_time => Time.now.to_i,
72
+ :_type => "foobar",
73
+ :_session => "sess213"
74
+ )
75
+ get "/foospace/sessions"
76
+ JSON.parse(last_response.body).should have_key("sessions")
77
+ JSON.parse(last_response.body)["sessions"].length.should == 1
78
+ end
74
79
 
75
- describe "metrics api" do
80
+ it "should render a list of all active sessions with timestamps" do
81
+ @namespace.ready!(@redis_wrap).announce(
82
+ :_time => @now-5,
83
+ :_type => "foobar",
84
+ :_session => "sess213"
85
+ )
86
+ get "/foospace/sessions"
87
+ sess = JSON.parse(last_response.body)["sessions"].first
88
+ sess["_updated_at"].should == (@now-5).to_s
89
+ end
90
+
91
+ it "should render a list of all active sessions with usernames" do
92
+ @namespace.ready!(@redis_wrap).announce(
93
+ :_time => @now,
94
+ :_type => "_set_name",
95
+ :_session => "sess213",
96
+ :name => "Hans Peter"
97
+ )
98
+ get "/foospace/sessions"
99
+ sess = JSON.parse(last_response.body)["sessions"].first
100
+ sess["_name"].should == "Hans Peter"
101
+ end
102
+
103
+ it "should render a list of all active sessions with user pictures" do
104
+ @namespace.ready!(@redis_wrap).announce(
105
+ :_time => @now,
106
+ :_type => "_set_picture",
107
+ :_session => "sess213",
108
+ :url => "http://myhost.com/mypic.jpg"
109
+ )
110
+ get "/foospace/sessions"
111
+ sess = JSON.parse(last_response.body)["sessions"].first
112
+ sess["_picture"].should == "http://myhost.com/mypic.jpg"
113
+ end
114
+
115
+ it "should render a list of all active sessions with hashed keys" do
116
+ @namespace.ready!(@redis_wrap).announce(
117
+ :_time => @now-5,
118
+ :_type => "foobar",
119
+ :_session => "sess133"
120
+ )
121
+ get "/foospace/sessions"
122
+ sess = JSON.parse(last_response.body)["sessions"].first
123
+ sess["session_key"].should == Digest::MD5.hexdigest("sess133")
124
+ end
125
+
126
+ it "should not render more than 100 sessions at once" do
127
+ 123.times do |n|
128
+ @namespace.ready!(@redis_wrap).announce(
129
+ :_time => Time.now.to_i,
130
+ :_type => "foobar",
131
+ :_session => "sess213-#{n}"
132
+ )
133
+ end
134
+ get "/foospace/sessions"
135
+ JSON.parse(last_response.body).should have_key("sessions")
136
+ JSON.parse(last_response.body)["sessions"].length.should == 100
137
+ end
138
+
139
+ it "should render sessions ordered by last_updated_at" do
140
+ context = @namespace.ready!(@redis_wrap)
141
+ context.announce(
142
+ :_time => Time.now.to_i,
143
+ :_type => "foobar",
144
+ :_session => "sessfoo"
145
+ )
146
+ context.announce(
147
+ :_time => Time.now.to_i-23,
148
+ :_type => "foobar",
149
+ :_session => "sessbar"
150
+ )
151
+ context.announce(
152
+ :_time => Time.now.to_i-5,
153
+ :_type => "foobar",
154
+ :_session => "sessfnord"
155
+ )
156
+ get "/foospace/sessions"
157
+ sessions = JSON.parse(last_response.body)["sessions"]
158
+ sessions.length.should == 3
159
+ sessions[0]["session_key"].should == Digest::MD5.hexdigest("sessfoo")
160
+ sessions[1]["session_key"].should == Digest::MD5.hexdigest("sessfnord")
161
+ sessions[2]["session_key"].should == Digest::MD5.hexdigest("sessbar")
162
+ end
163
+
164
+ end
165
+
166
+ describe "events api: rendering events" do
76
167
 
77
168
  before(:each) do
78
- FnordMetric::Event.destroy_all
79
- FnordMetric.metric('my_event_count', :count => true, :types => [:my_event_type])
80
- FnordMetric.track('my_event_type', :time => 33.hours.ago)
81
- FnordMetric.track('my_event_type', :time => 32.hours.ago)
82
- FnordMetric.track('my_event_type', :time => 29.hours.ago)
83
- FnordMetric.track('my_event_type', :time => 27.hours.ago)
84
- FnordMetric.track('my_event_type', :time => 26.hours.ago)
85
- FnordMetric.track('my_event_type', :time => 13.hours.ago)
86
- FnordMetric.track('my_event_type', :time => 12.hours.ago)
87
- FnordMetric.track('my_event_type', :time => 2.hours.ago)
88
- FnordMetric.track('my_event_type', :time => 3.hours.ago)
169
+ @redis.keys("fnordmetric-foospace*").each { |k| @redis.del(k) }
170
+ end
171
+
172
+ it "should render a list of all events" do
173
+ @namespace.ready!(@redis_wrap).announce(
174
+ :_eid => "sdkjgh9sd8f",
175
+ :_time => Time.now.to_i,
176
+ :_type => "foobar!!!"
177
+ )
178
+ get "/foospace/events"
179
+ JSON.parse(last_response.body).should have_key("events")
180
+ JSON.parse(last_response.body)["events"].length.should == 1
89
181
  end
90
182
 
91
- it "should return the right answer for: /metric/:name" do
92
- get "/metric/my_event_count"
93
- JSON.parse(last_response.body)["value"].to_i.should == 9
183
+ it "should render a list of all events including event-times" do
184
+ @namespace.ready!(@redis_wrap).announce(
185
+ :_eid => "sdkjgh9sd8f",
186
+ :_time => @now-23,
187
+ :_type => "foobar!!!"
188
+ )
189
+ get "/foospace/events"
190
+ JSON.parse(last_response.body).should have_key("events")
191
+ JSON.parse(last_response.body)["events"].length.should == 1
192
+ JSON.parse(last_response.body)["events"].first["_time"].to_i.should == @now-23
94
193
  end
95
194
 
96
- it "should return the right answer for: /metric/:name?at=timestamp" do
97
- get "/metric/my_event_count", :at => 18.hours.ago.to_i.to_s
98
- JSON.parse(last_response.body)["value"].to_i.should == 5
195
+ it "should render a list of all events including event-ids" do
196
+ @namespace.ready!(@redis_wrap).announce(
197
+ :_eid => "sdkjgh9sd8f",
198
+ :_time => Time.now.to_i,
199
+ :_type => "foobar!!!"
200
+ )
201
+ get "/foospace/events"
202
+ JSON.parse(last_response.body).should have_key("events")
203
+ JSON.parse(last_response.body)["events"].length.should == 1
204
+ JSON.parse(last_response.body)["events"].first["_eid"].should == "sdkjgh9sd8f"
99
205
  end
100
206
 
101
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp" do
102
- get "/metric/my_event_count", :at => "#{30.hours.ago.to_i}-#{20.hours.ago.to_i}"
103
- JSON.parse(last_response.body)["value"].to_i.should == 3
104
- end
105
207
 
106
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
107
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
108
- JSON.parse(last_response.body)["values"].length.should == 6
208
+ it "should render a list of all events including event-types" do
209
+ create_event("sdkjgh9sd8f", {
210
+ :_eid => "sdkjgh9sd8f",
211
+ :_time => Time.now.to_i,
212
+ :_type => "foobar!!!"
213
+ })
214
+ get "/foospace/events"
215
+ JSON.parse(last_response.body).should have_key("events")
216
+ JSON.parse(last_response.body)["events"].length.should == 1
217
+ JSON.parse(last_response.body)["events"].first["_type"].should == "foobar!!!"
218
+ end
219
+
220
+ it "should render a list of all events including _session-data" do
221
+ create_event("65785678634", {
222
+ :_eid => "65785678634",
223
+ :_time => @now-23,
224
+ :_type => "foobar!!!",
225
+ :_session => "blubb123"
226
+ })
227
+ get "/foospace/events"
228
+ JSON.parse(last_response.body).should have_key("events")
229
+ JSON.parse(last_response.body)["events"].length.should == 1
230
+ JSON.parse(last_response.body)["events"].first["_session"].should == "blubb123"
109
231
  end
110
232
 
111
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
112
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
113
- JSON.parse(last_response.body)["values"][0].first.should == 34.hours.ago.to_i
114
- JSON.parse(last_response.body)["values"][0].last.should == 3
233
+ it "should render a list of all events including _session-data" do
234
+ create_event("4234234634", {
235
+ :_eid => "4234234634",
236
+ :_time => @now-23,
237
+ :_type => "foobar!!!",
238
+ :_session => "blubb123",
239
+ :fnord => "yeah"
240
+ })
241
+ get "/foospace/events"
242
+ JSON.parse(last_response.body).should have_key("events")
243
+ JSON.parse(last_response.body)["events"].length.should == 1
244
+ blubb123_md5 = "e5fa475b26873af5ec6c77668f9975a5"
245
+ JSON.parse(last_response.body)["events"].first["_session_key"].should == blubb123_md5
115
246
  end
116
247
 
117
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
118
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
119
- JSON.parse(last_response.body)["values"][1].first.should == 28.hours.ago.to_i
120
- JSON.parse(last_response.body)["values"][1].last.should == 2
248
+ it "should render a list of all events in the correct chronological order" do
249
+ create_event("daasdasd", {
250
+ :_eid => "daasdasd",
251
+ :_time => @now-23,
252
+ :_type => "foobar!!!"
253
+ })
254
+ create_event("345345345", {
255
+ :_eid => "345345345",
256
+ :_time => @now-5,
257
+ :_type => "foobar!!!"
258
+ })
259
+ create_event("sdygsygsdg", {
260
+ :_eid => "sdygsygsdg",
261
+ :_time => @now-16,
262
+ :_type => "foobar!!!"
263
+ })
264
+ get "/foospace/events"
265
+ JSON.parse(last_response.body).should have_key("events")
266
+ JSON.parse(last_response.body)["events"].length.should == 3
267
+ JSON.parse(last_response.body)["events"][0]["_eid"].should == "345345345"
268
+ JSON.parse(last_response.body)["events"][1]["_eid"].should == "sdygsygsdg"
269
+ JSON.parse(last_response.body)["events"][2]["_eid"].should == "daasdasd"
121
270
  end
122
271
 
123
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
124
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
125
- JSON.parse(last_response.body)["values"][2].first.should == 22.hours.ago.to_i
126
- JSON.parse(last_response.body)["values"][2].last.should == 0
272
+ it "should not render more than 100 events at a time" do
273
+ 120.times do |n|
274
+ create_event("sdygsygsdg-#{n}", {
275
+ :_eid => "sdygsygsdg-#{n}",
276
+ :_time => @now-16,
277
+ :_type => "foobar!!!"
278
+ })
279
+ end
280
+ get "/foospace/events"
281
+ JSON.parse(last_response.body).should have_key("events")
282
+ JSON.parse(last_response.body)["events"].length.should == 100
127
283
  end
128
284
 
129
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
130
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
131
- JSON.parse(last_response.body)["values"][3].first.should == 16.hours.ago.to_i
132
- JSON.parse(last_response.body)["values"][3].last.should == 2
285
+ it "should render all events since a time, not including events at that exact time" do
286
+ create_event("daasdasd", {
287
+ :_eid => "daasdasd",
288
+ :_time => @now-23,
289
+ :_type => "foobar!!!"
290
+ })
291
+ create_event("345345345", {
292
+ :_eid => "345345345",
293
+ :_time => @now-5,
294
+ :_type => "foobar!!!"
295
+ })
296
+ create_event("sdygsygsdg", {
297
+ :_eid => "sdygsygsdg",
298
+ :_time => @now-16,
299
+ :_type => "foobar!!!"
300
+ })
301
+ get "/foospace/events?since=#{@now-24}"
302
+ JSON.parse(last_response.body)["events"].length.should == 3
303
+ get "/foospace/events?since=#{@now-17}"
304
+ JSON.parse(last_response.body)["events"].length.should == 2
305
+ get "/foospace/events?since=#{@now-16}"
306
+ JSON.parse(last_response.body)["events"].length.should == 1
307
+ get "/foospace/events?since=#{@now-2}"
308
+ JSON.parse(last_response.body)["events"].length.should == 0
133
309
  end
134
310
 
135
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
136
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i, :delta => true
137
- JSON.parse(last_response.body)["values"][5].first.should == 4.hours.ago.to_i
138
- JSON.parse(last_response.body)["values"][5].last.should == 2
311
+ it "should render all events for a single event type" do
312
+ @namespace.ready!(@redis_wrap).announce(
313
+ :_type => "fn0rd",
314
+ :_time => @now,
315
+ :_eid => "124234"
316
+ )
317
+ @namespace.ready!(@redis_wrap).announce(
318
+ :_type => "f00bar",
319
+ :_time => @now,
320
+ :_eid => "12235234"
321
+ )
322
+ @namespace.ready!(@redis_wrap).announce(
323
+ :_type => "fn0rd",
324
+ :_time => @now,
325
+ :_eid => "124234234"
326
+ )
327
+ get "/foospace/events?type=fn0rd"
328
+ JSON.parse(last_response.body)["events"].length.should == 2
329
+ get "/foospace/events?type=f00bar"
330
+ JSON.parse(last_response.body)["events"].length.should == 1
139
331
  end
140
332
 
141
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
142
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
143
- JSON.parse(last_response.body)["values"].length.should == 6
333
+ it "should render a list of event types" do
334
+ @namespace.ready!(@redis_wrap).announce(
335
+ :_type => "fn0rd",
336
+ :_time => @now,
337
+ :_eid => "124234"
338
+ )
339
+ @namespace.ready!(@redis_wrap).announce(
340
+ :_type => "f00bar",
341
+ :_time => @now,
342
+ :_eid => "12235234"
343
+ )
344
+ @namespace.ready!(@redis_wrap).announce(
345
+ :_type => "fn0rd",
346
+ :_time => @now,
347
+ :_eid => "124234234"
348
+ )
349
+ get "/foospace/event_types"
350
+ JSON.parse(last_response.body)["types"].length.should == 2
351
+ JSON.parse(last_response.body)["types"].should include("fn0rd")
352
+ JSON.parse(last_response.body)["types"].should include("f00bar")
144
353
  end
145
354
 
146
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
147
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
148
- JSON.parse(last_response.body)["values"][0].first.should == 34.hours.ago.to_i
149
- JSON.parse(last_response.body)["values"][0].last.should == 0
355
+ it "should render all events for a single session"
356
+
357
+ it "should render all events for a single session since a unix timestamp"
358
+
359
+ it "should render all events for a single session, but not more than 100"
360
+
361
+ def create_event(event_id, event_data)
362
+ @redis_wrap.zadd(@namespace.key_prefix(:timeline), event_data.delete(:_time), event_id)
363
+ @redis_wrap.set("fnordmetric-event-#{event_id}", event_data.to_json)
150
364
  end
151
365
 
152
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
153
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
154
- JSON.parse(last_response.body)["values"][1].first.should == 28.hours.ago.to_i
155
- JSON.parse(last_response.body)["values"][1].last.should == 3
366
+ end
367
+
368
+ describe "events api: creating events" do
369
+
370
+ it "should track an event without auth" do
371
+ pending("fix this")
372
+ #post "/events", :type => "myevent", :fnord => "foobar"
373
+ #last_response.status.should == 200
374
+ #FnordMetric::Event.last.type.should == "myevent"
375
+ #FnordMetric::Event.last.fnord.should == "foobar"
156
376
  end
157
377
 
158
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
159
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
160
- JSON.parse(last_response.body)["values"][2].first.should == 22.hours.ago.to_i
161
- JSON.parse(last_response.body)["values"][2].last.should == 5
378
+ it "should return 400 if no type is provided" do
379
+ pending("fix this")
380
+ #post "/events", :fnord => "foobar"
381
+ #last_response.status.should == 400
382
+ #last_response.body.should == "please specify the event_type"
162
383
  end
163
384
 
164
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
165
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
166
- JSON.parse(last_response.body)["values"][3].first.should == 16.hours.ago.to_i
167
- JSON.parse(last_response.body)["values"][3].last.should == 5
385
+ it "should track an event in the past" do
386
+ pending("fix this")
387
+ #my_time = (Time.now-3.years).to_i
388
+ #post "/events", :type => "myevent", :time => my_time
389
+ #last_response.status.should == 200
390
+ #FnordMetric::Event.last.type.should == "myevent"
391
+ #FnordMetric::Event.last.time.should == my_time
168
392
  end
169
393
 
170
- it "should return the right answer for: /metric/:name?at=timestamp-timstamp&tick=seconds" do
171
- get "/metric/my_event_count", :at => "#{34.hours.ago.to_i}-#{1.hour.ago.to_i}", :tick => 6.hours.to_i
172
- JSON.parse(last_response.body)["values"][5].first.should == 4.hours.ago.to_i
173
- JSON.parse(last_response.body)["values"][5].last.should == 7
394
+ it "should track an event with integer data" do
395
+ pending("fix this")
396
+ #post "/events", :type => "myevent", :blubb => "123"
397
+ #last_response.status.should == 200
398
+ #FnordMetric::Event.last.type.should == "myevent"
399
+ #FnordMetric::Event.last.blubb.should == 123
174
400
  end
401
+
402
+ it "should track an event with float data" do
403
+ pending("fix this")
404
+ #post "/events", :type => "myevent", :blubb => "42.23"
405
+ #last_response.status.should == 200
406
+ #FnordMetric::Event.last.type.should == "myevent"
407
+ #FnordMetric::Event.last.blubb.should == 42.23
408
+ end
409
+
410
+
175
411
 
412
+
413
+ end
414
+
415
+ describe "metrics api" do
416
+ # copy from _spec/app_spec.rb ?
176
417
  end
177
-
418
+
419
+
178
420
  end