chalk_ruby 0.3.1 → 0.4.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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +41 -0
- data/.github/workflows/test.yml +33 -0
- data/chalk_ruby.gemspec +1 -1
- data/lib/chalk_ruby/client.rb +46 -2
- data/lib/chalk_ruby/config.rb +8 -1
- data/lib/chalk_ruby/grpc_client.rb +18 -0
- data/lib/chalk_ruby/version.rb +1 -1
- data/test/chalk_ruby/integration/client_test.rb +1 -1
- data/test/chalk_ruby/integration/connection_warming_test.rb +35 -0
- metadata +20 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be8baa09bb22ab16fe18d5d82d89fa4d5ca75f2216f60daeb240ee185aecafc1
|
4
|
+
data.tar.gz: 07cfafd2ff5de2898f492697f17eba513e5cdea23df58ed8489b637c3a5b6b40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: befc8666980d27db057207bcf38a97e8f347879ed0938a9f8a5fcd3cbb07fe06d00e458ec50b7a54c0f308ab1f8ad2c331abe5c63213acde8073e04954ae1442
|
7
|
+
data.tar.gz: b8fdb9a0157d03e68047bcc5da8ecd569441cbc60c93f9b42378c6a227a401b99b0a3eede639f5ec1bcf44891193fc619ea3ca7e5e64bc470e8cf40eeec3dc31
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Release Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- 'v*'
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v4
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: '3.0'
|
20
|
+
bundler-cache: true
|
21
|
+
|
22
|
+
- name: Extract version from tag
|
23
|
+
id: get_version
|
24
|
+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
25
|
+
|
26
|
+
- name: Update version.rb
|
27
|
+
run: |
|
28
|
+
sed -i "s/VERSION = '.*'/VERSION = '${{ env.VERSION }}'/g" lib/chalk_ruby/version.rb
|
29
|
+
|
30
|
+
- name: Build gem
|
31
|
+
run: gem build chalk_ruby.gemspec
|
32
|
+
|
33
|
+
- name: Publish to RubyGems
|
34
|
+
run: |
|
35
|
+
mkdir -p $HOME/.gem
|
36
|
+
touch $HOME/.gem/credentials
|
37
|
+
chmod 0600 $HOME/.gem/credentials
|
38
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
39
|
+
gem push "chalk_ruby-${{ env.VERSION }}.gem"
|
40
|
+
env:
|
41
|
+
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Run Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
|
26
|
+
- name: Install dependencies
|
27
|
+
run: bundle install
|
28
|
+
|
29
|
+
- name: Run linter
|
30
|
+
run: bundle exec rake rubocop
|
31
|
+
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake test:all
|
data/chalk_ruby.gemspec
CHANGED
@@ -42,11 +42,11 @@ Gem::Specification.new do |spec|
|
|
42
42
|
|
43
43
|
spec.add_dependency 'multi_json', '~> 1.0'
|
44
44
|
spec.add_dependency 'net-http-persistent'
|
45
|
-
spec.add_dependency 'red-arrow', '~> 18.0.0'
|
46
45
|
|
47
46
|
spec.add_development_dependency 'httpclient'
|
48
47
|
spec.add_development_dependency 'm'
|
49
48
|
spec.add_development_dependency 'minitest'
|
50
49
|
spec.add_development_dependency 'minitest-hooks'
|
51
50
|
spec.add_development_dependency 'minitest-proveit'
|
51
|
+
spec.add_development_dependency 'red-arrow', '~> 18.0.0'
|
52
52
|
end
|
data/lib/chalk_ruby/client.rb
CHANGED
@@ -29,6 +29,11 @@ module ChalkRuby
|
|
29
29
|
# @param additional_headers [Hash[String, String]]
|
30
30
|
# Additional headers to be sent with every request. Typically not required.
|
31
31
|
#
|
32
|
+
# @param eagerly_initialize_connection_pool [Boolean]
|
33
|
+
# Whether to eagerly initialize connections to the query and API servers.
|
34
|
+
# When true, connections will be pre-warmed during client initialization.
|
35
|
+
# Default is false (lazy initialization).
|
36
|
+
#
|
32
37
|
# @return self
|
33
38
|
#
|
34
39
|
def self.create(
|
@@ -37,7 +42,8 @@ module ChalkRuby
|
|
37
42
|
environment = nil,
|
38
43
|
query_server = nil,
|
39
44
|
api_server = nil,
|
40
|
-
additional_headers = {}
|
45
|
+
additional_headers = {},
|
46
|
+
eagerly_initialize_connection_pool = false
|
41
47
|
)
|
42
48
|
config = Config.new(
|
43
49
|
client_id: client_id,
|
@@ -45,7 +51,8 @@ module ChalkRuby
|
|
45
51
|
environment: environment,
|
46
52
|
query_server: query_server,
|
47
53
|
api_server: api_server,
|
48
|
-
additional_headers: additional_headers
|
54
|
+
additional_headers: additional_headers,
|
55
|
+
eagerly_initialize_connection_pool: eagerly_initialize_connection_pool
|
49
56
|
)
|
50
57
|
create_with_config(config)
|
51
58
|
end
|
@@ -213,9 +220,46 @@ module ChalkRuby
|
|
213
220
|
logger = opts[:logger] || LoggerHelper.create
|
214
221
|
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter: adapter, logger: logger)
|
215
222
|
@transporter = Http::HttpRequesterChalk.new(requester: requester)
|
223
|
+
|
224
|
+
# Eagerly initialize connections if configured
|
225
|
+
if @config.eagerly_initialize_connection_pool
|
226
|
+
warm_connections
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Warm up connections to the API and query servers by establishing
|
231
|
+
# TCP connections with lightweight HEAD requests
|
232
|
+
def warm_connections
|
233
|
+
# Get the query server host
|
234
|
+
query_host = query_server_host
|
235
|
+
|
236
|
+
# Warm up API server connection
|
237
|
+
warm_connection(@config.api_server)
|
238
|
+
|
239
|
+
# Warm up query server connection
|
240
|
+
warm_connection(query_host)
|
216
241
|
end
|
217
242
|
|
218
243
|
private
|
244
|
+
|
245
|
+
# Establish a connection to a host by making a lightweight request
|
246
|
+
def warm_connection(host)
|
247
|
+
# Access the underlying HTTP requester
|
248
|
+
requester = @transporter.instance_variable_get(:@http_requester)
|
249
|
+
|
250
|
+
# Create the Faraday connection object
|
251
|
+
connection = requester.connection(host)
|
252
|
+
|
253
|
+
# Make a HEAD request to "/" to actually establish the TCP connection
|
254
|
+
# HEAD is used as it's lightweight and most servers support it
|
255
|
+
begin
|
256
|
+
connection.head('/')
|
257
|
+
rescue => e
|
258
|
+
# Ignore errors - we're just warming the connection
|
259
|
+
# The server might not support HEAD on /, but the TCP connection
|
260
|
+
# will still be established
|
261
|
+
end
|
262
|
+
end
|
219
263
|
|
220
264
|
def api_server_request(method:, path:, body:, headers:)
|
221
265
|
@transporter.send_request(
|
data/lib/chalk_ruby/config.rb
CHANGED
@@ -17,7 +17,8 @@ module ChalkRuby
|
|
17
17
|
:api_timeout,
|
18
18
|
:connect_timeout,
|
19
19
|
:query_service_root_ca_path,
|
20
|
-
:additional_headers
|
20
|
+
:additional_headers,
|
21
|
+
:eagerly_initialize_connection_pool
|
21
22
|
|
22
23
|
# Creates a new ChalkRuby::Config object for use with ChalkRuby::Client.
|
23
24
|
#
|
@@ -52,6 +53,11 @@ module ChalkRuby
|
|
52
53
|
# @option options [Hash<String, String>?] :additional_headers
|
53
54
|
# Additional headers to be sent with every request. Typically not required.
|
54
55
|
#
|
56
|
+
# @option options [Boolean?] :eagerly_initialize_connection_pool
|
57
|
+
# Whether to eagerly initialize connections to the query and API servers.
|
58
|
+
# When true, connections will be pre-warmed during client initialization.
|
59
|
+
# Default is false (lazy initialization).
|
60
|
+
#
|
55
61
|
def initialize(opts = {})
|
56
62
|
@client_id = opts[:client_id] || ENV['CHALK_CLIENT_ID']
|
57
63
|
@client_secret = opts[:client_secret] || ENV['CHALK_CLIENT_SECRET']
|
@@ -63,6 +69,7 @@ module ChalkRuby
|
|
63
69
|
@connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
|
64
70
|
@query_service_root_ca_path = opts[:query_service_root_ca_path] || Defaults::ROOT_CA_PATH
|
65
71
|
@additional_headers = opts[:additional_headers] || {}
|
72
|
+
@eagerly_initialize_connection_pool = opts[:eagerly_initialize_connection_pool] || false
|
66
73
|
|
67
74
|
raise ChalkError, 'No Client ID provided, please set :client_id' if @client_id.nil?
|
68
75
|
raise ChalkError, 'No Client Secret provided, please set :client_secret' if @client_secret.nil?
|
@@ -168,6 +168,9 @@ module ChalkRuby
|
|
168
168
|
correlation_id: nil,
|
169
169
|
planner_options: nil
|
170
170
|
)
|
171
|
+
unless red_arrow_available?
|
172
|
+
raise NotImplementedError, "query_bulk requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
|
173
|
+
end
|
171
174
|
# Convert input to feather format
|
172
175
|
inputs_feather = to_feather(input)
|
173
176
|
|
@@ -412,10 +415,22 @@ module ChalkRuby
|
|
412
415
|
|
413
416
|
private
|
414
417
|
|
418
|
+
def red_arrow_available?
|
419
|
+
@red_arrow_available ||= begin
|
420
|
+
require 'arrow'
|
421
|
+
true
|
422
|
+
rescue LoadError
|
423
|
+
false
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
415
427
|
# Converts Arrow binary data to an array of hashes
|
416
428
|
# @param arrow_data [String] Binary Arrow data (IPC stream format)
|
417
429
|
# @return [Array<Hash>] Array of hashes with column name as keys and Ruby values
|
418
430
|
def arrow_table_to_array(arrow_data)
|
431
|
+
unless red_arrow_available?
|
432
|
+
raise NotImplementedError, "arrow_table_to_array requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
|
433
|
+
end
|
419
434
|
require 'arrow'
|
420
435
|
|
421
436
|
buffer = Arrow::Buffer.new(arrow_data)
|
@@ -454,6 +469,9 @@ module ChalkRuby
|
|
454
469
|
end
|
455
470
|
|
456
471
|
def to_feather(input_hash)
|
472
|
+
unless red_arrow_available?
|
473
|
+
raise NotImplementedError, "to_feather requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
|
474
|
+
end
|
457
475
|
require 'arrow'
|
458
476
|
|
459
477
|
# Ensure all values in the input hash are arrays
|
data/lib/chalk_ruby/version.rb
CHANGED
@@ -8,7 +8,7 @@ CLIENT_SECRET = ''
|
|
8
8
|
|
9
9
|
RSpec.describe 'Online query' do
|
10
10
|
it 'should accept valid queries' do
|
11
|
-
client = ChalkRuby::Client.create(CLIENT_ID, CLIENT_SECRET)
|
11
|
+
client = ChalkRuby::Client.create(CLIENT_ID, CLIENT_SECRET, "tmnmrbyb8x53f")
|
12
12
|
response = client.query(
|
13
13
|
input: { 'user.id': 3454 },
|
14
14
|
output: %w(user.id),
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'chalk_ruby/client'
|
3
|
+
require 'chalk_ruby/config'
|
4
|
+
|
5
|
+
describe 'Connection warming' do
|
6
|
+
it 'should accept eagerly_initialize_connection_pool parameter in config' do
|
7
|
+
config = ChalkRuby::Config.new(
|
8
|
+
client_id: 'test_id',
|
9
|
+
client_secret: 'test_secret',
|
10
|
+
eagerly_initialize_connection_pool: true
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_equal true, config.eagerly_initialize_connection_pool
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should default eagerly_initialize_connection_pool to false' do
|
17
|
+
config = ChalkRuby::Config.new(
|
18
|
+
client_id: 'test_id',
|
19
|
+
client_secret: 'test_secret'
|
20
|
+
)
|
21
|
+
|
22
|
+
assert_equal false, config.eagerly_initialize_connection_pool
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should accept eagerly_initialize_connection_pool parameter in create method' do
|
26
|
+
# This test verifies the parameter is accepted
|
27
|
+
params = ChalkRuby::Client.method(:create).parameters.map(&:last)
|
28
|
+
assert params.include?(:eagerly_initialize_connection_pool)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have warm_connections method' do
|
32
|
+
# Test that the method exists on the class
|
33
|
+
assert ChalkRuby::Client.public_instance_methods.include?(:warm_connections)
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chalk_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chalk AI, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,20 +140,6 @@ dependencies:
|
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
|
-
- !ruby/object:Gem::Dependency
|
144
|
-
name: red-arrow
|
145
|
-
requirement: !ruby/object:Gem::Requirement
|
146
|
-
requirements:
|
147
|
-
- - "~>"
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: 18.0.0
|
150
|
-
type: :runtime
|
151
|
-
prerelease: false
|
152
|
-
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
requirements:
|
154
|
-
- - "~>"
|
155
|
-
- !ruby/object:Gem::Version
|
156
|
-
version: 18.0.0
|
157
143
|
- !ruby/object:Gem::Dependency
|
158
144
|
name: httpclient
|
159
145
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,6 +210,20 @@ dependencies:
|
|
224
210
|
- - ">="
|
225
211
|
- !ruby/object:Gem::Version
|
226
212
|
version: '0'
|
213
|
+
- !ruby/object:Gem::Dependency
|
214
|
+
name: red-arrow
|
215
|
+
requirement: !ruby/object:Gem::Requirement
|
216
|
+
requirements:
|
217
|
+
- - "~>"
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: 18.0.0
|
220
|
+
type: :development
|
221
|
+
prerelease: false
|
222
|
+
version_requirements: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - "~>"
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: 18.0.0
|
227
227
|
description: A simple Ruby client for Chalk
|
228
228
|
email:
|
229
229
|
- help@chalk.ai
|
@@ -234,6 +234,8 @@ files:
|
|
234
234
|
- ".github/CODEOWNERS"
|
235
235
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
236
236
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
237
|
+
- ".github/workflows/release.yml"
|
238
|
+
- ".github/workflows/test.yml"
|
237
239
|
- ".gitignore"
|
238
240
|
- ".rubocop.yml"
|
239
241
|
- ".rubocop_todo.yml"
|
@@ -364,6 +366,7 @@ files:
|
|
364
366
|
- sig/chalk_ruby/versions.rbs
|
365
367
|
- test/chalk_ruby/integration/arrow_conversion_test.rb
|
366
368
|
- test/chalk_ruby/integration/client_test.rb
|
369
|
+
- test/chalk_ruby/integration/connection_warming_test.rb
|
367
370
|
- test/chalk_ruby/integration/grpc_client_test.rb
|
368
371
|
- test/chalk_ruby/test_helper.rb
|
369
372
|
homepage: https://github.com/chalk-ai/chalk-ruby
|
@@ -395,5 +398,6 @@ summary: A simple Ruby client for Chalk
|
|
395
398
|
test_files:
|
396
399
|
- test/chalk_ruby/integration/arrow_conversion_test.rb
|
397
400
|
- test/chalk_ruby/integration/client_test.rb
|
401
|
+
- test/chalk_ruby/integration/connection_warming_test.rb
|
398
402
|
- test/chalk_ruby/integration/grpc_client_test.rb
|
399
403
|
- test/chalk_ruby/test_helper.rb
|