influxer 1.1.5 → 1.3.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -0
  3. data/{MIT-LICENSE → LICENSE.txt} +1 -1
  4. data/README.md +106 -47
  5. data/lib/influxer.rb +10 -9
  6. data/lib/influxer/client.rb +2 -2
  7. data/lib/influxer/config.rb +19 -6
  8. data/lib/influxer/engine.rb +1 -1
  9. data/lib/influxer/metrics/active_model3/model.rb +2 -4
  10. data/lib/influxer/metrics/metrics.rb +10 -13
  11. data/lib/influxer/metrics/quoting/timestamp.rb +23 -11
  12. data/lib/influxer/metrics/relation.rb +33 -17
  13. data/lib/influxer/metrics/relation/calculations.rb +1 -1
  14. data/lib/influxer/metrics/relation/time_query.rb +15 -13
  15. data/lib/influxer/metrics/relation/where_clause.rb +15 -7
  16. data/lib/influxer/metrics/scoping.rb +4 -4
  17. data/lib/influxer/metrics/scoping/current_scope.rb +2 -1
  18. data/lib/influxer/metrics/scoping/default.rb +1 -1
  19. data/lib/influxer/metrics/scoping/named.rb +2 -1
  20. data/lib/influxer/model.rb +4 -9
  21. data/lib/influxer/rails/client.rb +6 -6
  22. data/lib/influxer/version.rb +1 -1
  23. metadata +32 -97
  24. data/.gitignore +0 -37
  25. data/.rspec +0 -2
  26. data/.rubocop.yml +0 -77
  27. data/.travis.yml +0 -10
  28. data/Changelog.md +0 -116
  29. data/Gemfile +0 -10
  30. data/Rakefile +0 -13
  31. data/gemfiles/rails32.gemfile +0 -7
  32. data/gemfiles/rails42.gemfile +0 -7
  33. data/gemfiles/rails5.gemfile +0 -7
  34. data/influxer.gemspec +0 -33
  35. data/spec/cases/points_spec.rb +0 -36
  36. data/spec/cases/write_points_spec.rb +0 -85
  37. data/spec/client_spec.rb +0 -46
  38. data/spec/fixtures/empty_result.json +0 -21
  39. data/spec/fixtures/single_series.json +0 -29
  40. data/spec/metrics/metrics_spec.rb +0 -283
  41. data/spec/metrics/relation_spec.rb +0 -485
  42. data/spec/metrics/scoping_spec.rb +0 -66
  43. data/spec/model/user_spec.rb +0 -46
  44. data/spec/spec_helper.rb +0 -64
  45. data/spec/support/metrics/action_metrics.rb +0 -5
  46. data/spec/support/metrics/custom_metrics.rb +0 -6
  47. data/spec/support/metrics/dummy_metrics.rb +0 -12
  48. data/spec/support/metrics/user_metrics.rb +0 -6
  49. data/spec/support/metrics/visits_metrics.rb +0 -8
  50. data/spec/support/shared_contexts/shared_query.rb +0 -16
  51. data/spec/support/user.rb +0 -16
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Influxer::Metrics, :query do
6
- let(:klass) do
7
- Class.new(Influxer::Metrics) do
8
- set_series 'dummy'
9
- end
10
- end
11
-
12
- let(:dummy) do
13
- Class.new(klass) do
14
- default_scope -> { time(:hour) }
15
- end
16
- end
17
-
18
- let(:dappy) do
19
- Class.new(dummy) do
20
- default_scope -> { limit(100) }
21
- end
22
- end
23
-
24
- let(:doomy) do
25
- Class.new(dappy) do
26
- scope :by_user, ->(id) { where(user_id: id) if id.present? }
27
- scope :hourly, -> { time(:hour) }
28
- scope :daily, -> { time(:day) }
29
- end
30
- end
31
-
32
- describe "default scope" do
33
- it "works without default scope" do
34
- expect(klass.all.to_sql).to eq "select * from \"dummy\""
35
- end
36
-
37
- it "works with default scope" do
38
- expect(dummy.all.to_sql).to eq "select * from \"dummy\" group by time(1h)"
39
- end
40
-
41
- it "works with unscoped" do
42
- expect(dummy.unscoped.to_sql).to eq "select * from \"dummy\""
43
- end
44
-
45
- it "works with several defaults" do
46
- expect(dappy.where(user_id: 1).to_sql)
47
- .to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
48
- end
49
- end
50
-
51
- describe "named scope" do
52
- it "works with named scope" do
53
- expect(doomy.by_user(1).to_sql)
54
- .to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
55
- end
56
-
57
- it "works with named scope with empty relation" do
58
- expect(doomy.by_user(nil).to_sql).to eq "select * from \"dummy\" group by time(1h) limit 100"
59
- end
60
-
61
- it "works with several scopes" do
62
- expect(doomy.where(dummy_id: 100).by_user([1, 2, 3]).daily.to_sql)
63
- .to eq "select * from \"dummy\" where (dummy_id = 100) and (user_id = 1 or user_id = 2 or user_id = 3) group by time(1d) limit 100"
64
- end
65
- end
66
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe User do
6
- let(:user) { described_class.create age: 20, gender: 1, email: 'user@example.com' }
7
- subject { user }
8
-
9
- specify { is_expected.to respond_to :metrics }
10
- specify { is_expected.to respond_to :visits_metrics }
11
- specify { is_expected.to respond_to :action_metrics }
12
- specify { is_expected.to respond_to :custom_metrics }
13
-
14
- describe "#metrics" do
15
- subject { user.metrics.new }
16
-
17
- it "add foreign key" do
18
- expect(subject.user_id).to eq user.id
19
- end
20
- end
21
-
22
- describe "#visits_metrics" do
23
- subject { user.visits_metrics.new }
24
-
25
- it "adds inherited attributes" do
26
- expect(subject.age).to eq 20
27
- expect(subject.gender).to eq 1
28
- end
29
- end
30
-
31
- describe "#action_metrics" do
32
- subject { user.action_metrics.new }
33
-
34
- it "adds custom foreign key" do
35
- expect(subject.user).to eq user.id
36
- end
37
- end
38
-
39
- describe "#custom_metrics" do
40
- subject { user.custom_metrics.new }
41
-
42
- it "doesn't add foreign key" do
43
- expect(subject.user_id).to be_nil
44
- end
45
- end
46
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
-
6
- ENV["RAILS_ENV"] ||= 'test'
7
-
8
- if ENV['COVER']
9
- require 'simplecov'
10
- SimpleCov.root File.join(File.dirname(__FILE__), '..')
11
- SimpleCov.start
12
- end
13
-
14
- require 'rspec'
15
- require "webmock/rspec"
16
- require 'pry-byebug'
17
- require 'timecop'
18
-
19
- require 'active_record'
20
- require 'sqlite3'
21
-
22
- require "influxer"
23
-
24
- # Rails stub
25
- class Rails
26
- class << self
27
- def cache
28
- @cache ||= ActiveSupport::Cache::MemoryStore.new
29
- end
30
-
31
- def logger
32
- @logger ||= Logger.new(nil)
33
- end
34
-
35
- def env
36
- 'test'
37
- end
38
- end
39
- end
40
-
41
- require "influxer/rails/client"
42
-
43
- ActiveRecord::Base.send :include, Influxer::Model
44
-
45
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
46
-
47
- Dir["#{File.dirname(__FILE__)}/support/metrics/*.rb"].each { |f| require f }
48
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
49
-
50
- WebMock.disable_net_connect!
51
-
52
- RSpec.configure do |config|
53
- config.mock_with :rspec
54
-
55
- config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
56
- config.filter_run :focus
57
- config.run_all_when_everything_filtered = true
58
-
59
- config.order = :random
60
- Kernel.srand config.seed
61
-
62
- config.after(:each) { Influxer.reset! }
63
- config.after(:each) { Timecop.return }
64
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ActionMetrics < Influxer::Metrics
4
- tags :user, :action
5
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CustomMetrics < Influxer::Metrics
4
- tags :code, :user_id
5
- attributes :val
6
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class DummyMetrics < Influxer::Metrics # :nodoc:
4
- tags :dummy_id, :host
5
- attributes :user_id
6
-
7
- validates_presence_of :dummy_id, :user_id
8
-
9
- before_write -> { self.timestamp = Time.now }
10
-
11
- scope :calc, ->(method, *args) { send(method, *args) }
12
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class UserMetrics < Influxer::Metrics
4
- tags :user_id
5
- attributes :time_spent
6
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class VisitsMetrics < Influxer::Metrics
4
- set_retention_policy :yearly
5
-
6
- tags :user_id, :gender
7
- attributes :age, :page
8
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_context "stub_query", :query do
4
- let(:client) { Influxer.client }
5
-
6
- before do
7
- # Stub all query methods
8
- allow_any_instance_of(InfluxDB::Client).to receive(:query) do |_, sql|
9
- sql
10
- end
11
-
12
- allow_any_instance_of(InfluxDB::Client).to receive(:time_precision)
13
-
14
- allow_any_instance_of(InfluxDB::Client).to receive(:post)
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Schema.define do
4
- create_table :users do |t|
5
- t.string :email
6
- t.integer :age
7
- t.integer :gender
8
- end
9
- end
10
-
11
- class User < ActiveRecord::Base
12
- has_metrics
13
- has_metrics :visits_metrics, class_name: "VisitsMetrics", inherits: [:gender, :age]
14
- has_metrics :action_metrics, class_name: "ActionMetrics", foreign_key: :user
15
- has_metrics :custom_metrics, class_name: "CustomMetrics", foreign_key: nil
16
- end