influxer 0.2.4 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +1 -17
- data/Changelog.md +7 -0
- data/Gemfile +7 -0
- data/README.md +6 -20
- data/Rakefile +4 -0
- data/gemfiles/rails42.gemfile +4 -1
- data/influxer.gemspec +6 -6
- data/lib/influxer/client.rb +4 -44
- data/lib/influxer/config.rb +23 -14
- data/lib/influxer/engine.rb +0 -1
- data/lib/influxer/metrics/metrics.rb +40 -7
- data/lib/influxer/metrics/relation/calculations.rb +13 -7
- data/lib/influxer/metrics/relation/time_query.rb +14 -8
- data/lib/influxer/metrics/relation/where_clause.rb +62 -0
- data/lib/influxer/metrics/relation.rb +67 -76
- data/lib/influxer/metrics/scoping.rb +4 -4
- data/lib/influxer/model.rb +4 -0
- data/lib/influxer/rails/client.rb +47 -0
- data/lib/influxer/version.rb +1 -1
- data/lib/influxer.rb +4 -2
- data/spec/cases/points_spec.rb +34 -0
- data/spec/client_spec.rb +21 -24
- data/spec/fixtures/empty_result.json +21 -0
- data/spec/fixtures/single_series.json +29 -0
- data/spec/metrics/metrics_spec.rb +139 -113
- data/spec/metrics/relation_spec.rb +160 -105
- data/spec/metrics/scoping_spec.rb +11 -17
- data/spec/model/user_spec.rb +44 -0
- data/spec/spec_helper.rb +38 -8
- data/spec/support/metrics/action_metrics.rb +3 -0
- data/spec/support/metrics/custom_metrics.rb +4 -0
- data/spec/support/{dummy_metrics.rb → metrics/dummy_metrics.rb} +2 -1
- data/spec/support/metrics/user_metrics.rb +4 -0
- data/spec/support/metrics/visits_metrics.rb +4 -0
- data/spec/support/shared_contexts/shared_query.rb +16 -0
- data/spec/support/user.rb +14 -0
- metadata +42 -71
- data/gemfiles/rails40.gemfile +0 -7
- data/gemfiles/rails41.gemfile +0 -7
- data/lib/influxer/metrics/fanout.rb +0 -65
- data/lib/influxer/metrics/relation/fanout_query.rb +0 -49
- data/lib/tasks/influxer_tasks.rake +0 -4
- data/spec/config_spec.rb +0 -17
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/metrics/testo_metrics.rb +0 -3
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/testo.rb +0 -6
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -83
- data/spec/dummy/config/environments/test.rb +0 -38
- data/spec/dummy/config/influxdb.yml +0 -5
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -56
- data/spec/dummy/config/secrets.yml +0 -25
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20140730133818_add_testos.rb +0 -11
- data/spec/dummy/db/migrate/20140731162044_add_column_to_testos.rb +0 -5
- data/spec/dummy/db/schema.rb +0 -22
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/fanout_series.json +0 -23
- data/spec/metrics/fanout_spec.rb +0 -61
- data/spec/model/testo_spec.rb +0 -27
@@ -1,177 +1,203 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Influxer::Metrics do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Influxer::Metrics, :query do
|
4
|
+
let(:metrics) { described_class.new }
|
5
|
+
let(:dummy_metrics) { DummyMetrics.new dummy_id: 1, user_id: 1 }
|
6
|
+
|
7
|
+
subject { metrics }
|
8
|
+
|
9
|
+
context "class methods" do
|
10
|
+
subject { described_class }
|
11
|
+
|
12
|
+
specify { is_expected.to respond_to :attributes }
|
13
|
+
specify { is_expected.to respond_to :set_series }
|
14
|
+
specify { is_expected.to respond_to :series }
|
15
|
+
specify { is_expected.to respond_to :write }
|
16
|
+
specify { is_expected.to respond_to :write! }
|
17
|
+
|
18
|
+
specify { is_expected.to respond_to :all }
|
19
|
+
specify { is_expected.to respond_to :where }
|
20
|
+
specify { is_expected.to respond_to :offset }
|
21
|
+
specify { is_expected.to respond_to :time }
|
22
|
+
specify { is_expected.to respond_to :past }
|
23
|
+
specify { is_expected.to respond_to :since }
|
24
|
+
specify { is_expected.to respond_to :limit }
|
25
|
+
specify { is_expected.to respond_to :select }
|
26
|
+
specify { is_expected.to respond_to :delete_all }
|
8
27
|
end
|
9
28
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
specify { expect(metrics_class).to respond_to :series }
|
18
|
-
|
19
|
-
# query methods
|
20
|
-
|
21
|
-
specify { expect(metrics_class).to respond_to :all }
|
22
|
-
specify { expect(metrics_class).to respond_to :where }
|
23
|
-
specify { expect(metrics_class).to respond_to :merge }
|
24
|
-
specify { expect(metrics_class).to respond_to :time }
|
25
|
-
specify { expect(metrics_class).to respond_to :past }
|
26
|
-
specify { expect(metrics_class).to respond_to :since }
|
27
|
-
specify { expect(metrics_class).to respond_to :limit }
|
28
|
-
specify { expect(metrics_class).to respond_to :select }
|
29
|
-
specify { expect(metrics_class).to respond_to :delete_all }
|
30
|
-
|
31
|
-
# instance methods
|
32
|
-
|
33
|
-
specify { expect(metrics).to respond_to :write }
|
34
|
-
specify { expect(metrics).to respond_to :write! }
|
35
|
-
specify { expect(metrics).to respond_to :persisted? }
|
36
|
-
specify { expect(metrics).to respond_to :series }
|
37
|
-
|
38
|
-
# ActiveModel::Validations
|
39
|
-
|
40
|
-
specify { expect(metrics).to respond_to :valid? }
|
41
|
-
specify { expect(metrics).to respond_to :invalid? }
|
42
|
-
specify { expect(metrics).to respond_to :errors }
|
43
|
-
|
44
|
-
describe "instance methods" do
|
45
|
-
let(:dummy_metrics) { DummyMetrics.new dummy_id: 1, user_id: 1 }
|
29
|
+
context "instance methods" do
|
30
|
+
specify { is_expected.to respond_to :write }
|
31
|
+
specify { is_expected.to respond_to :write! }
|
32
|
+
specify { is_expected.to respond_to :persisted? }
|
33
|
+
specify { is_expected.to respond_to :series }
|
34
|
+
specify { is_expected.to be_a ActiveModel::Model }
|
35
|
+
end
|
46
36
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
describe "#write" do
|
38
|
+
it "doesn't write if required attribute is missing" do
|
39
|
+
m = DummyMetrics.new(dummy_id: 1)
|
40
|
+
expect(client).not_to receive(:write_point)
|
41
|
+
expect(m.write).to be false
|
42
|
+
expect(m.errors.size).to eq(1)
|
43
|
+
end
|
54
44
|
|
55
|
-
|
56
|
-
|
57
|
-
|
45
|
+
it "raises error if required attribute is missing" do
|
46
|
+
expect { DummyMetrics.new(user_id: 1).write! }.to raise_error(Influxer::MetricsInvalid)
|
47
|
+
end
|
58
48
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
49
|
+
it "raises error if you want to write twice" do
|
50
|
+
expect(dummy_metrics.write).to be_truthy
|
51
|
+
expect { dummy_metrics.write! }.to raise_error(Influxer::MetricsError)
|
52
|
+
end
|
64
53
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
54
|
+
it "writes successfully" do
|
55
|
+
expect(client).to receive(:write_point).with("dummy", anything)
|
56
|
+
expect(dummy_metrics.write).to be_truthy
|
57
|
+
expect(dummy_metrics.persisted?).to be_truthy
|
70
58
|
end
|
71
59
|
|
72
|
-
context "
|
73
|
-
it "
|
74
|
-
Timecop.freeze(Time.local(
|
75
|
-
|
76
|
-
|
77
|
-
expect(dummy_metrics.time).to eq Time.local(2014, 10, 10, 10, 10, 10)
|
60
|
+
context "after_write callback" do
|
61
|
+
it "sets current time" do
|
62
|
+
Timecop.freeze(Time.local(2015))
|
63
|
+
dummy_metrics.write!
|
64
|
+
expect(dummy_metrics.time).to eq Time.local(2015)
|
78
65
|
end
|
79
66
|
end
|
80
67
|
end
|
81
68
|
|
82
|
-
describe "
|
69
|
+
describe "#series" do
|
83
70
|
let(:dummy_metrics) do
|
84
|
-
Class.new(
|
71
|
+
Class.new(described_class) do
|
85
72
|
set_series :dummies
|
86
73
|
attributes :user_id, :dummy_id
|
87
74
|
end
|
88
75
|
end
|
89
76
|
|
90
77
|
let(:dummy_metrics_2) do
|
91
|
-
Class.new(
|
78
|
+
Class.new(described_class) do
|
92
79
|
set_series "dummy \"A\""
|
93
80
|
end
|
94
81
|
end
|
95
82
|
|
96
83
|
let(:dummy_metrics_3) do
|
97
|
-
Class.new(
|
84
|
+
Class.new(described_class) do
|
98
85
|
set_series /^.*$/
|
99
86
|
end
|
100
87
|
end
|
101
88
|
|
102
89
|
let(:dummy_with_2_series) do
|
103
|
-
Class.new(
|
90
|
+
Class.new(described_class) do
|
104
91
|
set_series :events, :errors
|
105
92
|
end
|
106
93
|
end
|
107
94
|
|
108
95
|
let(:dummy_with_2_series_quoted) do
|
109
|
-
Class.new(
|
96
|
+
Class.new(described_class) do
|
110
97
|
set_series "dummy \"A\"", "dummy \"B\""
|
111
98
|
end
|
112
99
|
end
|
113
100
|
|
114
101
|
let(:dummy_with_proc_series) do
|
115
|
-
Class.new(
|
102
|
+
Class.new(described_class) do
|
116
103
|
attributes :user_id, :test_id
|
117
104
|
set_series ->(metrics) { "test/#{metrics.test_id}/user/#{metrics.user_id}" }
|
118
105
|
end
|
119
106
|
end
|
120
107
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
108
|
+
it "sets series name from class name by default" do
|
109
|
+
expect(DummyMetrics.new.series).to eq "\"dummy\""
|
110
|
+
end
|
125
111
|
|
126
|
-
|
127
|
-
|
128
|
-
|
112
|
+
it "sets series from subclass" do
|
113
|
+
expect(dummy_metrics.new.series).to eq "\"dummies\""
|
114
|
+
end
|
129
115
|
|
130
|
-
|
131
|
-
|
132
|
-
|
116
|
+
it "sets series as regexp" do
|
117
|
+
expect(dummy_metrics_3.new.series).to eq '/^.*$/'
|
118
|
+
end
|
133
119
|
|
134
|
-
|
135
|
-
|
136
|
-
|
120
|
+
it "quotes series" do
|
121
|
+
expect(dummy_metrics_2.new.series).to eq "\"dummy \\\"A\\\"\""
|
122
|
+
end
|
137
123
|
|
138
|
-
|
139
|
-
|
140
|
-
|
124
|
+
it "set several series" do
|
125
|
+
expect(dummy_with_2_series.new.series).to eq "merge(\"events\",\"errors\")"
|
126
|
+
end
|
141
127
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
128
|
+
it "quotes several series" do
|
129
|
+
expect(dummy_with_2_series_quoted.new.series)
|
130
|
+
.to eq "merge(\"dummy \\\"A\\\"\",\"dummy \\\"B\\\"\")"
|
131
|
+
end
|
146
132
|
|
147
|
-
|
148
|
-
|
133
|
+
it "sets series from proc" do
|
134
|
+
expect(dummy_with_proc_series.series).to be_an_instance_of Proc
|
135
|
+
|
136
|
+
m = dummy_with_proc_series.new user_id: 2, test_id: 123
|
137
|
+
expect(m.series).to eq "\"test/123/user/2\""
|
138
|
+
end
|
139
|
+
end
|
149
140
|
|
150
|
-
|
151
|
-
|
141
|
+
describe ".tags" do
|
142
|
+
let(:dummy1) { Class.new(DummyMetrics) }
|
143
|
+
let!(:dummy2) do
|
144
|
+
Class.new(dummy1) do
|
145
|
+
tags :zone
|
152
146
|
end
|
153
147
|
end
|
154
148
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
.to receive(:write_point).with("dummies", user_id: 1, dummy_id: 2)
|
149
|
+
it "inherits tags" do
|
150
|
+
expect(dummy2.tag_names).to include('dummy_id', 'host', 'zone')
|
151
|
+
end
|
159
152
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
153
|
+
it "clones tags" do
|
154
|
+
dummy1.tags :status
|
155
|
+
expect(dummy1.tag_names).to include('status')
|
156
|
+
expect(dummy2.tag_names).not_to include('status')
|
157
|
+
end
|
158
|
+
end
|
165
159
|
|
166
|
-
|
167
|
-
|
168
|
-
|
160
|
+
describe "#dup" do
|
161
|
+
let(:point) { DummyMetrics.new(user_id: 1, dummy_id: 2) }
|
162
|
+
subject { point.dup }
|
163
|
+
|
164
|
+
specify { expect(subject.user_id).to eq 1 }
|
165
|
+
specify { expect(subject.dummy_id).to eq 2 }
|
166
|
+
|
167
|
+
context "dup is not persisted" do
|
168
|
+
before { point.write }
|
169
|
+
specify { expect(subject.persisted?).to be_falsey }
|
169
170
|
end
|
171
|
+
end
|
170
172
|
|
171
|
-
|
172
|
-
|
173
|
-
|
173
|
+
describe ".write" do
|
174
|
+
let(:dummy_metrics) do
|
175
|
+
Class.new(described_class) do
|
176
|
+
set_series :dummies
|
177
|
+
tags :dummy_id, :host
|
178
|
+
attributes :user_id
|
174
179
|
end
|
175
180
|
end
|
181
|
+
|
182
|
+
it "write data and return point" do
|
183
|
+
expect(client)
|
184
|
+
.to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 })
|
185
|
+
|
186
|
+
point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test')
|
187
|
+
expect(point.persisted?).to be_truthy
|
188
|
+
expect(point.user_id).to eq 1
|
189
|
+
expect(point.dummy_id).to eq 2
|
190
|
+
end
|
191
|
+
|
192
|
+
it "doesn't write data and return false if invalid" do
|
193
|
+
expect(client).not_to receive(:write_point)
|
194
|
+
expect(DummyMetrics.write(dummy_id: 2)).to be false
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe ".all" do
|
199
|
+
it "responds with relation" do
|
200
|
+
expect(described_class.all).to be_a Influxer::Relation
|
201
|
+
end
|
176
202
|
end
|
177
203
|
end
|