Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metabase.search namespace #42487

Merged
merged 18 commits into from May 22, 2024
Merged

metabase.search namespace #42487

merged 18 commits into from May 22, 2024

Conversation

camsaul
Copy link
Member

@camsaul camsaul commented May 9, 2024

Consolidate search into a metabase.search module. Most of the important stuff related to search already lived in metabase.search namespaeces, but a significant chunk of search implementation stuff lived in metabase.api.search. I moved all of that stuff out into a new metabase.search.impl namespace, so now the search module exists completely independently of the REST API. I removed search's dependency on metabase.api/*current-user-id* and made it part of the search context instead (for some reason :current-user-perms was already part of search context but current User ID was not). This is so there are no circular deps between the metabase.search and metabase.api modules.2

I moved some of the tests over but there is probably more work to do there still.

Also I couldn't help myself and split a bunch of big tests into smaller ones and marked them ^:parallel where it made sense.

@camsaul camsaul requested review from johnswanson and a team May 9, 2024 21:11
@metabase-bot metabase-bot bot added the .Team/QueryProcessor :hammer_and_wrench: label May 9, 2024
@@ -56,3 +56,50 @@
"All namespaces from a module that are used outside that module."
[module-symb]
(into (sorted-set) (map :depends-on-namespace) (external-usages module-symb)))

(defn module-dependencies
Copy link
Member Author

Choose a reason for hiding this comment

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

Some extra new dev tools to help me find circular references between modules

Copy link
Contributor

Choose a reason for hiding this comment

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

Gave some feedback on this in the other PR that used it, in case you were planning on merging this one first.

@@ -246,70 +244,69 @@
[& args]
(apply search-request-data-with identity args))

(deftest order-clause-test
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to metabase.search.impl-test

@@ -900,50 +919,6 @@
(t2/update! Pulse (:id pulse) {:dashboard_id (:id dashboard)})
(is (= nil (search-for-pulses pulse))))))))))

(deftest search-db-call-count-test
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to metabase.search.impl-test

@@ -1312,173 +1292,7 @@
(is (= "Failed to parse datetime value: today~"
(mt/user-http-request :crowberto :get 400 "search" :q search-term :last_edited_at "today~" :creator_id (mt/user->id :rasta))))))))

(deftest created-at-correctness-test
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to metabase.search.impl-test

@@ -788,15 +788,15 @@
:status status})))
(thunk)))

(defmacro with-verified-cards
(defmacro with-verified-cards!
Copy link
Member Author

Choose a reason for hiding this comment

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

Not ok in ^:parallel tests so I gave it a !

@camsaul camsaul added the no-backport Do not backport this PR to any branch label May 9, 2024
Copy link

replay-io bot commented May 9, 2024

Status Complete ↗︎
Commit c9c9a12
Results
⚠️ 1 Flaky
2572 Passed

@camsaul camsaul changed the title Search API namespace metabase.search namespace May 10, 2024
Copy link
Contributor

@crisptrutski crisptrutski left a comment

Choose a reason for hiding this comment

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

Oh man, so nice that you encapsulated the search code like this. We're about to start working on this module to put the "search engine" behind of plugable interface, so the timing couldn't be better.

@@ -56,3 +56,50 @@
"All namespaces from a module that are used outside that module."
[module-symb]
(into (sorted-set) (map :depends-on-namespace) (external-usages module-symb)))

(defn module-dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Gave some feedback on this in the other PR that used it, in case you were planning on merging this one first.

Comment on lines 37 to 38
resources. This seems to be the default this is the default for Postgres, but MySQL/MariaDB seem to default to
`HOLD_CURSORS_OVER_COMMIT`."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
resources. This seems to be the default this is the default for Postgres, but MySQL/MariaDB seem to default to
`HOLD_CURSORS_OVER_COMMIT`."
resources. This this is the default for Postgres, but MySQL/MariaDB seem to default to `HOLD_CURSORS_OVER_COMMIT`."

Comment on lines 69 to 70
(doto (.getConnection data-source)
(setup-connection!))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Comment on lines 167 to 168
;; otherwise we don't need our savepoint anymore and we can release it.
(.releaseSavepoint connection savepoint))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

(try
(.rollback connection savepoint)
(catch Throwable e2
(log/errorf e2 "Error rolling back transaction: %s (triggered by: %s)" (ex-message e2) (ex-message e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Comment on lines +67 to +72
;; TODO FIXME -- search actually currently still requires [[metabase.api.common/*current-user*]] to be bound,
;; because [[metabase.public-settings.premium-features/sandboxed-or-impersonated-user?]] requires it to be bound.
;; Since it's part of the search context it would be nice if we could run search without having to bind that stuff at
;; all.
(assert @@(requiring-resolve 'metabase.api.common/*current-user*)
"metabase.api.common/*current-user* must be bound in order to use search for an indexed entity")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the detailed explanation and validation 🙏

test/metabase/analytics/snowplow_test.clj Show resolved Hide resolved
test/metabase/api/search_test.clj Outdated Show resolved Hide resolved
@crisptrutski
Copy link
Contributor

Out of curiosity, did you check how much all this parallelism speeds up tests locally / in CI?

@johnswanson
Copy link
Contributor

johnswanson commented May 10, 2024

@camsaul reviewing this now, but just a thought - as far as I can tell, metabase.search is solely used by metabase.api.search, and it doesn't seem like a useful module outside of that context - it's pretty API specific. I wonder whether instead of moving code from metabase.api.search to the metabase.search module, we should instead be removing metabase.search and moving its code to live under metabase.api.search. WDYT?

@camsaul camsaul removed the request for review from johnswanson May 10, 2024 16:53
Copy link
Contributor

@johnswanson johnswanson left a comment

Choose a reason for hiding this comment

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

Thanks for parallelizing all those tests, that's awesome!

Changes all LGTM, but I do kind of think metabase.search should probably live under metabase.api.search, so I'd honestly rather move things in the reverse direction here, unless we can think of a good reason why other parts of the system might want to use a metabase.search module. Especially since e.g. there are functions like metabase.search.scoring/serialize (which honestly, I don't know why it lives there in the first place, but nevertheless...) which seem to be pretty intimately connected to sending data to an API client.

@piranha
Copy link
Contributor

piranha commented May 10, 2024

We're about to modularize search, so it's going to have a few backends, and models will have to implement some protocol to be searchable — so it doesn't seem like moving it under metabase.api.search makes sense.

@johnswanson
Copy link
Contributor

We're about to modularize search, so it's going to have a few backends, and models will have to implement some protocol to be searchable — so it doesn't seem like moving it under metabase.api.search makes sense.

Alright, that makes sense then - thanks!

Copy link
Member

@tsmacdonald tsmacdonald left a comment

Choose a reason for hiding this comment

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

, but a significant chunk of search implementation stuff lived in metabase.api.search. I moved all of that stuff out into a new metabase.search.impl namespace

👏

(test-search "past1years-from-12months" old-result)
(test-search "today" new-result))))))

(deftest last-edited-at-correctness-test
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to metabase.search.impl-test

@camsaul camsaul requested a review from noahmoss as a code owner May 22, 2024 01:23
@camsaul camsaul merged commit d5a32ec into master May 22, 2024
107 checks passed
@camsaul camsaul deleted the search-api-namespace branch May 22, 2024 03:44
Copy link

@camsaul Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

oisincoveney pushed a commit that referenced this pull request May 22, 2024
* Search API namespace

* Search API namespace

* Search API namespace

* Fix Kondo warnings

* Fix typo

* Finally solve the MySQL ^:parallel test failures <3

* Make some search tests REPL-friendly

* Did I finally fix `^:parallel` MySQL tests?

* Ok I give up just make the search tests single-threaded for MySQL/MariaDB.

* Revert the stuff to make paralell tests work for MySQL... for now.

* Keep new name

* Revert deps-graph changes

* Remove unused namespaces

* Fix Kondo linter for log/info + format

* Misc fixes 🔧

* Test fixes 🔧
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/QueryProcessor :hammer_and_wrench:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants