Add instrumentation to the search services (#30350)
This commit is contained in:
parent
8394a150d7
commit
acc77c3836
6 changed files with 55 additions and 20 deletions
|
@ -151,13 +151,23 @@ class AccountSearchService < BaseService
|
|||
end
|
||||
|
||||
def call(query, account = nil, options = {})
|
||||
@query = query&.strip&.gsub(/\A@/, '')
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
@options = options
|
||||
@account = account
|
||||
MastodonOTELTracer.in_span('AccountSearchService#call') do |span|
|
||||
@query = query&.strip&.gsub(/\A@/, '')
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
@options = options
|
||||
@account = account
|
||||
|
||||
search_service_results.compact.uniq
|
||||
span.add_attributes(
|
||||
'search.offset' => @offset,
|
||||
'search.limit' => @limit,
|
||||
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||
)
|
||||
|
||||
search_service_results.compact.uniq.tap do |results|
|
||||
span.set_attribute('search.results.count', results.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,14 +2,24 @@
|
|||
|
||||
class StatusesSearchService < BaseService
|
||||
def call(query, account = nil, options = {})
|
||||
@query = query&.strip
|
||||
@account = account
|
||||
@options = options
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
MastodonOTELTracer.in_span('StatusesSearchService#call') do |span|
|
||||
@query = query&.strip
|
||||
@account = account
|
||||
@options = options
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
convert_deprecated_options!
|
||||
|
||||
convert_deprecated_options!
|
||||
status_search_results
|
||||
span.add_attributes(
|
||||
'search.offset' => @offset,
|
||||
'search.limit' => @limit,
|
||||
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||
)
|
||||
|
||||
status_search_results.tap do |results|
|
||||
span.set_attribute('search.results.count', results.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,15 +2,25 @@
|
|||
|
||||
class TagSearchService < BaseService
|
||||
def call(query, options = {})
|
||||
@query = query.strip.delete_prefix('#')
|
||||
@offset = options.delete(:offset).to_i
|
||||
@limit = options.delete(:limit).to_i
|
||||
@options = options
|
||||
MastodonOTELTracer.in_span('TagSearchService#call') do |span|
|
||||
@query = query.strip.delete_prefix('#')
|
||||
@offset = options.delete(:offset).to_i
|
||||
@limit = options.delete(:limit).to_i
|
||||
@options = options
|
||||
|
||||
results = from_elasticsearch if Chewy.enabled?
|
||||
results ||= from_database
|
||||
span.add_attributes(
|
||||
'search.offset' => @offset,
|
||||
'search.limit' => @limit,
|
||||
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||
)
|
||||
|
||||
results
|
||||
results = from_elasticsearch if Chewy.enabled?
|
||||
results ||= from_database
|
||||
|
||||
span.set_attribute('search.results.count', results.size)
|
||||
|
||||
results
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue