nightfury 0.7.2 → 0.8.0

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.
@@ -30,7 +30,8 @@ module Nightfury
30
30
  end
31
31
 
32
32
  def decode_data_point(data_point)
33
- current_count, current_total, data = data_point[0].split(',')
33
+ time, data_with_meta = super(data_point)
34
+ current_count, current_total, data = data_with_meta.split(',')
34
35
  [data_point[1], data, {current_count: current_count, current_total: current_total}]
35
36
  end
36
37
  end
@@ -7,32 +7,28 @@ module Nightfury
7
7
  current_step_time = current_step_time.to_s
8
8
  last_step_time = last_step_time.to_s
9
9
  next if data_points[current_step_time]
10
- data_points[current_step_time] = data_points[last_step_time]
10
+ data_points[current_step_time] = 0.to_s
11
11
  end
12
12
  data_points
13
13
  end
14
14
 
15
- def incr(step=1, timestamp = Time.now)
16
- last_data_point = get
17
- if last_data_point
18
- time, value = last_data_point.flatten
19
- value = value.to_i + step
20
- set(value, timestamp)
21
- else
22
- set(step, timestamp)
23
- end
15
+ def incr(step=1, time = Time.now)
16
+ value = 0
17
+ step_time = get_step_time(time)
18
+ data_point = get_exact(step_time)
19
+ value = data_point.flatten[1] unless data_point.nil?
20
+ updated_value = value.to_i + step
21
+ set(updated_value, step_time)
24
22
  end
25
23
 
26
- def decr(step=1, timestamp = Time.now)
27
- last_data_point = get
28
- if last_data_point
29
- time, value = last_data_point.flatten
30
- value = value.to_i - step
31
- set(value, timestamp)
32
- else
33
- set(-step, timestamp)
34
- end
35
- end
24
+ def decr(step=1, time = Time.now)
25
+ value = 0
26
+ step_time = get_step_time(time)
27
+ data_point = get_exact(step_time)
28
+ value = data_point.flatten[1] unless data_point.nil?
29
+ updated_value = value.to_i - step
30
+ set(updated_value, step_time)
31
+ end
36
32
  end
37
33
  end
38
34
  end
@@ -120,13 +120,21 @@ module Nightfury
120
120
  end
121
121
 
122
122
  def decode_data_point(data_point)
123
- [data_point[1], data_point[0], {}]
123
+ data_point = data_point.first
124
+ colon_index = data_point.index(':')
125
+ [
126
+ data_point[0...colon_index],
127
+ data_point[colon_index+1..-1],
128
+ {}
129
+ ]
124
130
  end
125
131
 
126
132
  private
127
133
 
128
134
  def add_value_to_timeline(value, time)
129
135
  timestamp = get_step_time(time).to_i
136
+ redis.zremrangebyscore redis_key, timestamp, timestamp
137
+ value = "#{timestamp}:#{value}"
130
138
  redis.zadd redis_key, timestamp, value
131
139
  end
132
140
 
@@ -1,3 +1,3 @@
1
1
  module Nightfury
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Nightfury::Metric::CountTimeSeries do
4
4
  describe "#get_padded_range" do
5
- it "should fill the missing data points" do
5
+ it "should fill the missing data points with zero" do
6
6
  count_series = Nightfury::Metric::CountTimeSeries.new(:count)
7
7
  start_time = Time.new(2013,1,1,0,0,0)
8
8
  end_time = start_time + 120
@@ -10,111 +10,134 @@ describe Nightfury::Metric::CountTimeSeries do
10
10
 
11
11
  count_series.set(1, start_time)
12
12
  count_series.set(2, end_time)
13
- count_series.get_padded_range(start_time, end_time)[missing_time.to_i.to_s].should == "1"
13
+ count_series.get_padded_range(start_time, end_time)[missing_time.to_i.to_s].should == "0"
14
14
  end
15
15
  end
16
16
 
17
17
  describe "Incr" do
18
- context "Has data points" do
19
- it "should be able to increment value by 1 at the current timestamp by default" do
20
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
21
- time_now = Time.now
22
- # Add a data point
23
- count_series.set(1, time_now - 10)
24
-
25
- Timecop.freeze(time_now) do
26
- count_series.incr
27
- end
28
- Timecop.return
29
-
30
- count_series.get.values.first.should == "2"
31
- end
18
+ it "should increment the count at the step time of the given timestamp" do
19
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
20
+ time_now = Time.now
21
+ #Add a data point
22
+ count_series.set(2, time_now)
23
+
24
+ count_series.incr(2, time_now)
32
25
 
33
- it "should be able to increment value by a given step" do
34
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
35
- time_now = Time.now
36
- # Add a data point
37
- count_series.set(1, time_now - 10)
26
+ count_series.get.values.first.should == "4"
27
+ end
28
+
29
+ it "should increment the count at the step time of the current time by default" do
30
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
31
+ time_now = Time.now
32
+ #Add a data point
33
+ count_series.set(2, time_now)
34
+
35
+ Timecop.freeze(time_now) do
36
+ count_series.incr(2)
37
+ end
38
+ Timecop.return
38
39
 
39
- Timecop.freeze(time_now) do
40
- count_series.incr(2)
41
- end
42
- Timecop.return
40
+ count_series.get.values.first.should == "4"
41
+ end
43
42
 
44
- count_series.get.values.first.should == "3"
43
+ it "should increment the count by 1 by default" do
44
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
45
+ time_now = Time.now
46
+ #Add a data point
47
+ count_series.set(2, time_now)
48
+
49
+ Timecop.freeze(time_now) do
50
+ count_series.incr
45
51
  end
52
+ Timecop.return
46
53
 
54
+ count_series.get.values.first.should == "3"
55
+ end
47
56
 
48
- it "should be able to increment value at a step near the given timestamp" do
49
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
50
- time_now = Time.now
51
- time_later = time_now + 61
52
- # Add a data point
53
- count_series.set(1, time_now - 10)
54
- count_series.incr(1,time_later)
55
- count_series.get.should == { floor_time(time_later, 60).to_i.to_s => "2"}
56
- end
57
+ it "should set the count to the step when there is no data point at the step time" do
58
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
59
+ time_now = Time.now
60
+ count_series.incr(1, time_now)
61
+ count_series.get(time_now).values.first.should == "1"
57
62
  end
58
63
 
59
- context "Has no data points" do
60
- it "should add a data point with the given step" do
61
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
62
- time_now = Time.now
63
- count_series.incr(2, time_now)
64
- count_series.get.should == { floor_time(time_now, 60).to_i.to_s => "2"}
65
- end
64
+ it "should increment the right step bucket" do
65
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
66
+ first_step_bucket = Time.now
67
+ second_step_bucket = Time.now + 61
68
+
69
+ count_series.set(5, first_step_bucket)
70
+ count_series.set(6, second_step_bucket)
71
+
72
+ count_series.incr(1, first_step_bucket)
73
+ count_series.incr(1, second_step_bucket)
74
+
75
+ count_series.get(first_step_bucket).values.first.should == "6"
76
+ count_series.get(second_step_bucket).values.first.should == "7"
66
77
  end
67
78
  end
68
79
 
69
80
  describe "Decr" do
70
- context "Has data points" do
71
- it "should be able to decrement value by 1 at a step near the current timestamp by default" do
72
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
73
- time_now = Time.now
74
- # Add a data point
75
- count_series.set(1, time_now - 61)
76
-
77
- Timecop.freeze(time_now) do
78
- count_series.decr
79
- end
80
- Timecop.return
81
-
82
- count_series.get.values.first.should == "0"
83
- end
84
-
85
- it "should be able to decrement value by a given step" do
86
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
87
- time_now = Time.now
88
- # Add a data point
89
- count_series.set(2, time_now - 61)
81
+ it "should decrement the count at the step time of the given timestamp" do
82
+ count_series = Nightfury::Metric::CountTimeSeries.new(:counter)
83
+ time_now = Time.now
84
+
85
+ #Add a data point
86
+ count_series.set(2, time_now)
90
87
 
91
- Timecop.freeze(time_now) do
92
- count_series.decr(2)
93
- end
94
- Timecop.return
88
+ count_series.decr(2, time_now)
95
89
 
96
- count_series.get.values.first.should == "0"
90
+ count_series.get.values.first.should == "0"
91
+ end
92
+
93
+ it "should decrement the count at the step time of the current time by default" do
94
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
95
+ time_now = Time.now
96
+ #Add a data point
97
+ count_series.set(2, time_now)
98
+
99
+ Timecop.freeze(time_now) do
100
+ count_series.decr(2)
97
101
  end
102
+ Timecop.return
98
103
 
104
+ count_series.get.values.first.should == "0"
105
+ end
99
106
 
100
- it "should be able to decrement value at nearest step of a given timestamp" do
101
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
102
- time_now = Time.now
103
- time_later = time_now + 61
104
- # Add a data point
105
- count_series.set(1, time_now - 10)
106
- count_series.decr(1,time_later)
107
- count_series.get.should == { floor_time(time_later, 60).to_i.to_s => "0"}
107
+ it "should decrement the count by 1 by default" do
108
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
109
+ time_now = Time.now
110
+ #Add a data point
111
+ count_series.set(2, time_now)
112
+
113
+ Timecop.freeze(time_now) do
114
+ count_series.decr
108
115
  end
116
+ Timecop.return
117
+
118
+ count_series.get.values.first.should == "1"
109
119
  end
110
120
 
111
- context "Has no data points" do
112
- it "should add a data point with the given step" do
113
- count_series = Nightfury::Metric::CountTimeSeries.new(1)
114
- time_now = Time.now
115
- count_series.decr(2, time_now)
116
- count_series.get.should == { floor_time(time_now, 60).to_i.to_s => "-2"}
117
- end
121
+ it "should set the count to the step when there is no data point at the step time" do
122
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
123
+ time_now = Time.now
124
+ count_series.decr(1, time_now)
125
+ count_series.get(time_now).values.first.should == "-1"
126
+ end
127
+
128
+ it "should decrement the right step bucket" do
129
+ count_series = Nightfury::Metric::CountTimeSeries.new(:count)
130
+ first_step_bucket = Time.now
131
+ second_step_bucket = Time.now + 61
132
+
133
+ count_series.set(5, first_step_bucket)
134
+ count_series.set(6, second_step_bucket)
135
+
136
+ count_series.decr(1, first_step_bucket)
137
+ count_series.decr(1, second_step_bucket)
138
+
139
+ count_series.get(first_step_bucket).values.first.should == "4"
140
+ count_series.get(second_step_bucket).values.first.should == "5"
118
141
  end
119
142
  end
120
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nightfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-08 00:00:00.000000000 Z
13
+ date: 2013-03-11 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Nightfury is a reporting/analytics backend written on Redis
16
16
  email: