influxer 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/README.md +7 -5
- data/influxer.gemspec +1 -0
- data/lib/influxer/config.rb +20 -44
- data/lib/influxer/metrics/metrics.rb +3 -1
- data/lib/influxer/metrics/relation.rb +24 -8
- data/lib/influxer/version.rb +1 -1
- data/spec/metrics/metrics_spec.rb +16 -4
- data/spec/metrics/relation_spec.rb +15 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41e9c97ead83ee84ac09bcbb5d4e4192513aa0cb
|
4
|
+
data.tar.gz: e8e98767913c3afa849d7f8a5bcc2215a18cd442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fcbb580a0e0907a441566aab7e6d23b7d63c5bc7e0ff08bdb8a68a9e1c1ecbe724d6028a9297751a72ffb75678fb83fcfa42043c62a7decb3fbb657c6e51538
|
7
|
+
data.tar.gz: 9548bbdf12e8c6b4354711814653faff335a88741dfc00e9a8344bb521b06010c9685f4bc9c68ecb11bfaa66607378cceca82b1eb2bf5113e628d610ccd490ee
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Influxer
|
4
4
|
|
5
|
-
ActiveRecord-
|
5
|
+
Influxer provides an ActiveRecord-style way to work with [InfluxDB](https://influxdb.com/) with many useful features, such as:
|
6
6
|
- Familar query language (use `select`, `where`, `not`, `group` etc).
|
7
7
|
- Support for Regex conditions: `where(page_id: /^home\/.*/) #=> select * ... where page_id=~/^home\/.*/`.
|
8
8
|
- Special query methods for InfluxDB:
|
@@ -11,7 +11,7 @@ ActiveRecord-like wrapper for [influxdb-ruby](https://github.com/influxdb/influx
|
|
11
11
|
- `since` - get only points since date (e.g. `Metrics.since(Time.utc(2014,12,31)) => # select * ... where time > 1419984000s`);
|
12
12
|
- `merge` - merge series.
|
13
13
|
- Scopes support
|
14
|
-
```
|
14
|
+
```ruby
|
15
15
|
class Metrics < Influxer::Metrics
|
16
16
|
default_scope -> { time(:hour).limit(1000) }
|
17
17
|
scope :unlimited, -> { limit(nil) }
|
@@ -26,7 +26,7 @@ ActiveRecord-like wrapper for [influxdb-ruby](https://github.com/influxdb/influx
|
|
26
26
|
|
27
27
|
```
|
28
28
|
- Support for handling fanout series as one metrics.
|
29
|
-
```
|
29
|
+
```ruby
|
30
30
|
class Metrics < Influxer::Metrics
|
31
31
|
fanout :account, :user, :page
|
32
32
|
end
|
@@ -43,7 +43,7 @@ ActiveRecord-like wrapper for [influxdb-ruby](https://github.com/influxdb/influx
|
|
43
43
|
|
44
44
|
```
|
45
45
|
- Integrate with your model:
|
46
|
-
```
|
46
|
+
```ruby
|
47
47
|
class UserVisits < Influxer::Metrics
|
48
48
|
end
|
49
49
|
|
@@ -57,4 +57,6 @@ ActiveRecord-like wrapper for [influxdb-ruby](https://github.com/influxdb/influx
|
|
57
57
|
|
58
58
|
user.visits.where(page_id: 'home')
|
59
59
|
#=> select * from user_visits where page_id='home'
|
60
|
-
```
|
60
|
+
```
|
61
|
+
|
62
|
+
Find more on [Wiki](/palkan/influxer/wiki).
|
data/influxer.gemspec
CHANGED
@@ -17,6 +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.1"
|
20
21
|
|
21
22
|
s.add_development_dependency "timecop"
|
22
23
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
data/lib/influxer/config.rb
CHANGED
@@ -1,50 +1,26 @@
|
|
1
|
-
|
2
|
-
class Config
|
3
|
-
attr_accessor :database,
|
4
|
-
:host,
|
5
|
-
:port,
|
6
|
-
:username,
|
7
|
-
:password,
|
8
|
-
:use_ssl,
|
9
|
-
:async,
|
10
|
-
:cache,
|
11
|
-
:retry,
|
12
|
-
:time_precision,
|
13
|
-
:initial_delay,
|
14
|
-
:max_delay,
|
15
|
-
:read_timeout,
|
16
|
-
:write_timeout
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@database = 'db'
|
20
|
-
@host = 'localhost'
|
21
|
-
@port = 8083
|
22
|
-
@use_ssl = false
|
23
|
-
@async = true
|
24
|
-
@cache = false
|
25
|
-
@retry = false
|
26
|
-
@time_precision = 's'
|
27
|
-
@max_delay = 30
|
28
|
-
@initial_delay = 0.01
|
29
|
-
@read_timeout = 30
|
30
|
-
@write_timeout = 5
|
31
|
-
|
32
|
-
config_path = Rails.root.join("config","influxdb.yml")
|
33
|
-
|
34
|
-
config = {}
|
35
|
-
|
36
|
-
if File.file? config_path
|
37
|
-
config = YAML.load_file(config_path)[Rails.env] || {}
|
38
|
-
end
|
1
|
+
require 'anyway'
|
39
2
|
|
40
|
-
|
41
|
-
|
42
|
-
|
3
|
+
module Influxer
|
4
|
+
class Config < Anyway::Config
|
5
|
+
config_name :influxdb
|
43
6
|
|
44
|
-
|
45
|
-
|
46
|
-
|
7
|
+
attr_config database: 'db',
|
8
|
+
host: 'localhost',
|
9
|
+
port: 8083,
|
10
|
+
username: 'root',
|
11
|
+
password: 'root',
|
12
|
+
use_ssl: false,
|
13
|
+
async: true,
|
14
|
+
cache: false,
|
15
|
+
retry: false,
|
16
|
+
time_precision: 's',
|
17
|
+
initial_delay: 0.01,
|
18
|
+
max_delay: 30,
|
19
|
+
read_timeout: 30,
|
20
|
+
write_timeout: 5
|
47
21
|
|
22
|
+
def load
|
23
|
+
super
|
48
24
|
# we want pass @cache value as options to cache store, so we want it to be a Hash
|
49
25
|
if @cache == true
|
50
26
|
@cache = {}
|
@@ -16,7 +16,8 @@ module Influxer
|
|
16
16
|
define_model_callbacks :write
|
17
17
|
|
18
18
|
class << self
|
19
|
-
delegate
|
19
|
+
# delegate query functions to all
|
20
|
+
delegate :write, :select, :where, :group, :merge, :time, :past, :since, :limit, :fill, :delete_all, to: :all
|
20
21
|
|
21
22
|
def attributes(*attrs)
|
22
23
|
attrs.each do |name|
|
@@ -76,6 +77,7 @@ module Influxer
|
|
76
77
|
run_callbacks :write do
|
77
78
|
self.write_point
|
78
79
|
end
|
80
|
+
self
|
79
81
|
end
|
80
82
|
|
81
83
|
def write!
|
@@ -60,6 +60,12 @@ module Influxer
|
|
60
60
|
CODE
|
61
61
|
end
|
62
62
|
|
63
|
+
|
64
|
+
class << self
|
65
|
+
# delegate array methods to to_a
|
66
|
+
delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join, to: :to_a
|
67
|
+
end
|
68
|
+
|
63
69
|
# Initialize new Relation for 'klass' (Class) metrics.
|
64
70
|
#
|
65
71
|
# Available params:
|
@@ -133,7 +139,6 @@ module Influxer
|
|
133
139
|
def to_a
|
134
140
|
return @records if loaded?
|
135
141
|
load
|
136
|
-
@records
|
137
142
|
end
|
138
143
|
|
139
144
|
def inspect
|
@@ -143,8 +148,23 @@ module Influxer
|
|
143
148
|
"#<#{self.class.name} [#{entries.join(', ')}]>"
|
144
149
|
end
|
145
150
|
|
146
|
-
def
|
147
|
-
|
151
|
+
def empty?
|
152
|
+
unless loaded?
|
153
|
+
# we don't need selects here
|
154
|
+
select_values.clear
|
155
|
+
limit(1).load
|
156
|
+
end
|
157
|
+
return @records.empty?
|
158
|
+
end
|
159
|
+
|
160
|
+
def as_json(options=nil)
|
161
|
+
to_a.as_json(options)
|
162
|
+
end
|
163
|
+
|
164
|
+
def load
|
165
|
+
@records = get_points(@instance.client.cached_query(to_sql))
|
166
|
+
@loaded = true
|
167
|
+
@records
|
148
168
|
end
|
149
169
|
|
150
170
|
def delete_all
|
@@ -185,6 +205,7 @@ module Influxer
|
|
185
205
|
self
|
186
206
|
end
|
187
207
|
|
208
|
+
|
188
209
|
protected
|
189
210
|
def build_where(args, hargs, negate)
|
190
211
|
case
|
@@ -236,11 +257,6 @@ module Influxer
|
|
236
257
|
end
|
237
258
|
end
|
238
259
|
|
239
|
-
def load
|
240
|
-
@records = get_points(@instance.client.cached_query(to_sql))
|
241
|
-
@loaded = true
|
242
|
-
end
|
243
|
-
|
244
260
|
def loaded?
|
245
261
|
@loaded
|
246
262
|
end
|
data/lib/influxer/version.rb
CHANGED
@@ -62,17 +62,16 @@ describe Influxer::Metrics do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should write successfully when all required attributes are set" do
|
65
|
-
expect(dummy_metrics.write).to
|
66
|
-
expect(dummy_metrics.persisted?).to
|
65
|
+
expect(dummy_metrics.write).to be_truthy
|
66
|
+
expect(dummy_metrics.persisted?).to be_truthy
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should raise error if you want to write twice" do
|
70
|
-
expect(dummy_metrics.write).to
|
70
|
+
expect(dummy_metrics.write).to be_truthy
|
71
71
|
expect{dummy_metrics.write!}.to raise_error(StandardError)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
75
|
describe "active_model callbacks on write" do
|
77
76
|
it "should work" do
|
78
77
|
|
@@ -158,6 +157,19 @@ describe Influxer::Metrics do
|
|
158
157
|
end
|
159
158
|
end
|
160
159
|
|
160
|
+
describe "write method" do
|
161
|
+
it "should write data and return point" do
|
162
|
+
point = DummyMetrics.write(user_id: 1, dummy_id: 2)
|
163
|
+
expect(point.persisted?).to be_truthy
|
164
|
+
expect(point.user_id).to eq 1
|
165
|
+
expect(point.dummy_id).to eq 2
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should not write data and return false" do
|
169
|
+
expect(DummyMetrics.write(dummy_id: 2)).to be false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
161
173
|
describe "all method" do
|
162
174
|
it "should respond with relation" do
|
163
175
|
expect(metrics_class.all).to be_an_instance_of Influxer::Relation
|
@@ -192,6 +192,21 @@ describe Influxer::Relation do
|
|
192
192
|
expect(rel.limit(100).to_sql).to eq "select * from \"dummy\" limit 100"
|
193
193
|
end
|
194
194
|
end
|
195
|
+
|
196
|
+
describe "empty?" do
|
197
|
+
after(:each) { Influxer.reset }
|
198
|
+
it "should return false if has points" do
|
199
|
+
Influxer.client.stub(:query) { {points: [{time: 1, id: 2}]} }
|
200
|
+
expect(rel.empty?).to be_falsey
|
201
|
+
expect(rel.present?).to be_truthy
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should return true if no points" do
|
205
|
+
Influxer.client.stub(:query) { {} }
|
206
|
+
expect(rel.empty?).to be_truthy
|
207
|
+
expect(rel.present?).to be_falsey
|
208
|
+
end
|
209
|
+
end
|
195
210
|
end
|
196
211
|
|
197
212
|
describe "delete_all" do
|
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.1.
|
4
|
+
version: 0.1.1
|
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-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.1.8
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: anyway_config
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.1'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: timecop
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|