influxer 1.1.3 → 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 (51) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +92 -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 +1 -1
  7. data/lib/influxer/config.rb +5 -4
  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 +52 -9
  12. data/lib/influxer/metrics/relation.rb +33 -19
  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 +19 -11
  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 +2 -2
  22. data/lib/influxer/version.rb +1 -1
  23. metadata +30 -95
  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 -103
  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 -425
  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
data/.gitignore DELETED
@@ -1,37 +0,0 @@
1
- # Numerous always-ignore extensions
2
- *.diff
3
- *.err
4
- *.orig
5
- *.log
6
- *.rej
7
- *.swo
8
- *.swp
9
- *.vi
10
- *~
11
- *.sass-cache
12
- *.iml
13
- .idea/
14
-
15
- # Sublime
16
- *.sublime-project
17
- *.sublime-workspace
18
-
19
- # OS or Editor folders
20
- .DS_Store
21
- .cache
22
- .project
23
- .settings
24
- .tmproj
25
- Thumbs.db
26
-
27
- .bundle/
28
- log/*.log
29
- pkg/
30
- spec/dummy/db/*.sqlite3
31
- spec/dummy/db/*.sqlite3-journal
32
- spec/dummy/tmp/
33
- tmp/
34
-
35
- Gemfile.lock
36
- Gemfile.local
37
- *.gem
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- -f d
@@ -1,77 +0,0 @@
1
- AllCops:
2
- # Include gemspec and Rakefile
3
- Include:
4
- - 'lib/**/*.rb'
5
- - 'lib/**/*.rake'
6
- - 'spec/**/*.rb'
7
- Exclude:
8
- - 'bin/**/*'
9
- - 'spec/dummy/**/*'
10
- - 'vendor/**/*'
11
- - 'gemfiles/vendor/**/*'
12
- - Gemfile
13
- - Rakefile
14
- DisplayCopNames: true
15
- StyleGuideCopsOnly: false
16
- TargetRubyVersion: 2.3
17
-
18
- Rails:
19
- Enabled: false
20
-
21
- Style/SymbolArray:
22
- Enabled: false
23
-
24
- Style/SafeNavigation:
25
- Enabled: false
26
-
27
- Naming/AccessorMethodName:
28
- Enabled: false
29
-
30
- Style/TrivialAccessors:
31
- Enabled: false
32
-
33
- Style/Documentation:
34
- Exclude:
35
- - 'spec/**/*.rb'
36
-
37
- Style/StringLiterals:
38
- Enabled: false
39
-
40
- Style/DateTime:
41
- Exclude:
42
- - 'spec/**/*.rb'
43
-
44
- Naming/SpaceInsideStringInterpolation:
45
- EnforcedStyle: no_space
46
-
47
- Style/BlockDelimiters:
48
- Exclude:
49
- - 'spec/**/*.rb'
50
-
51
- Lint/MissingCopEnableDirective:
52
- Enabled: false
53
-
54
- Lint/AmbiguousRegexpLiteral:
55
- Enabled: false
56
-
57
- Metrics/BlockLength:
58
- Exclude:
59
- - 'spec/**/*.rb'
60
-
61
- Metrics/MethodLength:
62
- Exclude:
63
- - 'spec/**/*.rb'
64
-
65
- Metrics/LineLength:
66
- Max: 100
67
- Exclude:
68
- - 'spec/**/*.rb'
69
-
70
- Rails/Date:
71
- Enabled: false
72
-
73
- Rails/TimeZone:
74
- Enabled: false
75
-
76
- Gemspec/OrderedDependencies:
77
- Enabled: false
@@ -1,10 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- matrix:
4
- include:
5
- - rvm: 2.2.1
6
- gemfile: gemfiles/rails32.gemfile
7
- - rvm: 2.3.0
8
- gemfile: gemfiles/rails42.gemfile
9
- - rvm: 2.3.1
10
- gemfile: gemfiles/rails5.gemfile
@@ -1,103 +0,0 @@
1
- # Change log
2
-
3
- ## master
4
-
5
- ## 1.1.2
6
-
7
- - Support exclusive ranges as `where` arguments. ([@MPursche][])
8
-
9
- ```ruby
10
- # range including the end
11
- where(a: 1..4)
12
- #=> ... WHERE a >= 1 AND a <= 4
13
-
14
- #range excluding the end
15
- where(a: 1...4)
16
- #=> ... WHERE a >= 1 AND a < 4
17
- ```
18
-
19
- ## 1.1.1
20
-
21
- - [Fixes [#31](https://github.com/palkan/influxer/issues/31)] Fix bug with empty arrays in `where` clause
22
-
23
- - Introduce `Relation#none` method
24
-
25
- ## 1.1.0
26
-
27
- ### Features
28
-
29
- - Add ability to specify per-metrics retention-policy, precision and database
30
-
31
- Now you can override default configuration for a specific metrics class:
32
-
33
- ```ruby
34
- class CustomMetrics < Influxer::Metrics
35
- set_database "custom_db"
36
- set_retention_policy :yearly
37
- set_precision "ms"
38
- end
39
- ```
40
-
41
- ### Fixes
42
-
43
- - [Fixes [#30](https://github.com/palkan/influxer/issues/30)] Fix writing points with custom retention policy
44
-
45
- ### Misc
46
-
47
- - Update Rubocop configuration and add Rubocop Rake task to defaults
48
-
49
- ## 1.0.1
50
-
51
- - Fix missing `#delegate` in ActiveRecord 3.2
52
-
53
- ## 0.5.4
54
- - Add `set_retention_policy` method
55
-
56
- ## 0.5.3
57
- - Fix `where.not` with ranges typo
58
-
59
- ## 0.5.2
60
- - Fix bug with query logging
61
-
62
- ## 0.5.1
63
- - Fix whitespace around operators
64
- - Add `Relation#from` method to redefine series
65
- - Handle nil values for tags in #where clause
66
-
67
- ## 0.5.0
68
- - Update `timestamp` support
69
- - Add `epoch` method
70
-
71
- ## 0.4.0
72
- - Rename default `time` attribute to `timestamp`
73
-
74
- ## 0.2.3
75
- - Parse fanout queries points to handle _fanouted_ values
76
- - Add Rubocop config and cleanup code style
77
-
78
- ## 0.1.1
79
- - Add [anyway_config](https://github.com/palkan/anyway_config)
80
- - Add `empty?` method
81
-
82
- ## 0.1.0
83
- - Add logs
84
- - Add `foreign_key` param to `has_metrics` options
85
-
86
- ## 0.1.0-rc
87
- - Fix `Relation#to_a` (now returns array of points correctrly)
88
- - Fix fanout queries with array args (now use `merge(Regexp)`)
89
-
90
- ## 0.1.0-alpha
91
- - Add `time` method to Relation to group by time with constants (`:hour`, `:day`, etc) and fill support
92
- - Series names now properly quoted with double-quotes
93
- - Using regexps, ranges and arrays within `where` clause
94
- - `where.not(...)` support
95
- - Add `past` and `since` methods
96
- - Add `merge` method and support for regexp series
97
- - Add `delete_all` support
98
- - Add cache support (using `Rails.cache`)
99
- - Scopes (default and named)
100
- - Support for fanout series
101
-
102
- [@palkan]: https://github.com/palkan
103
- [@MPursche]: https://github.com/MPursche
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- local_gemfile = 'Gemfile.local'
5
-
6
- if File.exist?(local_gemfile)
7
- eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
8
- else
9
- gem 'activerecord', '~>4.2'
10
- end
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- require "rubocop/rake_task"
7
- RuboCop::RakeTask.new
8
-
9
- task default: [:rubocop, :spec]
10
-
11
- task :console do
12
- sh 'pry -r ./lib/influxer.rb'
13
- end
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
- gem 'activerecord', '~> 3.2.22'
6
-
7
- gemspec path: '..'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
- gem 'activerecord', '~> 4.2.0'
6
-
7
- gemspec path: '..'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sqlite3', platform: :mri
4
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
- gem 'activerecord', '~> 5.0.0'
6
-
7
- gemspec path: '..'
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
4
-
5
- require "influxer/version"
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "influxer"
9
- s.version = Influxer::VERSION
10
- s.authors = ["Vlad Dem"]
11
- s.email = ["dementiev.vm@gmail.com"]
12
- s.homepage = "http://github.com/palkan/influxer"
13
- s.summary = "InfluxDB for Rails"
14
- s.description = "InfluxDB the Rails way"
15
- s.license = "MIT"
16
-
17
- s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
- s.require_paths = ["lib"]
19
-
20
- s.add_dependency "activemodel", '>= 3.2.0'
21
- s.add_dependency "influxdb", "~> 0.3"
22
- s.add_dependency "anyway_config", "~> 1.0"
23
-
24
- s.add_development_dependency "timecop"
25
- s.add_development_dependency "simplecov", ">= 0.3.8"
26
- s.add_development_dependency 'rake', '~> 10.1'
27
- s.add_development_dependency 'sqlite3'
28
- s.add_development_dependency 'activerecord', '>= 3.2.0'
29
- s.add_development_dependency 'pry-byebug'
30
- s.add_development_dependency "rspec", ">= 3.1.0"
31
- s.add_development_dependency "webmock", "~> 2.1"
32
- s.add_development_dependency "rubocop", "~> 0.52"
33
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe DummyMetrics do
6
- before do
7
- stub_request(:get, "http://localhost:8086/query")
8
- .with(
9
- query: { q: 'select * from "dummy"', u: "root", p: "root", precision: 'ns', db: 'db' }
10
- )
11
- .to_return(body: fixture_file)
12
- end
13
-
14
- context "single_series" do
15
- let(:fixture_file) { File.read('./spec/fixtures/single_series.json') }
16
-
17
- context "default format (values merged with tags)" do
18
- subject { described_class.all.to_a }
19
-
20
- it "returns array of hashes" do
21
- expect(subject.first).to include("host" => "server01", "region" => "us-west", "value" => 0.64)
22
- expect(subject.second).to include("host" => "server01", "region" => "us-west", "value" => 0.93)
23
- end
24
- end
25
- end
26
-
27
- context "empty result" do
28
- let(:fixture_file) { File.read('./spec/fixtures/empty_result.json') }
29
-
30
- subject { described_class.all.to_a }
31
-
32
- it "returns empty array" do
33
- expect(subject).to eq []
34
- end
35
- end
36
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe "Write points" do
6
- before do
7
- stub_request(:post, /write/)
8
- .to_return(
9
- status: 204
10
- )
11
- end
12
-
13
- let(:metrics_class) do
14
- Class.new(Influxer::Metrics) do
15
- set_series :test
16
-
17
- tags :user_id
18
-
19
- attributes :val
20
- end
21
- end
22
-
23
- let(:point) { 'test,user_id=1 val="2"' }
24
-
25
- subject { metrics_class.write! user_id: 1, val: '2' }
26
-
27
- it "calls HTTP with correct params" do
28
- subject
29
- expect(
30
- a_request(:post, "http://localhost:8086/write")
31
- .with(
32
- query: { u: "root", p: "root", precision: 'ns', db: 'db' },
33
- body: point
34
- )
35
- ).to have_been_made
36
- end
37
-
38
- context "with retention policy" do
39
- it "calls HTTP with correct params" do
40
- metrics_class.set_retention_policy 'yearly'
41
-
42
- subject
43
-
44
- expect(
45
- a_request(:post, "http://localhost:8086/write")
46
- .with(
47
- query: { u: "root", p: "root", precision: 'ns', db: 'db', rp: 'yearly' },
48
- body: point
49
- )
50
- ).to have_been_made
51
- end
52
- end
53
-
54
- context "with custom db" do
55
- it "calls HTTP with correct params" do
56
- metrics_class.set_database 'another_db'
57
-
58
- subject
59
-
60
- expect(
61
- a_request(:post, "http://localhost:8086/write")
62
- .with(
63
- query: { u: "root", p: "root", precision: 'ns', db: 'another_db' },
64
- body: point
65
- )
66
- ).to have_been_made
67
- end
68
- end
69
-
70
- context "with custom db" do
71
- it "calls HTTP with correct params" do
72
- metrics_class.set_precision 'ms'
73
-
74
- subject
75
-
76
- expect(
77
- a_request(:post, "http://localhost:8086/write")
78
- .with(
79
- query: { u: "root", p: "root", precision: 'ms', db: 'db' },
80
- body: point
81
- )
82
- ).to have_been_made
83
- end
84
- end
85
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Influxer::Client do
6
- let(:conf) { Influxer.config }
7
- subject { Influxer.client }
8
-
9
- describe "#initialize" do
10
- it "sets config database value" do
11
- expect(subject.config.database).to eq conf.database
12
- end
13
-
14
- it "passes config params" do
15
- conf.username = 'admin'
16
- conf.port = 2222
17
- expect(subject.config.username).to eq 'admin'
18
- expect(subject.config.port).to eq 2222
19
- end
20
- end
21
-
22
- describe "cache", :query do
23
- let(:q) { "list series" }
24
- after { Rails.cache.clear }
25
-
26
- it "writes data to cache" do
27
- conf.cache = {}
28
-
29
- subject.query(q)
30
- expect(Rails.cache.exist?("influxer:listseries")).to be_truthy
31
- end
32
-
33
- it "should write data to cache with expiration" do
34
- conf.cache = { expires_in: 90 }
35
-
36
- subject.query(q)
37
- expect(Rails.cache.exist?("influxer:listseries")).to be_truthy
38
-
39
- Timecop.travel(1.minute.from_now)
40
- expect(Rails.cache.exist?("influxer:listseries")).to be_truthy
41
-
42
- Timecop.travel(2.minutes.from_now)
43
- expect(Rails.cache.exist?("influxer:listseries")).to be_falsey
44
- end
45
- end
46
- end