influxer 1.1.3 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +92 -0
- data/{MIT-LICENSE → LICENSE.txt} +1 -1
- data/README.md +106 -47
- data/lib/influxer.rb +10 -9
- data/lib/influxer/client.rb +1 -1
- data/lib/influxer/config.rb +5 -4
- data/lib/influxer/engine.rb +1 -1
- data/lib/influxer/metrics/active_model3/model.rb +2 -4
- data/lib/influxer/metrics/metrics.rb +10 -13
- data/lib/influxer/metrics/quoting/timestamp.rb +52 -9
- data/lib/influxer/metrics/relation.rb +33 -19
- data/lib/influxer/metrics/relation/calculations.rb +1 -1
- data/lib/influxer/metrics/relation/time_query.rb +15 -13
- data/lib/influxer/metrics/relation/where_clause.rb +19 -11
- data/lib/influxer/metrics/scoping.rb +4 -4
- data/lib/influxer/metrics/scoping/current_scope.rb +2 -1
- data/lib/influxer/metrics/scoping/default.rb +1 -1
- data/lib/influxer/metrics/scoping/named.rb +2 -1
- data/lib/influxer/model.rb +4 -9
- data/lib/influxer/rails/client.rb +2 -2
- data/lib/influxer/version.rb +1 -1
- metadata +30 -95
- data/.gitignore +0 -37
- data/.rspec +0 -2
- data/.rubocop.yml +0 -77
- data/.travis.yml +0 -10
- data/Changelog.md +0 -103
- data/Gemfile +0 -10
- data/Rakefile +0 -13
- data/gemfiles/rails32.gemfile +0 -7
- data/gemfiles/rails42.gemfile +0 -7
- data/gemfiles/rails5.gemfile +0 -7
- data/influxer.gemspec +0 -33
- data/spec/cases/points_spec.rb +0 -36
- data/spec/cases/write_points_spec.rb +0 -85
- data/spec/client_spec.rb +0 -46
- data/spec/fixtures/empty_result.json +0 -21
- data/spec/fixtures/single_series.json +0 -29
- data/spec/metrics/metrics_spec.rb +0 -283
- data/spec/metrics/relation_spec.rb +0 -425
- data/spec/metrics/scoping_spec.rb +0 -66
- data/spec/model/user_spec.rb +0 -46
- data/spec/spec_helper.rb +0 -64
- data/spec/support/metrics/action_metrics.rb +0 -5
- data/spec/support/metrics/custom_metrics.rb +0 -6
- data/spec/support/metrics/dummy_metrics.rb +0 -12
- data/spec/support/metrics/user_metrics.rb +0 -6
- data/spec/support/metrics/visits_metrics.rb +0 -8
- data/spec/support/shared_contexts/shared_query.rb +0 -16
- 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
|
data/spec/model/user_spec.rb
DELETED
@@ -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
|
data/spec/spec_helper.rb
DELETED
@@ -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,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,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
|
data/spec/support/user.rb
DELETED
@@ -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
|