influxer 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/influxer.gemspec +1 -1
- data/lib/influxer/metrics/metrics.rb +22 -13
- data/lib/influxer/version.rb +1 -1
- data/spec/metrics/metrics_spec.rb +25 -21
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b4166514c7bebd4c2af58c8362902eac3ee2113
|
4
|
+
data.tar.gz: 4d635a59d2969f7be5134018504d1fd93679d73c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46fdff670e7c1f5d82dd4c89724c3b2710946bed1e5b584fb0fdddd2b78f7279d5e2a551599592f3ae7d99b2a1fb0f494cfbc8df981b40fada5ce2512cad04e5
|
7
|
+
data.tar.gz: 7db66507e1616b9dd99dfe55310e73c080c655fd70f2f8506eb6d294e61bfd9fb94401a6caf0ef23de9e66235fafb7afe5e550cdcd68cd8aa1961175fb00d515
|
data/influxer.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_runtime_dependency "rails", '~> 4.0'
|
19
19
|
s.add_dependency "influxdb", "~> 0.1.0", ">= 0.1.8"
|
20
|
-
s.add_dependency "anyway_config", "~> 0.
|
20
|
+
s.add_dependency "anyway_config", "~>0", ">= 0.3"
|
21
21
|
|
22
22
|
s.add_development_dependency "timecop"
|
23
23
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'influxer/metrics/relation'
|
2
2
|
require 'influxer/metrics/scoping'
|
3
3
|
require 'influxer/metrics/fanout'
|
4
|
+
require 'active_model'
|
4
5
|
|
5
6
|
module Influxer
|
6
7
|
class MetricsError < StandardError; end
|
7
8
|
class MetricsInvalid < MetricsError; end
|
8
|
-
|
9
|
+
|
9
10
|
class Metrics
|
10
11
|
include ActiveModel::Model
|
11
12
|
include ActiveModel::Validations
|
@@ -20,10 +21,10 @@ module Influxer
|
|
20
21
|
# delegate query functions to all
|
21
22
|
delegate *(
|
22
23
|
[
|
23
|
-
:write, :select, :where, :group,
|
24
|
-
:merge, :time, :past, :since, :limit,
|
24
|
+
:write, :select, :where, :group,
|
25
|
+
:merge, :time, :past, :since, :limit,
|
25
26
|
:fill, :delete_all
|
26
|
-
]+Influxer::Calculations::CALCULATION_METHODS),
|
27
|
+
]+Influxer::Calculations::CALCULATION_METHODS),
|
27
28
|
to: :all
|
28
29
|
|
29
30
|
def attributes(*attrs)
|
@@ -41,7 +42,7 @@ module Influxer
|
|
41
42
|
def inherited(subclass)
|
42
43
|
subclass.set_series
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def set_series(*args)
|
46
47
|
if args.empty?
|
47
48
|
matches = self.to_s.match(/^(.*)Metrics$/)
|
@@ -66,7 +67,7 @@ module Influxer
|
|
66
67
|
current_scope.clone
|
67
68
|
else
|
68
69
|
default_scoped
|
69
|
-
end
|
70
|
+
end
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -82,7 +83,7 @@ module Influxer
|
|
82
83
|
return false if self.invalid?
|
83
84
|
|
84
85
|
run_callbacks :write do
|
85
|
-
|
86
|
+
write_point
|
86
87
|
end
|
87
88
|
self
|
88
89
|
end
|
@@ -93,9 +94,9 @@ module Influxer
|
|
93
94
|
end
|
94
95
|
|
95
96
|
def write_point
|
96
|
-
client.write_point series, @attributes
|
97
|
+
client.write_point unquote(series), @attributes
|
97
98
|
@persisted = true
|
98
|
-
end
|
99
|
+
end
|
99
100
|
|
100
101
|
def persisted?
|
101
102
|
@persisted
|
@@ -109,6 +110,10 @@ module Influxer
|
|
109
110
|
Influxer.client
|
110
111
|
end
|
111
112
|
|
113
|
+
|
114
|
+
attributes :time
|
115
|
+
|
116
|
+
|
112
117
|
def quote_series(val)
|
113
118
|
case val
|
114
119
|
when Regexp
|
@@ -122,11 +127,15 @@ module Influxer
|
|
122
127
|
quote_series(val.first)
|
123
128
|
end
|
124
129
|
else
|
125
|
-
'"'+val.to_s.gsub(/\"/){ %q{\"} }+'"'
|
130
|
+
'"'+val.to_s.gsub(/\"/){ %q{\"} }+'"'
|
126
131
|
end
|
127
132
|
end
|
128
133
|
|
129
|
-
|
130
|
-
|
134
|
+
private
|
135
|
+
|
136
|
+
def unquote(name)
|
137
|
+
name.gsub(/(\A['"]|['"]\z)/,'')
|
138
|
+
end
|
139
|
+
|
131
140
|
end
|
132
|
-
end
|
141
|
+
end
|
data/lib/influxer/version.rb
CHANGED
@@ -49,36 +49,37 @@ describe Influxer::Metrics do
|
|
49
49
|
|
50
50
|
let(:dummy_metrics) { DummyMetrics.new dummy_id: 1, user_id: 1}
|
51
51
|
|
52
|
-
describe "write
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
describe "#write" do
|
53
|
+
|
54
|
+
context "Validations" do
|
55
|
+
it "should not write if required attribute is missing" do
|
56
|
+
m = DummyMetrics.new(dummy_id: 1)
|
57
|
+
expect(m.write).to be false
|
58
|
+
expect(m.errors.size).to eq(1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise error if required attribute is missing" do
|
62
|
+
expect{DummyMetrics.new(user_id: 1).write!}.to raise_error(StandardError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise error if you want to write twice" do
|
66
|
+
expect(dummy_metrics.write).to be_truthy
|
67
|
+
expect{dummy_metrics.write!}.to raise_error(StandardError)
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
it "should write successfully when all required attributes are set" do
|
72
|
+
expect(Influxer.client).to receive(:write_point).with("dummy", anything)
|
65
73
|
expect(dummy_metrics.write).to be_truthy
|
66
74
|
expect(dummy_metrics.persisted?).to be_truthy
|
67
75
|
end
|
68
|
-
|
69
|
-
it "should raise error if you want to write twice" do
|
70
|
-
expect(dummy_metrics.write).to be_truthy
|
71
|
-
expect{dummy_metrics.write!}.to raise_error(StandardError)
|
72
|
-
end
|
73
76
|
end
|
74
77
|
|
75
|
-
|
76
|
-
it "should
|
77
|
-
|
78
|
+
context "active_model callbacks" do
|
79
|
+
it "should set current time" do
|
78
80
|
Timecop.freeze(Time.local(2014,10,10,10,10,10)) do
|
79
81
|
dummy_metrics.write!
|
80
82
|
end
|
81
|
-
|
82
83
|
expect(dummy_metrics.time).to eq Time.local(2014,10,10,10,10,10)
|
83
84
|
end
|
84
85
|
end
|
@@ -89,7 +90,8 @@ describe Influxer::Metrics do
|
|
89
90
|
|
90
91
|
let(:dummy_metrics) do
|
91
92
|
Class.new(Influxer::Metrics) do
|
92
|
-
set_series :dummies
|
93
|
+
set_series :dummies
|
94
|
+
attributes :user_id, :dummy_id
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -159,7 +161,9 @@ describe Influxer::Metrics do
|
|
159
161
|
|
160
162
|
describe "write method" do
|
161
163
|
it "should write data and return point" do
|
162
|
-
|
164
|
+
expect(Influxer.client).to receive(:write_point).with("dummies", {user_id: 1, dummy_id: 2})
|
165
|
+
|
166
|
+
point = dummy_metrics.write(user_id: 1, dummy_id: 2)
|
163
167
|
expect(point.persisted?).to be_truthy
|
164
168
|
expect(point.user_id).to eq 1
|
165
169
|
expect(point.dummy_id).to eq 2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: influxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -50,14 +50,20 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
53
|
+
version: '0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.3'
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
requirements:
|
58
61
|
- - "~>"
|
59
62
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0
|
63
|
+
version: '0'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.3'
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: timecop
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,3 +277,4 @@ signing_key:
|
|
271
277
|
specification_version: 4
|
272
278
|
summary: InfluxDB for Rails
|
273
279
|
test_files: []
|
280
|
+
has_rdoc:
|