Skip to content

Commit a0526f8

Browse files
authored
RUBY-3352 Backport RUBY-3268 atlas search index helpers to 2.19-stable (#2804)
* RUBY-3268 search index management helpers (#2777) * RUBY-3268 Index View API for Search Indexes * documentation, and align method names with the spec * return the correct value here * suppress NamespaceNotFound errors for the drop operation * prose tests for search indexes * rubocop * prose tests pass * first stab at evergreen config for index management specs * rubocop * gah, executable permissions * don't use FLE for full atlas tests * make sure MONGODB_URI is set * set the timeout higher for the search index specs * pass all aggregation options through to the list indexes command * use the correct implementation for #empty? * remove unnecessary validation * bump drivers-evergreen-tools * RUBY-3324 bump drivers-evergreen-tools to get updated atlas setup/teardown (#2780) also, expose task_id expansion as environment variable to those scripts * RUBY-3328 add `execution` expansion to environment for atlas cluster name uniqueness (#2783)
1 parent 525c48e commit a0526f8

32 files changed

+1170
-24
lines changed

Diff for: .evergreen/config.yml

+62
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,50 @@ post:
469469
- func: "delete serverless instance"
470470

471471
task_groups:
472+
- name: testatlas_task_group
473+
setup_group_can_fail_task: true
474+
setup_group_timeout_secs: 1800 # 30 minutes
475+
setup_group:
476+
- func: fetch source
477+
- func: create expansions
478+
- command: shell.exec
479+
params:
480+
shell: "bash"
481+
working_dir: "src"
482+
script: |
483+
${PREPARE_SHELL}
484+
485+
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
486+
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
487+
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
488+
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
489+
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
490+
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
491+
MONGODB_VERSION="7.0" \
492+
task_id="${task_id}" \
493+
execution="${execution}" \
494+
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
495+
- command: expansions.update
496+
params:
497+
file: src/atlas-expansion.yml
498+
teardown_group:
499+
- command: shell.exec
500+
params:
501+
shell: "bash"
502+
working_dir: "src"
503+
script: |
504+
${PREPARE_SHELL}
505+
506+
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
507+
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
508+
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
509+
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
510+
task_id="${task_id}" \
511+
execution="${execution}" \
512+
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
513+
tasks:
514+
- test-full-atlas-task
515+
472516
- name: testgcpkms_task_group
473517
setup_group_can_fail_task: true
474518
setup_group_timeout_secs: 1800 # 30 minutes
@@ -586,6 +630,16 @@ tasks:
586630
commands:
587631
- func: "export AWS auth credentials"
588632
- func: "run AWS auth tests"
633+
- name: "test-full-atlas-task"
634+
commands:
635+
- command: shell.exec
636+
type: test
637+
params:
638+
working_dir: "src"
639+
shell: "bash"
640+
script: |
641+
${PREPARE_SHELL}
642+
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas-full.sh
589643
- name: "testgcpkms-task"
590644
commands:
591645
- command: shell.exec
@@ -1612,6 +1666,14 @@ buildvariants:
16121666
- name: testazurekms_task_group
16131667
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README
16141668

1669+
- matrix_name: atlas-full
1670+
matrix_spec:
1671+
ruby: "ruby-3.2"
1672+
os: rhel8
1673+
display_name: "Atlas (Full)"
1674+
tasks:
1675+
- name: testatlas_task_group
1676+
16151677
- matrix_name: "atlas"
16161678
matrix_spec:
16171679
ruby: ["ruby-3.2", "ruby-3.1", "ruby-3.0", "ruby-2.7", "ruby-2.6", "ruby-2.5", "jruby-9.3", "jruby-9.2"]

Diff for: .evergreen/config/common.yml.erb

+54
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,50 @@ post:
466466
- func: "delete serverless instance"
467467

468468
task_groups:
469+
- name: testatlas_task_group
470+
setup_group_can_fail_task: true
471+
setup_group_timeout_secs: 1800 # 30 minutes
472+
setup_group:
473+
- func: fetch source
474+
- func: create expansions
475+
- command: shell.exec
476+
params:
477+
shell: "bash"
478+
working_dir: "src"
479+
script: |
480+
${PREPARE_SHELL}
481+
482+
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
483+
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
484+
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
485+
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
486+
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
487+
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
488+
MONGODB_VERSION="7.0" \
489+
task_id="${task_id}" \
490+
execution="${execution}" \
491+
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
492+
- command: expansions.update
493+
params:
494+
file: src/atlas-expansion.yml
495+
teardown_group:
496+
- command: shell.exec
497+
params:
498+
shell: "bash"
499+
working_dir: "src"
500+
script: |
501+
${PREPARE_SHELL}
502+
503+
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
504+
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
505+
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
506+
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
507+
task_id="${task_id}" \
508+
execution="${execution}" \
509+
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
510+
tasks:
511+
- test-full-atlas-task
512+
469513
- name: testgcpkms_task_group
470514
setup_group_can_fail_task: true
471515
setup_group_timeout_secs: 1800 # 30 minutes
@@ -583,6 +627,16 @@ tasks:
583627
commands:
584628
- func: "export AWS auth credentials"
585629
- func: "run AWS auth tests"
630+
- name: "test-full-atlas-task"
631+
commands:
632+
- command: shell.exec
633+
type: test
634+
params:
635+
working_dir: "src"
636+
shell: "bash"
637+
script: |
638+
${PREPARE_SHELL}
639+
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas-full.sh
586640
- name: "testgcpkms-task"
587641
commands:
588642
- command: shell.exec

Diff for: .evergreen/config/standard.yml.erb

+8
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@ buildvariants:
497497
- name: testazurekms_task_group
498498
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README
499499

500+
- matrix_name: atlas-full
501+
matrix_spec:
502+
ruby: <%= latest_ruby %>
503+
os: rhel8
504+
display_name: "Atlas (Full)"
505+
tasks:
506+
- name: testatlas_task_group
507+
500508
- matrix_name: "atlas"
501509
matrix_spec:
502510
ruby: <%= supported_rubies %>

Diff for: .evergreen/run-tests-atlas-full.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
. `dirname "$0"`/../spec/shared/shlib/distro.sh
6+
. `dirname "$0"`/../spec/shared/shlib/set_env.sh
7+
. `dirname "$0"`/functions.sh
8+
9+
set_env_vars
10+
set_env_python
11+
set_env_ruby
12+
13+
bundle_install
14+
15+
ATLAS_URI=$MONGODB_URI \
16+
SERVERLESS=1 \
17+
EXAMPLE_TIMEOUT=600 \
18+
bundle exec rspec -fd spec/integration/search_indexes_prose_spec.rb
19+
20+
test_status=$?
21+
22+
kill_jruby
23+
24+
exit ${test_status}

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ data/*
2525
gemfiles/*.gemfile.lock
2626
.env.private*
2727
.env
28+
build
29+
profile/benchmarking/data
30+
secrets-export.sh
31+
secrets-expansion.yml
32+
atlas-expansion.yml

Diff for: .mod/drivers-evergreen-tools

Diff for: .rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Metrics/ModuleLength:
5656
Metrics/MethodLength:
5757
Max: 20
5858

59+
Naming/MethodParameterName:
60+
AllowedNames: [ id, op ]
61+
5962
RSpec/BeforeAfterAll:
6063
Enabled: false
6164

Diff for: lib/mongo.rb

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
require 'mongo/dbref'
6565
require 'mongo/grid'
6666
require 'mongo/index'
67+
require 'mongo/search_index/view'
6768
require 'mongo/lint'
6869
require 'mongo/query_cache'
6970
require 'mongo/server'

Diff for: lib/mongo/collection.rb

+23-1
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,35 @@ def distinct(field_name, filter = nil, options = {})
725725
#
726726
# @option options [ Session ] :session The session to use.
727727
#
728-
# @return [ View::Index ] The index view.
728+
# @return [ Index::View ] The index view.
729729
#
730730
# @since 2.0.0
731731
def indexes(options = {})
732732
Index::View.new(self, options)
733733
end
734734

735+
# Get a view of all search indexes for this collection. Can be iterated or
736+
# operated on directly. If id or name are given, the iterator will return
737+
# only the indicated index. For all other operations, id and name are
738+
# ignored.
739+
#
740+
# @note Only one of id or name may be given; it is an error to specify both,
741+
# although both may be omitted safely.
742+
#
743+
# @param [ Hash ] options The options to use to configure the view.
744+
#
745+
# @option options [ String ] :id The id of the specific index to query (optional)
746+
# @option options [ String ] :name The name of the specific index to query (optional)
747+
# @option options [ Hash ] :aggregate The options hash to pass to the
748+
# aggregate command (optional)
749+
#
750+
# @return [ SearchIndex::View ] The search index view.
751+
#
752+
# @since 2.0.0
753+
def search_indexes(options = {})
754+
SearchIndex::View.new(self, options)
755+
end
756+
735757
# Get a pretty printed string inspection for the collection.
736758
#
737759
# @example Inspect the collection.

Diff for: lib/mongo/operation.rb

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
require 'mongo/operation/remove_user'
5252
require 'mongo/operation/create_index'
5353
require 'mongo/operation/drop_index'
54+
require 'mongo/operation/create_search_indexes'
55+
require 'mongo/operation/drop_search_index'
56+
require 'mongo/operation/update_search_index'
5457

5558
module Mongo
5659

Diff for: lib/mongo/operation/create_search_indexes.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require 'mongo/operation/create_search_indexes/op_msg'
4+
5+
module Mongo
6+
module Operation
7+
# A MongoDB createSearchIndexes command operation.
8+
#
9+
# @api private
10+
class CreateSearchIndexes
11+
include Specifiable
12+
include OpMsgExecutable
13+
end
14+
end
15+
end

Diff for: lib/mongo/operation/create_search_indexes/op_msg.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Mongo
4+
module Operation
5+
class CreateSearchIndexes
6+
# A MongoDB createSearchIndexes operation sent as an op message.
7+
#
8+
# @api private
9+
class OpMsg < OpMsgBase
10+
include ExecutableTransactionLabel
11+
12+
private
13+
14+
# Returns the command to send to the database, describing the
15+
# desired createSearchIndexes operation.
16+
#
17+
# @param [ Mongo::Server ] _server the server that will receive the
18+
# command
19+
#
20+
# @return [ Hash ] the selector
21+
def selector(_server)
22+
{
23+
createSearchIndexes: coll_name,
24+
:$db => db_name,
25+
indexes: indexes,
26+
}
27+
end
28+
end
29+
end
30+
end
31+
end

Diff for: lib/mongo/operation/drop_search_index.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require 'mongo/operation/drop_search_index/op_msg'
4+
5+
module Mongo
6+
module Operation
7+
# A MongoDB dropSearchIndex command operation.
8+
#
9+
# @api private
10+
class DropSearchIndex
11+
include Specifiable
12+
include OpMsgExecutable
13+
end
14+
end
15+
end

Diff for: lib/mongo/operation/drop_search_index/op_msg.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
module Mongo
4+
module Operation
5+
class DropSearchIndex
6+
# A MongoDB createSearchIndexes operation sent as an op message.
7+
#
8+
# @api private
9+
class OpMsg < OpMsgBase
10+
include ExecutableTransactionLabel
11+
12+
private
13+
14+
# Returns the command to send to the database, describing the
15+
# desired dropSearchIndex operation.
16+
#
17+
# @param [ Mongo::Server ] _server the server that will receive the
18+
# command
19+
#
20+
# @return [ Hash ] the selector
21+
def selector(_server)
22+
{
23+
dropSearchIndex: coll_name,
24+
:$db => db_name,
25+
}.tap do |sel|
26+
sel[:id] = index_id if index_id
27+
sel[:name] = index_name if index_name
28+
end
29+
end
30+
end
31+
end
32+
end
33+
end

Diff for: lib/mongo/operation/shared/specifiable.rb

+7
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ def index
260260
spec[INDEX]
261261
end
262262

263+
# Get the index id from the spec.
264+
#
265+
# @return [ String ] The index id.
266+
def index_id
267+
spec[:index_id]
268+
end
269+
263270
# Get the index name from the spec.
264271
#
265272
# @example Get the index name.

Diff for: lib/mongo/operation/update_search_index.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require 'mongo/operation/update_search_index/op_msg'
4+
5+
module Mongo
6+
module Operation
7+
# A MongoDB updateSearchIndex command operation.
8+
#
9+
# @api private
10+
class UpdateSearchIndex
11+
include Specifiable
12+
include OpMsgExecutable
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)