influxer 1.2.0 → 1.2.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/{Changelog.md → CHANGELOG.md} +9 -50
  3. data/{MIT-LICENSE → LICENSE.txt} +1 -1
  4. data/README.md +83 -24
  5. data/lib/influxer/metrics/metrics.rb +1 -1
  6. data/lib/influxer/metrics/relation.rb +15 -3
  7. data/lib/influxer/metrics/relation/where_clause.rb +6 -0
  8. data/lib/influxer/rails/client.rb +1 -1
  9. data/lib/influxer/version.rb +1 -1
  10. metadata +8 -38
  11. data/.gitignore +0 -37
  12. data/.rspec +0 -2
  13. data/.rubocop.yml +0 -57
  14. data/.travis.yml +0 -15
  15. data/Gemfile +0 -13
  16. data/Rakefile +0 -15
  17. data/bin/console +0 -8
  18. data/gemfiles/rails32.gemfile +0 -7
  19. data/gemfiles/rails42.gemfile +0 -7
  20. data/gemfiles/rails5.gemfile +0 -7
  21. data/gemfiles/rails6.gemfile +0 -7
  22. data/influxer.gemspec +0 -40
  23. data/spec/cases/points_spec.rb +0 -36
  24. data/spec/cases/write_points_spec.rb +0 -85
  25. data/spec/client_spec.rb +0 -46
  26. data/spec/fixtures/empty_result.json +0 -21
  27. data/spec/fixtures/single_series.json +0 -29
  28. data/spec/metrics/metrics_spec.rb +0 -329
  29. data/spec/metrics/relation_spec.rb +0 -467
  30. data/spec/metrics/scoping_spec.rb +0 -66
  31. data/spec/model/user_spec.rb +0 -46
  32. data/spec/spec_helper.rb +0 -63
  33. data/spec/support/metrics/action_metrics.rb +0 -5
  34. data/spec/support/metrics/custom_metrics.rb +0 -6
  35. data/spec/support/metrics/dummy_metrics.rb +0 -12
  36. data/spec/support/metrics/user_metrics.rb +0 -6
  37. data/spec/support/metrics/visits_metrics.rb +0 -8
  38. data/spec/support/shared_contexts/shared_precision.rb +0 -19
  39. data/spec/support/shared_contexts/shared_query.rb +0 -16
  40. 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,63 +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
- require "rspec"
9
- require "webmock/rspec"
10
-
11
- begin
12
- require "pry-byebug"
13
- rescue LoadError # rubocop:disable Lint/HandleExceptions
14
- end
15
-
16
- require "timecop"
17
-
18
- require "active_record"
19
- require "sqlite3"
20
-
21
- require "influxer"
22
-
23
- # Rails stub
24
- class Rails
25
- class << self
26
- def cache
27
- @cache ||= ActiveSupport::Cache::MemoryStore.new
28
- end
29
-
30
- def logger
31
- @logger ||= Logger.new(nil)
32
- end
33
-
34
- def env
35
- "test"
36
- end
37
- end
38
- end
39
-
40
- require "influxer/rails/client"
41
-
42
- ActiveRecord::Base.send :include, Influxer::Model
43
-
44
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
45
-
46
- Dir["#{File.dirname(__FILE__)}/support/metrics/*.rb"].each { |f| require f }
47
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
48
-
49
- WebMock.disable_net_connect!
50
-
51
- RSpec.configure do |config|
52
- config.mock_with :rspec
53
-
54
- config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
55
- config.filter_run :focus
56
- config.run_all_when_everything_filtered = true
57
-
58
- config.order = :random
59
- Kernel.srand config.seed
60
-
61
- config.after(:each) { Influxer.reset! }
62
- config.after(:each) { Timecop.return }
63
- 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,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_context "precision:seconds", precision: :s do
4
- around do |ex|
5
- old_precision = Influxer.config.time_precision
6
- Influxer.config.time_precision = "s"
7
- ex.run
8
- Influxer.config.time_precision = old_precision
9
- end
10
- end
11
-
12
- shared_context "with_duration_suffix", duration_suffix: true do
13
- around do |ex|
14
- old_duration = Influxer.config.time_duration_suffix_enabled
15
- Influxer.config.time_duration_suffix_enabled = true
16
- ex.run
17
- Influxer.config.time_duration_suffix_enabled = old_duration
18
- end
19
- 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