Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions lib/mongo/search_index/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Mongo
module SearchIndex
# A class representing a view of search indexes.
class View
extend Forwardable
include Enumerable
include Retryable
include Collection::Helpers
Expand All @@ -21,6 +22,8 @@ class View
# when querying the available indexes.
attr_reader :aggregate_options

def_delegators :@collection, :tracer

# Create the new search index view.
#
# @param [ Collection ] collection The collection.
Expand Down Expand Up @@ -51,7 +54,10 @@ def initialize(collection, options = {})
#
# @return [ String ] the name of the new search index.
def create_one(definition, name: nil, type: 'search')
create_many([ { name: name, definition: definition, type: type } ]).first
spec = { definition: definition, type: type }.tap do |sp|
sp[:name] = name unless name.nil?
end
create_many([ spec ]).first
end

# Create multiple search indexes with a single command.
Expand All @@ -64,8 +70,12 @@ def create_one(definition, name: nil, type: 'search')
# @return [ Array<String> ] the names of the new search indexes.
def create_many(indexes)
spec = spec_with(indexes: indexes.map { |v| validate_search_index!(v) })
result = Operation::CreateSearchIndexes.new(spec).execute(next_primary, context: execution_context)
result.first['indexesCreated'].map { |idx| idx['name'] }
operation = Operation::CreateSearchIndexes.new(spec)
context = execution_context
tracer.trace_operation(operation, context, op_name: 'createSearchIndexes') do
result = operation.execute(next_primary, context: context)
result.first['indexesCreated'].map { |idx| idx['name'] }
end
end

# Drop the search index with the given id, or name. One or the other must
Expand All @@ -81,11 +91,14 @@ def drop_one(id: nil, name: nil)

spec = spec_with(index_id: id, index_name: name)
op = Operation::DropSearchIndex.new(spec)
context = execution_context

# per the spec:
# Drivers MUST suppress NamespaceNotFound errors for the
# ``dropSearchIndex`` helper. Drop operations should be idempotent.
do_drop(op, nil, execution_context)
tracer.trace_operation(op, context, op_name: 'dropSearchIndex') do
# per the spec:
# Drivers MUST suppress NamespaceNotFound errors for the
# ``dropSearchIndex`` helper. Drop operations should be idempotent.
do_drop(op, nil, context)
end
end

# Iterate over the search indexes.
Expand Down Expand Up @@ -127,7 +140,11 @@ def update_one(definition, id: nil, name: nil)
validate_id_or_name!(id, name)

spec = spec_with(index_id: id, index_name: name, index: definition)
Operation::UpdateSearchIndex.new(spec).execute(next_primary, context: execution_context)
op = Operation::UpdateSearchIndex.new(spec)
context = execution_context
tracer.trace_operation(op, context, op_name: 'updateSearchIndex') do
op.execute(next_primary, context: context)
end
end

# The following methods are to make the view act more like an array,
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_tests/open_telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
base = "#{CURRENT_PATH}/spec_tests/data/open_telemetry"
OTEL_UNIFIED_TESTS = Dir.glob("#{base}/**/*.yml").sort
SKIPPED_OTEL_TESTS = [
'bulk_write.yml', 'map_reduce.yml', 'atlas_search.yml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional? Given that you're adding tracing support for the atlas indexes here, should these tests remain part of the otel specs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new bulk_write is not yet implemented in the driver; same for map_reduce.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! My bad, I was reading that backward. I missed that these were skipped tests, and you were thus enabling atlas search tests. 👍 LGTM!

'bulk_write.yml', 'map_reduce.yml'
]

TESTS_TO_RUN = OTEL_UNIFIED_TESTS.reject do |path|
Expand Down
Loading