influxdb-client 2.1.0.pre.3441 → 2.2.0.pre.4244

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bd4863b65a77e9132d6e1592907cc2ed74cdc66de156ac474d7ff12955814e6
4
- data.tar.gz: c3fece1432f2d88abd392a52b3ff7315e5054c21c0f765e18799e5937c183bde
3
+ metadata.gz: a0dd61b35e7f884f78c34dc811322b5729752c29326b227cc490cefd51e74a8a
4
+ data.tar.gz: 67fa3056a29be235d4403f03af55fa2f13263935064886a88a9baaad5d513a51
5
5
  SHA512:
6
- metadata.gz: 49e160aaa1e8fbb689f83bb7d2f8f495b51adea1a90f8de05da2d3243ed68c4097ed3a3c61f53520f208e61e1eccab78cb42593834fd31dc5d43ed65b4756119
7
- data.tar.gz: de77bfe938248e8a7963c6d5fc5b48f31c1833baf50f291f5c30128919852692c635a74b7785245eae375320d192f1188efb9135813b2a7bd9b429990bc0bcb3
6
+ metadata.gz: a67ea2c94cb86793664c997de39552c63ab9f6b0591368ac574788e00efb11ce6ea837f71e2e8e7dc596c213a62124512848fdd0b076b9581e16ecfb08694c63
7
+ data.tar.gz: fa8e865d6838ea8498ac4b76bc936d5712173b48e7bb815652a62f94fa233582206cd2bffd77f1689a8bbd7d03f30f55b2c4efff2bb06cf18fadcc0c99b87df4
data/CHANGELOG.md CHANGED
@@ -1,7 +1,19 @@
1
- ## 2.1.0 [unreleased]
1
+ ## 2.2.0 [unreleased]
2
+
3
+ ### Features
4
+ 1. [#96](https://github.com/influxdata/influxdb-client-ruby/pull/96): Add support for Parameterized Queries
5
+
6
+ ### Documentation
7
+ 1. [#96](https://github.com/influxdata/influxdb-client-ruby/pull/96): Add Parameterized Queries example
8
+
9
+ ## 2.1.0 [2021-10-22]
10
+
11
+ ### Features
12
+ 1. [#93](https://github.com/influxdata/influxdb-client-ruby/pull/93): Add `PingApi` to check status of OSS and Cloud instance
2
13
 
3
14
  ### CI
4
15
  1. [#91](https://github.com/influxdata/influxdb-client-ruby/pull/91): Switch to next-gen CircleCI's convenience images
16
+ 1. [#95](https://github.com/influxdata/influxdb-client-ruby/pull/95): Update `jruby` to `9.3.1.0-jdk11`
5
17
 
6
18
  ## 2.0.0 [2021-09-13]
7
19
 
data/README.md CHANGED
@@ -64,13 +64,13 @@ The client can be installed manually or with bundler.
64
64
  To install the client gem manually:
65
65
 
66
66
  ```
67
- gem install influxdb-client -v 2.0.0
67
+ gem install influxdb-client -v 2.1.0
68
68
  ```
69
69
 
70
70
  For management API:
71
71
 
72
72
  ```
73
- gem install influxdb-client-apis -v 2.0.0
73
+ gem install influxdb-client-apis -v 2.1.0
74
74
  ```
75
75
 
76
76
  ## Usage
@@ -152,6 +152,33 @@ query_api.query_stream(query: query).each do |record|
152
152
  end
153
153
  ```
154
154
 
155
+ #### Parameterized queries
156
+ InfluxDB Cloud supports [Parameterized Queries](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/)
157
+ that let you dynamically change values in a query using the InfluxDB API. Parameterized queries make Flux queries more
158
+ reusable and can also be used to help prevent injection attacks.
159
+
160
+ InfluxDB Cloud inserts the params object into the Flux query as a Flux record named `params`. Use dot or bracket
161
+ notation to access parameters in the `params` record in your Flux query. Parameterized Flux queries support only `int`
162
+ , `float`, and `string` data types. To convert the supported data types into
163
+ other [Flux basic data types, use Flux type conversion functions](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/#supported-parameter-data-types).
164
+
165
+ Parameterized query example:
166
+ > :warning: Parameterized Queries are supported only in InfluxDB Cloud, currently there is no support in InfluxDB OSS.
167
+
168
+ ```ruby
169
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
170
+ bucket: 'my-bucket',
171
+ org: 'my-org')
172
+
173
+ query = 'from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam))'
174
+ params = { 'bucketParam' => 'my-bucket', 'startParam' => '-1h' }
175
+
176
+ query_api = client.create_query_api
177
+ result = query_api.query(query: query, params: params)
178
+
179
+ result[0].records.each { |record| puts "#{record.time} #{record.measurement}: #{record.field} #{record.value}" }
180
+ ```
181
+
155
182
  ### Writing data
156
183
  The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.0. In default api uses synchronous write. To enable batching you can use WriteOption.
157
184
 
@@ -400,7 +427,7 @@ client.close!
400
427
 
401
428
  ### Check the server status
402
429
 
403
- Server availability can be checked using the `client.health` method. That is equivalent of the [influx ping](https://v2.docs.influxdata.com/v2.0/reference/cli/influx/ping/).
430
+ Server availability can be checked using the `client.ping` method. That is equivalent of the [influx ping](https://v2.docs.influxdata.com/v2.0/reference/cli/influx/ping/).
404
431
 
405
432
  ### Proxy configuration
406
433
 
@@ -26,6 +26,7 @@ require 'influxdb2/client/write_api'
26
26
  require 'influxdb2/client/query_api'
27
27
  require 'influxdb2/client/delete_api'
28
28
  require 'influxdb2/client/health_api'
29
+ require 'influxdb2/client/ping_api'
29
30
  require 'influxdb2/client/point'
30
31
  require 'influxdb2/client/flux_table'
31
32
  require 'influxdb2/client/write_retry'
@@ -87,11 +87,20 @@ module InfluxDB2
87
87
 
88
88
  # Get the health of an instance.
89
89
  #
90
+ # @deprecated Use `ping` instead
90
91
  # @return [HealthCheck]
91
92
  def health
92
93
  HealthApi.new(options: @options).health
93
94
  end
94
95
 
96
+ # Checks the status of InfluxDB instance and version of InfluxDB.
97
+ #
98
+ # @deprecated Use `ping` instead
99
+ # @return [Ping]
100
+ def ping
101
+ PingApi.new(options: @options).ping
102
+ end
103
+
95
104
  # Close all connections into InfluxDB 2.
96
105
  #
97
106
  # @return [ true ] Always true.
@@ -22,6 +22,7 @@ require_relative 'models/health_check'
22
22
  module InfluxDB2
23
23
  # The client of the InfluxDB 2.0 that implement Health HTTP API endpoint.
24
24
  #
25
+ # @deprecated Use `PingApi` instead
25
26
  class HealthApi < DefaultApi
26
27
  # @param [Hash] options The options to be used by the client.
27
28
  def initialize(options:)
@@ -1,7 +1,7 @@
1
1
  =begin
2
- #Influx OSS API Service
2
+ #InfluxDB OSS API Service
3
3
 
4
- #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ #The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint.
5
5
 
6
6
  The version of the OpenAPI document: 2.0.0
7
7
 
@@ -24,6 +24,9 @@ module InfluxDB2
24
24
  # The type of query. Must be \"flux\".
25
25
  attr_reader :type
26
26
 
27
+ # Enumeration of key/value pairs that respresent parameters to be injected into query (can only specify either this field or extern and not both)
28
+ attr_accessor :params
29
+
27
30
  attr_accessor :dialect
28
31
 
29
32
  # Specifies the time that should be reported as \"now\" in the query. Default is the server's now time.
@@ -57,6 +60,7 @@ module InfluxDB2
57
60
  :'extern' => :'extern',
58
61
  :'query' => :'query',
59
62
  :'type' => :'type',
63
+ :'params' => :'params',
60
64
  :'dialect' => :'dialect',
61
65
  :'now' => :'now',
62
66
  }
@@ -68,6 +72,7 @@ module InfluxDB2
68
72
  :'extern' => :'File',
69
73
  :'query' => :'String',
70
74
  :'type' => :'String',
75
+ :'params' => :'Hash<String, Object>',
71
76
  :'dialect' => :'Dialect',
72
77
  :'now' => :'Time'
73
78
  }
@@ -106,6 +111,12 @@ module InfluxDB2
106
111
  self.type = attributes[:'type']
107
112
  end
108
113
 
114
+ if attributes.key?(:'params')
115
+ if (value = attributes[:'params']).is_a?(Hash)
116
+ self.params = value
117
+ end
118
+ end
119
+
109
120
  if attributes.key?(:'dialect')
110
121
  self.dialect = attributes[:'dialect']
111
122
  end
@@ -153,6 +164,7 @@ module InfluxDB2
153
164
  extern == o.extern &&
154
165
  query == o.query &&
155
166
  type == o.type &&
167
+ params == o.params &&
156
168
  dialect == o.dialect &&
157
169
  now == o.now
158
170
  end
@@ -166,7 +178,7 @@ module InfluxDB2
166
178
  # Calculates hash code according to all attributes.
167
179
  # @return [Integer] Hash code
168
180
  def hash
169
- [extern, query, type, dialect, now].hash
181
+ [extern, query, type, params, dialect, now].hash
170
182
  end
171
183
 
172
184
  # Builds the object from hash
@@ -0,0 +1,65 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ require_relative 'models/health_check'
21
+
22
+ module InfluxDB2
23
+ # The client of the InfluxDB 2.0 that implement Ping HTTP API endpoint.
24
+ #
25
+ class PingApi < DefaultApi
26
+ # @param [Hash] options The options to be used by the client.
27
+ def initialize(options:)
28
+ super(options: options)
29
+ end
30
+
31
+ # Checks the status of InfluxDB instance and version of InfluxDB.
32
+ #
33
+ # @return [Ping]
34
+ def ping
35
+ uri = _parse_uri('/ping')
36
+ headers = _get(uri)
37
+ Ping.new.tap do |model|
38
+ model.status = 'ok'
39
+ model.build = headers['X-Influxdb-Build']
40
+ model.version = headers['X-Influxdb-Version']
41
+ model.message = 'ready for queries and writes'
42
+ end
43
+ rescue StandardError => e
44
+ Ping.new.tap do |model|
45
+ model.status = 'fail'
46
+ model.message = e.message
47
+ end
48
+ end
49
+ end
50
+
51
+ # The status of InfluxDB instance and version of InfluxDB.
52
+ class Ping
53
+ # The type of InfluxDB build.
54
+ attr_accessor :build
55
+
56
+ # The version of InfluxDB.
57
+ attr_accessor :version
58
+
59
+ # The status of InfluxDB.
60
+ attr_accessor :status
61
+
62
+ # The error message.
63
+ attr_accessor :message
64
+ end
65
+ end
@@ -36,16 +36,18 @@ module InfluxDB2
36
36
 
37
37
  # @param [Object] query the flux query to execute. The data could be represent by [String], [Query]
38
38
  # @param [String] org specifies the source organization
39
+ # @param [Enumerable] params represent key/value pairs parameters to be injected into query
39
40
  # @return [String] result of query
40
- def query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT)
41
- _post_query(query: query, org: org, dialect: dialect).read_body
41
+ def query_raw(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
42
+ _post_query(query: query, org: org, dialect: dialect, params: params).read_body
42
43
  end
43
44
 
44
45
  # @param [Object] query the flux query to execute. The data could be represent by [String], [Query]
45
46
  # @param [String] org specifies the source organization
47
+ # @param [Enumerable] params represent key/value pairs parameters to be injected into query
46
48
  # @return [Array] list of FluxTables which are matched the query
47
- def query(query: nil, org: nil, dialect: DEFAULT_DIALECT)
48
- response = query_raw(query: query, org: org, dialect: dialect)
49
+ def query(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
50
+ response = query_raw(query: query, org: org, dialect: dialect, params: params)
49
51
  parser = InfluxDB2::FluxCsvParser.new(response)
50
52
 
51
53
  parser.parse
@@ -54,20 +56,21 @@ module InfluxDB2
54
56
 
55
57
  # @param [Object] query the flux query to execute. The data could be represent by [String], [Query]
56
58
  # @param [String] org specifies the source organization
59
+ # @param [Enumerable] params represent key/value pairs parameters to be injected into query
57
60
  # @return stream of Flux Records
58
- def query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT)
59
- response = _post_query(query: query, org: org, dialect: dialect)
61
+ def query_stream(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
62
+ response = _post_query(query: query, org: org, dialect: dialect, params: params)
60
63
 
61
64
  InfluxDB2::FluxCsvParser.new(response, stream: true)
62
65
  end
63
66
 
64
67
  private
65
68
 
66
- def _post_query(query: nil, org: nil, dialect: DEFAULT_DIALECT)
69
+ def _post_query(query: nil, org: nil, dialect: DEFAULT_DIALECT, params: nil)
67
70
  org_param = org || @options[:org]
68
71
  _check('org', org_param)
69
72
 
70
- payload = _generate_payload(query, dialect)
73
+ payload = _generate_payload(query: query, dialect: dialect, params: params)
71
74
  return nil if payload.nil?
72
75
 
73
76
  uri = _parse_uri('/api/v2/query')
@@ -76,16 +79,17 @@ module InfluxDB2
76
79
  _post_json(payload.to_body.to_json, uri)
77
80
  end
78
81
 
79
- def _generate_payload(query, dialect)
82
+ def _generate_payload(query: nil, dialect: nil, params: nil)
80
83
  if query.nil?
81
84
  nil
82
85
  elsif query.is_a?(Query)
86
+ query.params = params unless params.nil?
83
87
  query
84
88
  elsif query.is_a?(String)
85
89
  if query.empty?
86
90
  nil
87
91
  else
88
- Query.new(query: query, dialect: dialect, type: nil)
92
+ Query.new(query: query, dialect: dialect, type: nil, params: params)
89
93
  end
90
94
  end
91
95
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB2
22
- VERSION = '2.1.0'.freeze
22
+ VERSION = '2.2.0'.freeze
23
23
  end
@@ -90,6 +90,26 @@ class ClientTest < Minitest::Test
90
90
  assert_equal 'fail', health.status
91
91
  end
92
92
 
93
+ def test_ping
94
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token', use_ssl: false)
95
+
96
+ ping = client.ping
97
+ assert_equal 'ready for queries and writes', ping.message
98
+ assert_equal 'OSS, oss2', ping.build
99
+ assert_equal 'ok', ping.status
100
+ refute_empty ping.version
101
+ end
102
+
103
+ def test_ping_not_running
104
+ client_not_running = InfluxDB2::Client.new('http://localhost:8099', 'my-token', use_ssl: false)
105
+ ping = client_not_running.ping
106
+
107
+ assert_match 'Failed to open TCP connection to localhost:8099', ping.message
108
+ assert_equal 'fail', ping.status
109
+ assert_nil ping.build
110
+ assert_nil ping.version
111
+ end
112
+
93
113
  def test_trailing_slash_in_url
94
114
  uri = URI.parse(File.join('http://localhost:8099', '/api/v2/write'))
95
115
  assert_equal 'http://localhost:8099/api/v2/write', uri.to_s
@@ -49,6 +49,27 @@ class QueryApiTest < MiniTest::Test
49
49
  assert_equal result, SUCCESS_DATA
50
50
  end
51
51
 
52
+ def test_parameterized_query_raw
53
+ body = '{"query":"from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam)) |> last()",' \
54
+ '"params":{"bucketParam":"my-bucket","startParam":"1970-01-01T00:00:00.000000001Z"},' \
55
+ '"dialect":{"header":true,"delimiter":",","annotations":["datatype","group","default"],' \
56
+ '"commentPrefix":"#","dateTimeFormat":"RFC3339"}}'
57
+ stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
58
+ .with(body: body)
59
+ .to_return(body: SUCCESS_DATA)
60
+
61
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
62
+ bucket: 'my-bucket',
63
+ org: 'my-org',
64
+ use_ssl: false)
65
+
66
+ query = 'from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam)) |> last()'
67
+ params = Hash['bucketParam' => 'my-bucket', 'startParam' => '1970-01-01T00:00:00.000000001Z']
68
+ result = client.create_query_api.query_raw(query: query, params: params)
69
+
70
+ assert_equal result, SUCCESS_DATA
71
+ end
72
+
52
73
  def test_query
53
74
  stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
54
75
  .to_return(body: SUCCESS_DATA)
@@ -73,6 +94,36 @@ class QueryApiTest < MiniTest::Test
73
94
  assert_equal 'free', record1.field
74
95
  end
75
96
 
97
+ def test_parameterized_query
98
+ body = '{"query":"from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam)) |> last()",' \
99
+ '"params":{"bucketParam":"my-bucket","startParam":"1970-01-01T00:00:00.000000001Z"},' \
100
+ '"dialect":{"header":true,"delimiter":",","annotations":["datatype","group","default"],' \
101
+ '"commentPrefix":"#","dateTimeFormat":"RFC3339"}}'
102
+ stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
103
+ .with(body: body)
104
+ .to_return(body: SUCCESS_DATA)
105
+
106
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
107
+ bucket: 'my-bucket',
108
+ org: 'my-org',
109
+ use_ssl: false)
110
+
111
+ query = 'from(bucket: params.bucketParam) |> range(start: duration(v: params.startParam)) |> last()'
112
+ params = Hash['bucketParam' => 'my-bucket', 'startParam' => '1970-01-01T00:00:00.000000001Z']
113
+
114
+ result = client.create_query_api.query(query: query, params: params)
115
+
116
+ assert_equal 1, result.length
117
+ assert_equal 4, result[0].records.length
118
+
119
+ record1 = result[0].records[0]
120
+
121
+ assert_equal Time.parse('1970-01-01T00:00:10Z').to_datetime.rfc3339(9), record1.time
122
+ assert_equal 'mem', record1.measurement
123
+ assert_equal 10, record1.value
124
+ assert_equal 'free', record1.field
125
+ end
126
+
76
127
  def test_headers
77
128
  stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
78
129
  .to_return(body: SUCCESS_DATA)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.pre.3441
4
+ version: 2.2.0.pre.4244
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,6 +146,7 @@ files:
146
146
  - lib/influxdb2/client/models/dialect.rb
147
147
  - lib/influxdb2/client/models/health_check.rb
148
148
  - lib/influxdb2/client/models/query.rb
149
+ - lib/influxdb2/client/ping_api.rb
149
150
  - lib/influxdb2/client/point.rb
150
151
  - lib/influxdb2/client/query_api.rb
151
152
  - lib/influxdb2/client/version.rb
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  - !ruby/object:Gem::Version
189
190
  version: 1.3.1
190
191
  requirements: []
191
- rubygems_version: 3.2.22
192
+ rubygems_version: 3.2.32
192
193
  signing_key:
193
194
  specification_version: 4
194
195
  summary: Ruby library for InfluxDB 2.