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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 020023da263e0ad14394211eaab3b6388359a2ebd8de084182eeddca8b4f7569
4
- data.tar.gz: 4648019961ea24ff2132d73b7975a801f0be0270380ba003223166191c4d924d
3
+ metadata.gz: 5fa8f3e80a1c44d03d2217577611586d49e346fef552cc7545a73b39d6824a95
4
+ data.tar.gz: 990ebe156e20a28189949ad6d428188bc498cd70dd53614e777c28317609ed7e
5
5
  SHA512:
6
- metadata.gz: 3215b0bc249ad3e927f9f77dafb417c29c915c6b32f8f2342c6507b4d165f2a46b9aae82fe815ac374a2785f46c19020b6dd2688e8a208a79cc2a7e7060eb42c
7
- data.tar.gz: 70b27b50e9e98dcebde9b9ef4f16e1899c3f056770f31ece57af1c4c092a08ffa2484a4343e9c87795ffeca6b79553f9ab78a8dd431d40a75f0a2a808cf605b4
6
+ metadata.gz: fa4793fba2f7a21533ef25a18d44ea2e525878a0d5d23cdb94b87287c001b4b776e01c2aa2bd5a8ecc35fb18ec2e1841172f94bb3071f61ea00b1a5e820612d4
7
+ data.tar.gz: '09d22a2c32a82775c39503545197becfd5eda67bdd18251274770dd9e6681d06e6efd13aa84a62e08a406c8fa51b95398efdf74fb5cd2720f40751a404730258'
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.2.1 (2020-07-09)
6
+
7
+ - Support for setting timezone in queries to configure influx time calculations, e.g., time epoch aggregation ([@jklimke][])
8
+
9
+ [PR](https://github.com/palkan/influxer/pull/46)
10
+
5
11
  ## 1.2.0 (2019-05-20)
6
12
 
7
13
  - **Require Ruby 2.4+**
@@ -24,11 +30,11 @@
24
30
 
25
31
  ## 1.1.4
26
32
 
27
- - [Fixes [#35](https://github.com/palkan/influxer/issues/35)] Support time duration suffix and handle `'s'` and `'ms'` precisions. ([@palkan][])
33
+ - [Fixes [#35](https://github.com/palkan/influxer/issues/35)] Support time duration suffix and handle `'s'` and `'ms'` precision. ([@palkan][])
28
34
 
29
35
  [PR](https://github.com/palkan/influxer/pull/36)
30
36
 
31
- **BREAKING:** `Time`-like value are only typecasted for `time` key.
37
+ **BREAKING:** `Time`-like value are only type-casted for `time` key.
32
38
 
33
39
  ## 1.1.2
34
40
 
@@ -78,54 +84,7 @@ end
78
84
 
79
85
  - Fix missing `#delegate` in ActiveRecord 3.2
80
86
 
81
- ## 0.5.4
82
- - Add `set_retention_policy` method
83
-
84
- ## 0.5.3
85
- - Fix `where.not` with ranges typo
86
-
87
- ## 0.5.2
88
- - Fix bug with query logging
89
-
90
- ## 0.5.1
91
- - Fix whitespace around operators
92
- - Add `Relation#from` method to redefine series
93
- - Handle nil values for tags in #where clause
94
-
95
- ## 0.5.0
96
- - Update `timestamp` support
97
- - Add `epoch` method
98
-
99
- ## 0.4.0
100
- - Rename default `time` attribute to `timestamp`
101
-
102
- ## 0.2.3
103
- - Parse fanout queries points to handle _fanouted_ values
104
- - Add Rubocop config and cleanup code style
105
-
106
- ## 0.1.1
107
- - Add [anyway_config](https://github.com/palkan/anyway_config)
108
- - Add `empty?` method
109
-
110
- ## 0.1.0
111
- - Add logs
112
- - Add `foreign_key` param to `has_metrics` options
113
-
114
- ## 0.1.0-rc
115
- - Fix `Relation#to_a` (now returns array of points correctrly)
116
- - Fix fanout queries with array args (now use `merge(Regexp)`)
117
-
118
- ## 0.1.0-alpha
119
- - Add `time` method to Relation to group by time with constants (`:hour`, `:day`, etc) and fill support
120
- - Series names now properly quoted with double-quotes
121
- - Using regexps, ranges and arrays within `where` clause
122
- - `where.not(...)` support
123
- - Add `past` and `since` methods
124
- - Add `merge` method and support for regexp series
125
- - Add `delete_all` support
126
- - Add cache support (using `Rails.cache`)
127
- - Scopes (default and named)
128
- - Support for fanout series
87
+ See [changelog](https://github.com/palkan/influxer/blob/1.0.0/Changelog.md) for earlier versions.
129
88
 
130
89
  [@palkan]: https://github.com/palkan
131
90
  [@MPursche]: https://github.com/MPursche
@@ -1,4 +1,4 @@
1
- Copyright 2014-2019 palkan
1
+ Copyright 2014-2020 Vladimir Dementyev
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,37 +1,88 @@
1
- [![Gem Version](https://badge.fury.io/rb/influxer.svg)](https://rubygems.org/gems/influxer) [![Build Status](https://travis-ci.org/palkan/influxer.svg?branch=master)](https://travis-ci.org/palkan/influxer) [![Dependency Status](https://dependencyci.com/github/palkan/influxer/badge)](https://dependencyci.com/github/palkan/influxer)
2
- ## Influxer
1
+ ![Build](https://github.com/palkan/influxer/workflows/Build/badge.svg)
3
2
 
4
- **NOTE**: Version 0.3.x supports InfluxDB >= 0.9.0. For InfluxDB 0.8.x use [version 0.2.5](https://github.com/palkan/influxer/tree/0.2.5).
5
-
6
- **NOTE**: Influxer is Rails 4+ compatible! (Rails 3.2 support is still included but no longer required to pass all the tests).
3
+ # Influxer
7
4
 
8
5
  Influxer provides an ActiveRecord-style way to work with [InfluxDB](https://influxdb.com/) with many useful features, such as:
9
- - Familar query language (use `select`, `where`, `not`, `group` etc).
10
- - Support for Regex conditions: `where(page_id: /^home\/.*/) #=> select * ... where page_id=~/^home\/.*/`.
11
- - Special query methods for InfluxDB:
12
- - `time` - group by time (e.g. `Metrics.time(:hour) => # select * ... group by time(1h)`);
13
- - `past` - get only points for last hour/minute/whatever (e.g. `Metrics.past(:day) => # select * ... where time > now() - 1d`);
14
- - `since` - get only points since date (e.g. `Metrics.since(Time.utc(2014,12,31)) => # select * ... where time > 1419984000s`);
15
- - `merge` - merge series.
16
- - Scopes support
17
- ```ruby
6
+
7
+ ## Installation
8
+
9
+ Adding to a gem:
10
+
11
+ ```ruby
12
+ # my-cool-gem.gemspec
13
+ Gem::Specification.new do |spec|
14
+ # ...
15
+ spec.add_dependency "influxer", ">= 1.2.0"
16
+ # ...
17
+ end
18
+ ```
19
+
20
+ Or adding to your project:
21
+
22
+ ```ruby
23
+ # Gemfile
24
+ gem "influxer", "~> 1.2"
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Metrics classes
30
+
31
+ To query InfluxDB or write to it, you should define a metrics class first. Each metrics class represents a measurement/series (or multiple related measurements):
32
+
33
+ ```ruby
34
+ class VisitsMetrics < Influxer::Metrics
35
+ # Define tags...
36
+ tags :account_id, :page_id
37
+ # ...and attributes
38
+ attributes :user_id, :browser
39
+ end
40
+ ```
41
+
42
+ ### Querying
43
+
44
+ Now you can use your metrics classes in a similar way to Active Record models to build queries. For example:
45
+
46
+ ```ruby
47
+ VisitsMetrics.select(:account_id, :user_id).where(page_id: /^home\/.*/)
48
+ ```
49
+
50
+ Influxer provides special query methods for dealing with time series:
51
+
52
+ - Group by time: `Metrics.time(:hour) => # select * ... group by time(1h)`.
53
+ - Select only points for the last hour/minute/whatever: `Metrics.past(:day) => # select * ... where time > now() - 1d`.
54
+ - Select only points since the specified time: `Metrics.since(Time.utc(2014,12,31)) => # select * ... where time > 1419984000s`.
55
+ - and more.
56
+
57
+ See [our Wiki](https://github.com/palkan/influxer/wiki/Query-methods) for more.
58
+
59
+ ### Scopes support
60
+
61
+ You can define scopes to re-use query conditions:
62
+
63
+ ```ruby
18
64
  class Metrics < Influxer::Metrics
19
- default_scope -> { time(:hour).limit(1000) }
20
65
  tags :account_id
21
66
  attributes :value
67
+
68
+ default_scope -> { time(:hour).limit(1000) }
69
+
22
70
  scope :unlimited, -> { limit(nil) }
23
71
  scope :by_account, ->(id) { where(account_id: id) if id.present? }
24
72
  end
25
73
 
26
74
  Metrics.by_account(1)
27
- # => select * from "metrics" group by time(1h) where account_id=1 limit 1000
75
+ # => select * from "metrics" group by time(1h) where account_id=1 limit 1000
28
76
 
29
77
  Metrics.unlimited.by_account(1).time(:week)
30
- # => select * from "metrics" group by time(1w) where account_id=1
78
+ # => select * from "metrics" group by time(1w) where account_id=1
79
+ ```
80
+
81
+ ### Active Record integration
31
82
 
32
- ```
33
- - Integrate with your model:
34
- ```ruby
83
+ You can association metrics with Active Record models:
84
+
85
+ ```ruby
35
86
  class UserVisits < Influxer::Metrics
36
87
  end
37
88
 
@@ -41,10 +92,18 @@ end
41
92
 
42
93
  user = User.find(1)
43
94
  user.visits.write(page_id: "home")
44
- #=> < creates point {user_id: 1, page_id: 'home'} in 'user_visits' series >
95
+ #=> < creates point {user_id: 1, page_id: 'home'} in 'user_visits' series >
45
96
 
46
97
  user.visits.where(page_id: "home")
47
- #=> select * from user_visits where page_id='home'
48
- ```
98
+ #=> select * from user_visits where page_id='home'
99
+ ```
100
+
101
+ Find more on [Wiki](https://github.com/palkan/influxer/wiki/ActiveRecord-integration).
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/palkan/influxer](https://github.com/palkan/influxer).
106
+
107
+ ## License
49
108
 
50
- Find more on [Wiki](https://github.com/palkan/influxer/wiki).
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -33,7 +33,7 @@ module Influxer
33
33
  [
34
34
  :write, :write!, :select, :where,
35
35
  :group, :time, :past, :since,
36
- :limit, :offset, :fill, :delete_all, :epoch
36
+ :limit, :offset, :fill, :delete_all, :epoch, :timezone
37
37
  ] + Influxer::Calculations::CALCULATION_METHODS
38
38
  ),
39
39
  to: :all
@@ -22,11 +22,11 @@ module Influxer
22
22
 
23
23
  MULTI_KEY_METHODS = %i[fanout].freeze
24
24
 
25
- SINGLE_VALUE_METHODS = %i[fill time limit offset slimit soffset from normalized].freeze
25
+ SINGLE_VALUE_METHODS = %i[fill time limit offset slimit soffset from normalized timezone].freeze
26
26
 
27
27
  MULTI_VALUE_SIMPLE_METHODS = %i[select group].freeze
28
28
 
29
- SINGLE_VALUE_SIMPLE_METHODS = %i[fill limit offset slimit soffset from].freeze
29
+ SINGLE_VALUE_SIMPLE_METHODS = %i[fill limit offset slimit soffset from timezone].freeze
30
30
 
31
31
  MULTI_VALUE_METHODS.each do |name|
32
32
  class_eval <<-CODE, __FILE__, __LINE__ + 1
@@ -121,6 +121,13 @@ module Influxer
121
121
  self
122
122
  end
123
123
 
124
+ def timezone(val)
125
+ return self if val.blank?
126
+
127
+ @values[:timezone] = val
128
+ self
129
+ end
130
+
124
131
  def order(val)
125
132
  case val
126
133
  when Hash
@@ -159,6 +166,7 @@ module Influxer
159
166
  sql << "offset #{offset_value}" unless offset_value.nil?
160
167
  sql << "slimit #{slimit_value}" unless slimit_value.nil?
161
168
  sql << "soffset #{soffset_value}" unless soffset_value.nil?
169
+ sql << "TZ('#{timezone_value}')" unless timezone_value.blank?
162
170
  sql.join " "
163
171
  end
164
172
  # rubocop:enable Metrics/AbcSize
@@ -205,7 +213,11 @@ module Influxer
205
213
  end
206
214
 
207
215
  def delete_all
208
- sql = ["drop series"]
216
+ sql = if where_contains_time?
217
+ ["delete"]
218
+ else
219
+ ["drop series"]
220
+ end
209
221
 
210
222
  sql << "from #{@instance.series}"
211
223
 
@@ -104,5 +104,11 @@ module Influxer
104
104
  @null_relation = !negate
105
105
  negate ? "time >= 0" : "time < 0"
106
106
  end
107
+
108
+ def where_contains_time?
109
+ where_values.any? do |where_clause|
110
+ /time( )/ === where_clause
111
+ end
112
+ end
107
113
  end
108
114
  end
@@ -33,7 +33,7 @@ module Influxer
33
33
  # of config.cache if defined
34
34
  def cache_options(sql = nil)
35
35
  options = Influxer.config.cache.dup
36
- options[:expires_in] = (options[:cache_now_for] || 60) if sql =~ /\snow\(\)/
36
+ options[:expires_in] = (options[:cache_now_for] || 60) if /\snow\(\)/.match?(sql)
37
37
  options
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Influxer # :nodoc:
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Dem
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-21 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -143,21 +143,9 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".gitignore"
147
- - ".rspec"
148
- - ".rubocop.yml"
149
- - ".travis.yml"
150
- - Changelog.md
151
- - Gemfile
152
- - MIT-LICENSE
146
+ - CHANGELOG.md
147
+ - LICENSE.txt
153
148
  - README.md
154
- - Rakefile
155
- - bin/console
156
- - gemfiles/rails32.gemfile
157
- - gemfiles/rails42.gemfile
158
- - gemfiles/rails5.gemfile
159
- - gemfiles/rails6.gemfile
160
- - influxer.gemspec
161
149
  - lib/influxer.rb
162
150
  - lib/influxer/client.rb
163
151
  - lib/influxer/config.rb
@@ -177,24 +165,6 @@ files:
177
165
  - lib/influxer/model.rb
178
166
  - lib/influxer/rails/client.rb
179
167
  - lib/influxer/version.rb
180
- - spec/cases/points_spec.rb
181
- - spec/cases/write_points_spec.rb
182
- - spec/client_spec.rb
183
- - spec/fixtures/empty_result.json
184
- - spec/fixtures/single_series.json
185
- - spec/metrics/metrics_spec.rb
186
- - spec/metrics/relation_spec.rb
187
- - spec/metrics/scoping_spec.rb
188
- - spec/model/user_spec.rb
189
- - spec/spec_helper.rb
190
- - spec/support/metrics/action_metrics.rb
191
- - spec/support/metrics/custom_metrics.rb
192
- - spec/support/metrics/dummy_metrics.rb
193
- - spec/support/metrics/user_metrics.rb
194
- - spec/support/metrics/visits_metrics.rb
195
- - spec/support/shared_contexts/shared_precision.rb
196
- - spec/support/shared_contexts/shared_query.rb
197
- - spec/support/user.rb
198
168
  homepage: http://github.com/palkan/influxer
199
169
  licenses:
200
170
  - MIT
@@ -204,7 +174,7 @@ metadata:
204
174
  documentation_uri: http://github.com/palkan/influxer
205
175
  homepage_uri: http://github.com/palkan/influxer
206
176
  source_code_uri: http://github.com/palkan/influxer
207
- post_install_message:
177
+ post_install_message:
208
178
  rdoc_options: []
209
179
  require_paths:
210
180
  - lib
@@ -219,8 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
189
  - !ruby/object:Gem::Version
220
190
  version: '0'
221
191
  requirements: []
222
- rubygems_version: 3.0.3
223
- signing_key:
192
+ rubygems_version: 3.1.2
193
+ signing_key:
224
194
  specification_version: 4
225
195
  summary: InfluxDB for Rails
226
196
  test_files: []
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