Merge pull request #14333 from Budibase/trace-search

Add detailed tracing to searches.
This commit is contained in:
Sam Rose 2024-08-07 11:48:04 +01:00 committed by GitHub
commit d45bbb94e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 56 additions and 22 deletions

View File

@ -13,6 +13,7 @@ import { dataFilters } from "@budibase/shared-core"
import sdk from "../../index" import sdk from "../../index"
import { searchInputMapping } from "./search/utils" import { searchInputMapping } from "./search/utils"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import tracer from "dd-trace"
export { isValidFilter } from "../../../integrations/utils" export { isValidFilter } from "../../../integrations/utils"
@ -32,32 +33,65 @@ function pickApi(tableId: any) {
export async function search( export async function search(
options: RowSearchParams options: RowSearchParams
): Promise<SearchResponse<Row>> { ): Promise<SearchResponse<Row>> {
const isExternalTable = isExternalTableID(options.tableId) return await tracer.trace("search", async span => {
options.query = dataFilters.cleanupQuery(options.query || {}) span?.addTags({
options.query = dataFilters.fixupFilterArrays(options.query) tableId: options.tableId,
if ( query: options.query,
!dataFilters.hasFilters(options.query) && sort: options.sort,
options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE sortOrder: options.sortOrder,
) { sortType: options.sortType,
return { limit: options.limit,
rows: [], bookmark: options.bookmark,
paginate: options.paginate,
fields: options.fields,
countRows: options.countRows,
})
const isExternalTable = isExternalTableID(options.tableId)
options.query = dataFilters.cleanupQuery(options.query || {})
options.query = dataFilters.fixupFilterArrays(options.query)
span?.addTags({
cleanedQuery: options.query,
isExternalTable,
})
if (
!dataFilters.hasFilters(options.query) &&
options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
) {
span?.addTags({ emptyQuery: true })
return {
rows: [],
}
} }
}
if (options.sortOrder) { if (options.sortOrder) {
options.sortOrder = options.sortOrder.toLowerCase() as SortOrder options.sortOrder = options.sortOrder.toLowerCase() as SortOrder
} }
const table = await sdk.tables.getTable(options.tableId) const table = await sdk.tables.getTable(options.tableId)
options = searchInputMapping(table, options) options = searchInputMapping(table, options)
if (isExternalTable) { let result: SearchResponse<Row>
return external.search(options, table) if (isExternalTable) {
} else if (dbCore.isSqsEnabledForTenant()) { span?.addTags({ searchType: "external" })
return internal.sqs.search(options, table) result = await external.search(options, table)
} else { } else if (dbCore.isSqsEnabledForTenant()) {
return internal.lucene.search(options, table) span?.addTags({ searchType: "sqs" })
} result = await internal.sqs.search(options, table)
} else {
span?.addTags({ searchType: "lucene" })
result = await internal.lucene.search(options, table)
}
span?.addTags({
foundRows: result.rows.length,
totalRows: result.totalRows,
})
return result
})
} }
export async function exportRows( export async function exportRows(