Skip to content

Commit

Permalink
RUBY-3352 Backport RUBY-3268 atlas search index helpers to 2.19-stable (
Browse files Browse the repository at this point in the history
#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)
  • Loading branch information
jamis authored Nov 14, 2023
1 parent 525c48e commit a0526f8
Show file tree
Hide file tree
Showing 32 changed files with 1,170 additions and 24 deletions.
62 changes: 62 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,50 @@ post:
- func: "delete serverless instance"

task_groups:
- name: testatlas_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-full-atlas-task

- name: testgcpkms_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
Expand Down Expand Up @@ -586,6 +630,16 @@ tasks:
commands:
- func: "export AWS auth credentials"
- func: "run AWS auth tests"
- name: "test-full-atlas-task"
commands:
- command: shell.exec
type: test
params:
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas-full.sh
- name: "testgcpkms-task"
commands:
- command: shell.exec
Expand Down Expand Up @@ -1612,6 +1666,14 @@ buildvariants:
- name: testazurekms_task_group
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README

- matrix_name: atlas-full
matrix_spec:
ruby: "ruby-3.2"
os: rhel8
display_name: "Atlas (Full)"
tasks:
- name: testatlas_task_group

- matrix_name: "atlas"
matrix_spec:
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"]
Expand Down
54 changes: 54 additions & 0 deletions .evergreen/config/common.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,50 @@ post:
- func: "delete serverless instance"

task_groups:
- name: testatlas_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-full-atlas-task

- name: testgcpkms_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
Expand Down Expand Up @@ -583,6 +627,16 @@ tasks:
commands:
- func: "export AWS auth credentials"
- func: "run AWS auth tests"
- name: "test-full-atlas-task"
commands:
- command: shell.exec
type: test
params:
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas-full.sh
- name: "testgcpkms-task"
commands:
- command: shell.exec
Expand Down
8 changes: 8 additions & 0 deletions .evergreen/config/standard.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,14 @@ buildvariants:
- name: testazurekms_task_group
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README

- matrix_name: atlas-full
matrix_spec:
ruby: <%= latest_ruby %>
os: rhel8
display_name: "Atlas (Full)"
tasks:
- name: testatlas_task_group

- matrix_name: "atlas"
matrix_spec:
ruby: <%= supported_rubies %>
Expand Down
24 changes: 24 additions & 0 deletions .evergreen/run-tests-atlas-full.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -ex

. `dirname "$0"`/../spec/shared/shlib/distro.sh
. `dirname "$0"`/../spec/shared/shlib/set_env.sh
. `dirname "$0"`/functions.sh

set_env_vars
set_env_python
set_env_ruby

bundle_install

ATLAS_URI=$MONGODB_URI \
SERVERLESS=1 \
EXAMPLE_TIMEOUT=600 \
bundle exec rspec -fd spec/integration/search_indexes_prose_spec.rb

test_status=$?

kill_jruby

exit ${test_status}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ data/*
gemfiles/*.gemfile.lock
.env.private*
.env
build
profile/benchmarking/data
secrets-export.sh
secrets-expansion.yml
atlas-expansion.yml
2 changes: 1 addition & 1 deletion .mod/drivers-evergreen-tools
Submodule drivers-evergreen-tools updated 61 files
+19 −7 .evergreen/atlas/setup-atlas-cluster.sh
+34 −0 .evergreen/atlas/setup-variables.sh
+17 −7 .evergreen/atlas/teardown-atlas-cluster.sh
+22 −1 .evergreen/atlas_data_lake/README.md
+0 −0 .evergreen/atlas_data_lake/build-mongohouse-local.sh
+13 −1 .evergreen/atlas_data_lake/config.yml
+15 −0 .evergreen/atlas_data_lake/pull-mongohouse-image.sh
+13 −0 .evergreen/atlas_data_lake/run-mongohouse-image.sh
+0 −0 .evergreen/atlas_data_lake/run-mongohouse-local.sh
+9 −17 .evergreen/auth_aws/activate-authawsvenv.sh
+105 −0 .evergreen/auth_aws/aws_setup.sh
+71 −35 .evergreen/auth_aws/aws_tester.py
+23 −9 .evergreen/auth_aws/lib/aws_assign_instance_profile.py
+3 −3 .evergreen/auth_aws/lib/aws_assume_role.py
+3 −1 .evergreen/auth_aws/lib/aws_assume_web_role.py
+1 −0 .evergreen/auth_aws/lib/aws_handle_oidc_creds.py
+5 −0 .evergreen/auth_aws/lib/util.py
+49 −0 .evergreen/auth_aws/prepare_aws_env.sh
+94 −0 .evergreen/auth_aws/setup_secrets.py
+15 −0 .evergreen/auth_aws/setup_secrets.sh
+4 −18 .evergreen/auth_oidc/Dockerfile
+9 −19 .evergreen/auth_oidc/activate-authoidcvenv.sh
+2 −2 .evergreen/auth_oidc/azure/run-test.sh
+2 −18 .evergreen/auth_oidc/docker_entry.sh
+20 −0 .evergreen/auth_oidc/docker_entry_base.sh
+9 −9 .evergreen/auth_oidc/oidc_get_tokens.py
+10 −11 .evergreen/auth_oidc/oidc_get_tokens.sh
+2 −1 .evergreen/auth_oidc/oidc_write_orchestration.py
+24 −9 .evergreen/auth_oidc/start_local_server.sh
+12 −28 .evergreen/auth_oidc/utils.py
+50 −24 .evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
+120 −114 .evergreen/config.yml
+9 −17 .evergreen/csfle/activate-kmstlsvenv.sh
+33 −21 .evergreen/csfle/azurekms/create-and-setup-vm.sh
+12 −0 .evergreen/csfle/azurekms/delete-vm.sh
+43 −0 .evergreen/docker/README.md
+47 −0 .evergreen/docker/run-local.sh
+33 −0 .evergreen/docker/ubuntu20.04/Dockerfile
+14 −0 .evergreen/docker/ubuntu20.04/base-entrypoint.sh
+5 −0 .evergreen/docker/ubuntu20.04/local-entrypoint.sh
+7 −0 .evergreen/docker/ubuntu20.04/test-entrypoint.sh
+386 −355 .evergreen/download-mongodb.sh
+5 −0 .evergreen/find-python3.sh
+11 −0 .evergreen/github_app/README.md
+89 −0 .evergreen/github_app/create_or_modify_comment.mjs
+20 −0 .evergreen/github_app/create_or_modify_comment.sh
+0 −0 .evergreen/github_app/index.js
+647 −0 .evergreen/github_app/package-lock.json
+25 −0 .evergreen/github_app/package.json
+22 −0 .evergreen/init-node-and-npm-env.sh
+112 −0 .evergreen/install-node.sh
+1 −1 .evergreen/make-docs.sh
+9 −17 .evergreen/ocsp/activate-ocspvenv.sh
+0 −208 .evergreen/run-deployed-lambda-aws-tests.sh
+5 −3 .evergreen/run-load-balancer.sh
+22 −5 .evergreen/run-orchestration.sh
+3 −1 .evergreen/serverless/create-instance.sh
+23 −6 .evergreen/start-orchestration.sh
+2 −2 .evergreen/venv-utils.sh
+6 −0 .gitignore
+5 −1 action.yml
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Metrics/ModuleLength:
Metrics/MethodLength:
Max: 20

Naming/MethodParameterName:
AllowedNames: [ id, op ]

RSpec/BeforeAfterAll:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions lib/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
require 'mongo/dbref'
require 'mongo/grid'
require 'mongo/index'
require 'mongo/search_index/view'
require 'mongo/lint'
require 'mongo/query_cache'
require 'mongo/server'
Expand Down
24 changes: 23 additions & 1 deletion lib/mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,35 @@ def distinct(field_name, filter = nil, options = {})
#
# @option options [ Session ] :session The session to use.
#
# @return [ View::Index ] The index view.
# @return [ Index::View ] The index view.
#
# @since 2.0.0
def indexes(options = {})
Index::View.new(self, options)
end

# Get a view of all search indexes for this collection. Can be iterated or
# operated on directly. If id or name are given, the iterator will return
# only the indicated index. For all other operations, id and name are
# ignored.
#
# @note Only one of id or name may be given; it is an error to specify both,
# although both may be omitted safely.
#
# @param [ Hash ] options The options to use to configure the view.
#
# @option options [ String ] :id The id of the specific index to query (optional)
# @option options [ String ] :name The name of the specific index to query (optional)
# @option options [ Hash ] :aggregate The options hash to pass to the
# aggregate command (optional)
#
# @return [ SearchIndex::View ] The search index view.
#
# @since 2.0.0
def search_indexes(options = {})
SearchIndex::View.new(self, options)
end

# Get a pretty printed string inspection for the collection.
#
# @example Inspect the collection.
Expand Down
3 changes: 3 additions & 0 deletions lib/mongo/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
require 'mongo/operation/remove_user'
require 'mongo/operation/create_index'
require 'mongo/operation/drop_index'
require 'mongo/operation/create_search_indexes'
require 'mongo/operation/drop_search_index'
require 'mongo/operation/update_search_index'

module Mongo

Expand Down
15 changes: 15 additions & 0 deletions lib/mongo/operation/create_search_indexes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'mongo/operation/create_search_indexes/op_msg'

module Mongo
module Operation
# A MongoDB createSearchIndexes command operation.
#
# @api private
class CreateSearchIndexes
include Specifiable
include OpMsgExecutable
end
end
end
31 changes: 31 additions & 0 deletions lib/mongo/operation/create_search_indexes/op_msg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Mongo
module Operation
class CreateSearchIndexes
# A MongoDB createSearchIndexes operation sent as an op message.
#
# @api private
class OpMsg < OpMsgBase
include ExecutableTransactionLabel

private

# Returns the command to send to the database, describing the
# desired createSearchIndexes operation.
#
# @param [ Mongo::Server ] _server the server that will receive the
# command
#
# @return [ Hash ] the selector
def selector(_server)
{
createSearchIndexes: coll_name,
:$db => db_name,
indexes: indexes,
}
end
end
end
end
end
15 changes: 15 additions & 0 deletions lib/mongo/operation/drop_search_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'mongo/operation/drop_search_index/op_msg'

module Mongo
module Operation
# A MongoDB dropSearchIndex command operation.
#
# @api private
class DropSearchIndex
include Specifiable
include OpMsgExecutable
end
end
end
33 changes: 33 additions & 0 deletions lib/mongo/operation/drop_search_index/op_msg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Mongo
module Operation
class DropSearchIndex
# A MongoDB createSearchIndexes operation sent as an op message.
#
# @api private
class OpMsg < OpMsgBase
include ExecutableTransactionLabel

private

# Returns the command to send to the database, describing the
# desired dropSearchIndex operation.
#
# @param [ Mongo::Server ] _server the server that will receive the
# command
#
# @return [ Hash ] the selector
def selector(_server)
{
dropSearchIndex: coll_name,
:$db => db_name,
}.tap do |sel|
sel[:id] = index_id if index_id
sel[:name] = index_name if index_name
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/mongo/operation/shared/specifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ def index
spec[INDEX]
end

# Get the index id from the spec.
#
# @return [ String ] The index id.
def index_id
spec[:index_id]
end

# Get the index name from the spec.
#
# @example Get the index name.
Expand Down
15 changes: 15 additions & 0 deletions lib/mongo/operation/update_search_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'mongo/operation/update_search_index/op_msg'

module Mongo
module Operation
# A MongoDB updateSearchIndex command operation.
#
# @api private
class UpdateSearchIndex
include Specifiable
include OpMsgExecutable
end
end
end
Loading

0 comments on commit a0526f8

Please sign in to comment.