influxer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.travis.yml +21 -0
  4. data/Gemfile +16 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +15 -0
  7. data/Rakefile +6 -0
  8. data/gemfiles/rails40.gemfile +7 -0
  9. data/gemfiles/rails41.gemfile +7 -0
  10. data/influxer.gemspec +27 -0
  11. data/lib/influxer/client.rb +9 -0
  12. data/lib/influxer/config.rb +47 -0
  13. data/lib/influxer/engine.rb +12 -0
  14. data/lib/influxer/metrics/metrics.rb +95 -0
  15. data/lib/influxer/metrics/relation.rb +143 -0
  16. data/lib/influxer/model.rb +33 -0
  17. data/lib/influxer/version.rb +3 -0
  18. data/lib/influxer.rb +31 -0
  19. data/lib/tasks/influxer_tasks.rake +4 -0
  20. data/spec/client_spec.rb +14 -0
  21. data/spec/config_spec.rb +18 -0
  22. data/spec/dummy/README.rdoc +28 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  26. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  28. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/mailers/.keep +0 -0
  31. data/spec/dummy/app/metrics/testo_metrics.rb +3 -0
  32. data/spec/dummy/app/models/.keep +0 -0
  33. data/spec/dummy/app/models/concerns/.keep +0 -0
  34. data/spec/dummy/app/models/testo.rb +4 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/bin/bundle +3 -0
  37. data/spec/dummy/bin/rails +4 -0
  38. data/spec/dummy/bin/rake +4 -0
  39. data/spec/dummy/config/application.rb +23 -0
  40. data/spec/dummy/config/boot.rb +5 -0
  41. data/spec/dummy/config/database.yml +25 -0
  42. data/spec/dummy/config/environment.rb +5 -0
  43. data/spec/dummy/config/environments/development.rb +37 -0
  44. data/spec/dummy/config/environments/production.rb +83 -0
  45. data/spec/dummy/config/environments/test.rb +39 -0
  46. data/spec/dummy/config/influxdb.yml +5 -0
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  49. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/spec/dummy/config/initializers/inflections.rb +16 -0
  51. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  52. data/spec/dummy/config/initializers/session_store.rb +3 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/spec/dummy/config/locales/en.yml +23 -0
  55. data/spec/dummy/config/routes.rb +56 -0
  56. data/spec/dummy/config/secrets.yml +25 -0
  57. data/spec/dummy/config.ru +4 -0
  58. data/spec/dummy/db/migrate/20140730133818_add_testos.rb +11 -0
  59. data/spec/dummy/db/migrate/20140731162044_add_column_to_testos.rb +5 -0
  60. data/spec/dummy/db/schema.rb +22 -0
  61. data/spec/dummy/db/test.sqlite3 +0 -0
  62. data/spec/dummy/lib/assets/.keep +0 -0
  63. data/spec/dummy/log/.keep +0 -0
  64. data/spec/dummy/public/404.html +67 -0
  65. data/spec/dummy/public/422.html +67 -0
  66. data/spec/dummy/public/500.html +66 -0
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/metrics/metrics_spec.rb +133 -0
  69. data/spec/metrics/relation_spec.rb +78 -0
  70. data/spec/model/testo_spec.rb +18 -0
  71. data/spec/spec_helper.rb +23 -0
  72. data/spec/support/dummy_metrics.rb +7 -0
  73. metadata +205 -0
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxer::Metrics do
4
+
5
+ let(:metrics) { Influxer::Metrics.new }
6
+ let(:metrics_class) { Influxer::Metrics }
7
+
8
+
9
+ # class methods
10
+
11
+ specify {expect(metrics_class).to respond_to :attributes}
12
+ specify {expect(metrics_class).to respond_to :set_series}
13
+ specify {expect(metrics_class).to respond_to :series}
14
+
15
+ # query methods
16
+
17
+ specify { expect(metrics_class).to respond_to :all}
18
+ specify { expect(metrics_class).to respond_to :where}
19
+ specify { expect(metrics_class).to respond_to :group}
20
+ specify { expect(metrics_class).to respond_to :limit}
21
+ specify { expect(metrics_class).to respond_to :select}
22
+ specify { expect(metrics_class).to respond_to :delete_all}
23
+
24
+ # instance methods
25
+
26
+ specify { expect(metrics).to respond_to :write }
27
+ specify { expect(metrics).to respond_to :write! }
28
+ specify { expect(metrics).to respond_to :persisted? }
29
+ specify { expect(metrics).to respond_to :series}
30
+
31
+
32
+ # ActiveModel::Validations
33
+
34
+ specify { expect(metrics).to respond_to :valid? }
35
+ specify { expect(metrics).to respond_to :invalid? }
36
+ specify { expect(metrics).to respond_to :errors }
37
+
38
+
39
+
40
+ describe "instance methods" do
41
+
42
+ let(:dummy_metrics) { DummyMetrics.new dummy_id: 1, user_id: 1}
43
+
44
+ describe "write method" do
45
+
46
+ it "should not write if required attribute is missing" do
47
+ m = DummyMetrics.new(dummy_id: 1)
48
+ expect(m.write).to be false
49
+ expect(m.errors.size).to eq(1)
50
+ end
51
+
52
+ it "should raise error if required attribute is missing" do
53
+ expect{DummyMetrics.new(user_id: 1).write!}.to raise_error(StandardError)
54
+ end
55
+
56
+ it "should write successfully when all required attributes are set" do
57
+ expect(dummy_metrics.write).to be true
58
+ expect(dummy_metrics.persisted?).to be true
59
+ end
60
+
61
+ it "should raise error if you want to write twice" do
62
+ expect(dummy_metrics.write).to be true
63
+ expect{dummy_metrics.write!}.to raise_error(StandardError)
64
+ end
65
+ end
66
+
67
+
68
+ describe "active_model callbacks on write" do
69
+ it "should work" do
70
+
71
+ Timecop.freeze(Time.local(2014,10,10,10,10,10)) do
72
+ dummy_metrics.write!
73
+ end
74
+
75
+ expect(dummy_metrics.time).to eq Time.local(2014,10,10,10,10,10)
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ describe "class methods" do
82
+
83
+ let(:dummy_metrics) do
84
+ Class.new(Influxer::Metrics) do
85
+ set_series :dummies
86
+ end
87
+ end
88
+
89
+ let(:dummy_with_2_series) do
90
+ Class.new(Influxer::Metrics) do
91
+ set_series :events, :errors
92
+ end
93
+ end
94
+
95
+ let(:dummy_with_proc_series) do
96
+ Class.new(Influxer::Metrics) do
97
+ attributes :user_id, :test_id
98
+ set_series ->(metrics) { "test/#{metrics.test_id}/user/#{metrics.user_id}"}
99
+ end
100
+ end
101
+
102
+
103
+
104
+ describe "set_series" do
105
+ it "should set series name from class name by default" do
106
+ expect(DummyMetrics.series).to eq 'dummy'
107
+ end
108
+
109
+ it "should set series from subclass" do
110
+ expect(dummy_metrics.series).to eq 'dummies'
111
+ end
112
+
113
+ it "should set several series" do
114
+ expect(dummy_with_2_series.series).to eq 'events,errors'
115
+ end
116
+
117
+
118
+ it "should set series from proc" do
119
+ expect(dummy_with_proc_series.series).to be_an_instance_of Proc
120
+
121
+ m = dummy_with_proc_series.new user_id: 2, test_id:123
122
+ expect(dummy_with_proc_series.series.call(m)).to eq "test/123/user/2"
123
+ end
124
+ end
125
+
126
+ describe "all method" do
127
+ it "should respond with relation" do
128
+ expect(metrics_class.all).to be_an_instance_of Influxer::Relation
129
+ end
130
+ end
131
+
132
+ end
133
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxer::Relation do
4
+ let(:rel) { Influxer::Relation.new DummyMetrics}
5
+
6
+ specify { expect(rel).to respond_to :write}
7
+ specify { expect(rel).to respond_to :build}
8
+
9
+ # read
10
+ specify { expect(rel).to respond_to :select }
11
+ specify { expect(rel).to respond_to :where }
12
+ specify { expect(rel).to respond_to :limit }
13
+ specify { expect(rel).to respond_to :group }
14
+
15
+ #delete
16
+ specify { expect(rel).to respond_to :delete_all }
17
+
18
+ specify { expect(rel).to respond_to :to_sql }
19
+
20
+
21
+ describe "sql generation" do
22
+ describe "select" do
23
+ it "should select array of symbols" do
24
+ expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id,dummy_id from dummy"
25
+ end
26
+
27
+ it "should select string" do
28
+ expect(rel.select("count(user_id)").to_sql).to eq "select count(user_id) from dummy"
29
+ end
30
+ end
31
+
32
+ describe "where" do
33
+ it "should generate valid conditions from hash" do
34
+ Timecop.freeze(Time.now) do
35
+ expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from dummy where (user_id=1) and (dummy='q') and (timer=#{Time.now.to_i}s)"
36
+ end
37
+ end
38
+
39
+ it "should generate valid conditions from strings" do
40
+ expect(rel.where("time > now() - 1d").to_sql).to eq "select * from dummy where (time > now() - 1d)"
41
+ end
42
+ end
43
+
44
+ describe "group" do
45
+ it "should generate valid groups" do
46
+ expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from dummy group by user_id,time(1m) fill(0)"
47
+ end
48
+ end
49
+
50
+ describe "limit" do
51
+ it "should generate valid limi" do
52
+ expect(rel.limit(100).to_sql).to eq "select * from dummy limit 100"
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "inspect" do
58
+
59
+ after(:each) do
60
+ Influxer.reset
61
+ end
62
+
63
+ it "should return correct String represantation of empty relation" do
64
+ Influxer.client.stub(:query) { [] }
65
+ expect(rel.inspect).to eq "#<Influxer::Relation []>"
66
+ end
67
+
68
+ it "should return correct String represantation of non-empty relation" do
69
+ Influxer.client.stub(:query){ [1,2,3] }
70
+ expect(rel.inspect).to eq "#<Influxer::Relation [1, 2, 3]>"
71
+ end
72
+
73
+ it "should return correct String represantation of non-empty large (>11) relation" do
74
+ Influxer.client.stub(:query){ [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]}
75
+ expect(rel.inspect).to eq "#<Influxer::Relation [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]>"
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Testo do
5
+ let(:testo) { Testo.new receipt_id: 10}
6
+ specify { expect(testo).to respond_to :metrics }
7
+ specify { expect(testo).to respond_to :testo_metrics }
8
+
9
+ describe "metrics attributes" do
10
+
11
+ it "should add foreign key and inherits" do
12
+ expect(testo.metrics.build.testo_id).to eq testo.id
13
+ expect(testo.testo_metrics.build.testo_id).to eq testo.id
14
+ expect(testo.testo_metrics.build.receipt_id).to eq 10
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ # require 'simplecov'
7
+ # SimpleCov.root File.join(File.dirname(__FILE__), '..', 'lib')
8
+ # SimpleCov.start
9
+
10
+ require 'rspec'
11
+
12
+ require 'rails/all'
13
+ require 'rspec/rails'
14
+ require 'timecop'
15
+
16
+ require "dummy/config/environment"
17
+
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_with :rspec
22
+ config.use_transactional_fixtures = true
23
+ end
@@ -0,0 +1,7 @@
1
+ class DummyMetrics < Influxer::Metrics
2
+ attributes :dummy_id, :user_id
3
+
4
+ validates_presence_of :dummy_id, :user_id
5
+
6
+ before_write ->{ self.time = DateTime.now }
7
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: influxer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Dem
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: influxdb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.8
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.0
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.8
47
+ - !ruby/object:Gem::Dependency
48
+ name: timecop
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: simplecov
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.8
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.8
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: 3.0.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec-rails
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 3.0.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.0
103
+ description: InfluxDB the Rails way
104
+ email:
105
+ - dementiev.vm@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - .travis.yml
112
+ - Gemfile
113
+ - MIT-LICENSE
114
+ - README.md
115
+ - Rakefile
116
+ - gemfiles/rails40.gemfile
117
+ - gemfiles/rails41.gemfile
118
+ - influxer.gemspec
119
+ - lib/influxer.rb
120
+ - lib/influxer/client.rb
121
+ - lib/influxer/config.rb
122
+ - lib/influxer/engine.rb
123
+ - lib/influxer/metrics/metrics.rb
124
+ - lib/influxer/metrics/relation.rb
125
+ - lib/influxer/model.rb
126
+ - lib/influxer/version.rb
127
+ - lib/tasks/influxer_tasks.rake
128
+ - spec/client_spec.rb
129
+ - spec/config_spec.rb
130
+ - spec/dummy/README.rdoc
131
+ - spec/dummy/Rakefile
132
+ - spec/dummy/app/assets/images/.keep
133
+ - spec/dummy/app/assets/javascripts/application.js
134
+ - spec/dummy/app/assets/stylesheets/application.css
135
+ - spec/dummy/app/controllers/application_controller.rb
136
+ - spec/dummy/app/controllers/concerns/.keep
137
+ - spec/dummy/app/helpers/application_helper.rb
138
+ - spec/dummy/app/mailers/.keep
139
+ - spec/dummy/app/metrics/testo_metrics.rb
140
+ - spec/dummy/app/models/.keep
141
+ - spec/dummy/app/models/concerns/.keep
142
+ - spec/dummy/app/models/testo.rb
143
+ - spec/dummy/app/views/layouts/application.html.erb
144
+ - spec/dummy/bin/bundle
145
+ - spec/dummy/bin/rails
146
+ - spec/dummy/bin/rake
147
+ - spec/dummy/config.ru
148
+ - spec/dummy/config/application.rb
149
+ - spec/dummy/config/boot.rb
150
+ - spec/dummy/config/database.yml
151
+ - spec/dummy/config/environment.rb
152
+ - spec/dummy/config/environments/development.rb
153
+ - spec/dummy/config/environments/production.rb
154
+ - spec/dummy/config/environments/test.rb
155
+ - spec/dummy/config/influxdb.yml
156
+ - spec/dummy/config/initializers/backtrace_silencers.rb
157
+ - spec/dummy/config/initializers/cookies_serializer.rb
158
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
159
+ - spec/dummy/config/initializers/inflections.rb
160
+ - spec/dummy/config/initializers/mime_types.rb
161
+ - spec/dummy/config/initializers/session_store.rb
162
+ - spec/dummy/config/initializers/wrap_parameters.rb
163
+ - spec/dummy/config/locales/en.yml
164
+ - spec/dummy/config/routes.rb
165
+ - spec/dummy/config/secrets.yml
166
+ - spec/dummy/db/migrate/20140730133818_add_testos.rb
167
+ - spec/dummy/db/migrate/20140731162044_add_column_to_testos.rb
168
+ - spec/dummy/db/schema.rb
169
+ - spec/dummy/db/test.sqlite3
170
+ - spec/dummy/lib/assets/.keep
171
+ - spec/dummy/log/.keep
172
+ - spec/dummy/public/404.html
173
+ - spec/dummy/public/422.html
174
+ - spec/dummy/public/500.html
175
+ - spec/dummy/public/favicon.ico
176
+ - spec/metrics/metrics_spec.rb
177
+ - spec/metrics/relation_spec.rb
178
+ - spec/model/testo_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/support/dummy_metrics.rb
181
+ homepage: http://github.com/palkan/influxer
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.4.1
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: InfluxDB support for Rails
205
+ test_files: []