pinot-client 1.4.0 → 1.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 828dd3e3c441143fb0754adbcb1b50de4a070e777ad3a158c51dfabf91a3f877
4
- data.tar.gz: 6c4a3f0ae7e703ae0d3ff18fd473030710e5a1954b9624207e0b2c6e944d2365
3
+ metadata.gz: 2ea9db0f69b7fb8d963190553d6a92201f4d63d5d6a07a975f862d00e43aa30a
4
+ data.tar.gz: c3b968737e6b7650c57bb79ef42153eb6870df22521939f885e5332fe4a2b7eb
5
5
  SHA512:
6
- metadata.gz: ca183a5d10a9b87a18cb61725e6810f1446cd70b627e6a6a8320a3db9b2ec27981bf7d282e684f2c2cca94c2a87be2fb1595c2c178d378465bb77628cf501bb7
7
- data.tar.gz: 715e0acb71c456409c999da0207c4c2c1aac310d27024dae6d9154996811d51b1f4c665686b609d598128b031f766ae06ee18c111c6ef0f6801b69cd523b5c82
6
+ metadata.gz: b5809f8a9245ff2b13cd6a487499aff37ad9f879d4c5537570f61b1c34da6fe702817bb3ced5d6c812f8b38b9283bafb1bb3a16f2ae1f9279436e9cf86f274ae
7
+ data.tar.gz: 78c2573048ced129a60d9186092acba394456304cc343f1fca56cce1fa0bc8e3417c8748b3bd50a97f6dcd5f05f32caaf2c0f2a12e153e5685876e06aa033f31
data/README.md CHANGED
@@ -277,6 +277,10 @@ Environment variables:
277
277
  | `BROKER_HOST` | `127.0.0.1` | Pinot broker hostname |
278
278
  | `BROKER_PORT` | `8000` | Pinot broker HTTP port |
279
279
 
280
+ ## Changelog
281
+
282
+ See [CHANGELOG.md](CHANGELOG.md) for a full history of releases.
283
+
280
284
  ## License
281
285
 
282
286
  Apache License 2.0 — see [LICENSE](LICENSE).
data/lib/pinot/config.rb CHANGED
@@ -20,23 +20,26 @@ module Pinot
20
20
  end
21
21
 
22
22
  class ClientConfig
23
- attr_accessor :broker_list, :http_timeout, :extra_http_header,
23
+ attr_accessor :broker_list, :http_timeout, :query_timeout_ms, :extra_http_header,
24
24
  :use_multistage_engine, :controller_config, :logger, :tls_config,
25
- :grpc_config, :zookeeper_config
25
+ :grpc_config, :zookeeper_config, :query_timeout_ms
26
26
 
27
27
  def initialize(
28
28
  broker_list: [],
29
29
  http_timeout: nil,
30
+ query_timeout_ms: nil,
30
31
  extra_http_header: {},
31
32
  use_multistage_engine: false,
32
33
  controller_config: nil,
33
34
  logger: nil,
34
35
  tls_config: nil,
35
36
  grpc_config: nil,
36
- zookeeper_config: nil
37
+ zookeeper_config: nil,
38
+ query_timeout_ms: nil
37
39
  )
38
40
  @broker_list = broker_list
39
41
  @http_timeout = http_timeout
42
+ @query_timeout_ms = query_timeout_ms
40
43
  @extra_http_header = extra_http_header
41
44
  @use_multistage_engine = use_multistage_engine
42
45
  @controller_config = controller_config
@@ -44,6 +47,30 @@ module Pinot
44
47
  @tls_config = tls_config
45
48
  @grpc_config = grpc_config
46
49
  @zookeeper_config = zookeeper_config
50
+ @query_timeout_ms = query_timeout_ms
51
+ end
52
+
53
+ def validate!
54
+ sources = [
55
+ !broker_list.empty?,
56
+ !controller_config.nil?,
57
+ !zookeeper_config.nil?,
58
+ !grpc_config.nil?
59
+ ].count(true)
60
+
61
+ if sources == 0
62
+ raise ConfigurationError, "ClientConfig requires at least one of: broker_list, controller_config, zookeeper_config, or grpc_config"
63
+ end
64
+
65
+ if !http_timeout.nil? && http_timeout <= 0
66
+ raise ConfigurationError, "http_timeout must be positive, got: #{http_timeout}"
67
+ end
68
+
69
+ if !query_timeout_ms.nil? && query_timeout_ms <= 0
70
+ raise ConfigurationError, "query_timeout_ms must be positive, got: #{query_timeout_ms}"
71
+ end
72
+
73
+ self
47
74
  end
48
75
  end
49
76
  end
@@ -2,12 +2,15 @@ require "bigdecimal"
2
2
 
3
3
  module Pinot
4
4
  class Connection
5
- def initialize(transport:, broker_selector:, use_multistage_engine: false, logger: nil)
5
+ attr_accessor :query_timeout_ms
6
+
7
+ def initialize(transport:, broker_selector:, use_multistage_engine: false, logger: nil, query_timeout_ms: nil)
6
8
  @transport = transport
7
9
  @broker_selector = broker_selector
8
10
  @use_multistage_engine = use_multistage_engine
9
11
  @trace = false
10
12
  @logger = logger
13
+ @query_timeout_ms = query_timeout_ms
11
14
  end
12
15
 
13
16
  def use_multistage_engine=(val)
@@ -23,9 +26,19 @@ module Pinot
23
26
  end
24
27
 
25
28
  def execute_sql(table, query)
26
- logger.debug "Executing SQL on table=#{table}: #{query}"
29
+ Pinot::Instrumentation.instrument(table: table, query: query) do
30
+ logger.debug "Executing SQL on table=#{table}: #{query}"
31
+ broker = @broker_selector.select_broker(table)
32
+ @transport.execute(broker, build_request(query))
33
+ end
34
+ rescue => e
35
+ raise "unable to execute SQL on table #{table}: #{e.message}"
36
+ end
37
+
38
+ def execute_sql_with_timeout(table, query, timeout_ms)
39
+ logger.debug "Executing SQL with timeout=#{timeout_ms}ms on table=#{table}: #{query}"
27
40
  broker = @broker_selector.select_broker(table)
28
- @transport.execute(broker, build_request(query))
41
+ @transport.execute(broker, build_request(query, timeout_ms: timeout_ms))
29
42
  rescue => e
30
43
  raise "unable to execute SQL on table #{table}: #{e.message}"
31
44
  end
@@ -93,8 +106,8 @@ module Pinot
93
106
  @logger || Pinot::Logging.logger
94
107
  end
95
108
 
96
- def build_request(query)
97
- Request.new("sql", query, @trace, @use_multistage_engine)
109
+ def build_request(query, timeout_ms: @query_timeout_ms)
110
+ Request.new("sql", query, @trace, @use_multistage_engine, timeout_ms)
98
111
  end
99
112
  end
100
113
  end
@@ -12,6 +12,8 @@ module Pinot
12
12
  end
13
13
 
14
14
  def self.from_config(config, http_client: nil)
15
+ config.validate!
16
+
15
17
  if config.grpc_config
16
18
  transport = GrpcTransport.new(config.grpc_config)
17
19
  selector = SimpleBrokerSelector.new(config.grpc_config.broker_list)
@@ -61,7 +63,8 @@ module Pinot
61
63
  transport: transport,
62
64
  broker_selector: selector,
63
65
  use_multistage_engine: config.use_multistage_engine || false,
64
- logger: config.logger
66
+ logger: config.logger,
67
+ query_timeout_ms: config.query_timeout_ms
65
68
  )
66
69
 
67
70
  selector.init
@@ -0,0 +1,36 @@
1
+ module Pinot
2
+ module Instrumentation
3
+ # Called around every query execution.
4
+ # Implement by setting Pinot::Instrumentation.on_query = proc { |event| ... }
5
+ # event is a Hash:
6
+ # :table => String
7
+ # :query => String
8
+ # :duration_ms => Float
9
+ # :success => Boolean
10
+ # :error => Exception or nil
11
+
12
+ def self.on_query=(callback)
13
+ @on_query = callback
14
+ end
15
+
16
+ def self.on_query
17
+ @on_query
18
+ end
19
+
20
+ def self.instrument(table:, query:)
21
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
22
+ result = yield
23
+ duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000
24
+ notify(table: table, query: query, duration_ms: duration_ms, success: true, error: nil)
25
+ result
26
+ rescue => e
27
+ duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000
28
+ notify(table: table, query: query, duration_ms: duration_ms, success: false, error: e)
29
+ raise
30
+ end
31
+
32
+ def self.notify(event)
33
+ @on_query&.call(event)
34
+ end
35
+ end
36
+ end
data/lib/pinot/request.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pinot
2
- Request = Struct.new(:query_format, :query, :trace, :use_multistage_engine)
2
+ Request = Struct.new(:query_format, :query, :trace, :use_multistage_engine, :query_timeout_ms)
3
3
  end
@@ -170,6 +170,7 @@ module Pinot
170
170
  if @timeout_ms && @timeout_ms > 0
171
171
  parts << "timeoutMs=#{@timeout_ms}"
172
172
  end
173
+ parts << "timeoutMs=#{request.query_timeout_ms}" if request.query_timeout_ms
173
174
  end
174
175
  parts.join(";")
175
176
  end
data/lib/pinot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pinot
2
- VERSION = "1.4.0"
2
+ VERSION = "1.6.0"
3
3
  end
data/lib/pinot.rb CHANGED
@@ -5,6 +5,7 @@ require "bigdecimal"
5
5
  require "securerandom"
6
6
 
7
7
  require_relative "pinot/errors"
8
+ require_relative "pinot/instrumentation"
8
9
  require_relative "pinot/version"
9
10
  require_relative "pinot/logger"
10
11
  require_relative "pinot/config"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinot-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiang Fu
@@ -84,6 +84,7 @@ files:
84
84
  - lib/pinot/errors.rb
85
85
  - lib/pinot/grpc_config.rb
86
86
  - lib/pinot/grpc_transport.rb
87
+ - lib/pinot/instrumentation.rb
87
88
  - lib/pinot/logger.rb
88
89
  - lib/pinot/prepared_statement.rb
89
90
  - lib/pinot/proto/broker_service.proto