Skip to content

feat(explore): Adds prebuilt queries to Explore #90720

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

edwardgou-sentry
Copy link
Contributor

@edwardgou-sentry edwardgou-sentry commented May 1, 2025

Adds prebuilt queries to Explore:

  • PREBUILT_SAVED_QUERIES are saved as hardcoded dicts in explore_saved_queries.py.

  • On the first time GET is called on ExploreSavedQueriesEndpoint, we insert PREBUILT_SAVED_QUERIES entries into the saved queries db table, if they do not already exist. We also update or delete saved prebuilt queries in the db if there are changes detected (see sync_prebuilt_queries).

  • If it's the first time a user is fetching prebuilt queries, we also "star" them for the user by default. See sync_prebuilt_queries_starred.

  • This allows users to (mostly) interact with prebuilt queries in the same way as user generated saved queries (ie star, reorder star position, search filter, search sort, duplicate, etc). This also allows Sentry to add, change, or delete any prebuilt queries in the future. We do not allow users to delete or edit prebuilt queries.

The following migration changes are needed to support prebuilt queries:

  • add a prebuilt_id column to the ExploreSavedQuery model. This is so we know a saved query is prebuilt, and also serves as an identifier for when we need to rename or change a prebuilt query for the customer.
  • add a prebuilt_version column to the ExploreSavedQuery model. Serves as a way to version control saved prebuilt queries. ie, if prebuilt_version in the hardcoded PREBUILT_SAVED_QUERIES is greater than prebuilt_version in the db, we must update the db entry.
  • add a starred column to the ExploreSavedQueryStarred model, and make position nullable. This is necessary to support "starring" prebuilt queries by default. In the past, when a saved query is 'unstarred', we delete the entry from ExploreSavedQueryStarred to reflect this state. However, with prebuilt queries, when there is no entry in the ExploreSavedQueryStarred model, we can't tell if this means the prebuilt query was 'unstarred' by the user or if it's the first time the user is reading the prebuilt query. By adding a starred column, we can distinguish between these two different states.

@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels May 1, 2025
@edwardgou-sentry edwardgou-sentry force-pushed the egou/feat/explore-prebuilt-queries branch from e978b34 to 6b1123c Compare May 1, 2025 01:52
@getsentry getsentry deleted a comment from github-actions bot May 1, 2025
Copy link
Contributor

github-actions bot commented May 1, 2025

This PR has a migration; here is the generated SQL for src/sentry/explore/migrations/0003_add_prebuilt_column_to_explore_saved_queries.py

for 0003_add_prebuilt_column_to_explore_saved_queries in explore

--
-- Add field prebuilt_id to exploresavedquery
--
ALTER TABLE "explore_exploresavedquery" ADD COLUMN "prebuilt_id" integer DEFAULT NULL NULL CHECK ("prebuilt_id" >= 0);
--
-- Add field prebuilt_version to exploresavedquery
--
ALTER TABLE "explore_exploresavedquery" ADD COLUMN "prebuilt_version" integer DEFAULT NULL NULL CHECK ("prebuilt_version" >= 0);
--
-- Add field starred to exploresavedquerystarred
--
ALTER TABLE "explore_exploresavedquerystarred" ADD COLUMN "starred" boolean DEFAULT true NOT NULL;
--
-- Alter field position on exploresavedquerystarred
--
ALTER TABLE "explore_exploresavedquerystarred" ALTER COLUMN "position" SET DEFAULT NULL;
ALTER TABLE "explore_exploresavedquerystarred" ALTER COLUMN "position" DROP NOT NULL;
--
-- Alter unique_together for exploresavedquery (1 constraint(s))
--
CREATE UNIQUE INDEX CONCURRENTLY "explore_exploresavedquer_organization_id_prebuilt_26175712_uniq" ON "explore_exploresavedquery" ("organization_id", "prebuilt_id");
ALTER TABLE "explore_exploresavedquery" ADD CONSTRAINT "explore_exploresavedquer_organization_id_prebuilt_26175712_uniq" UNIQUE USING INDEX "explore_exploresavedquer_organization_id_prebuilt_26175712_uniq";

Copy link

codecov bot commented May 1, 2025

Codecov Report

Attention: Patch coverage is 86.45161% with 21 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/explore/models.py 43.75% 9 Missing ⚠️
.../sentry/explore/endpoints/explore_saved_queries.py 82.50% 7 Missing ⚠️
...y/explore/endpoints/explore_saved_query_starred.py 25.00% 3 Missing ⚠️
...ry/explore/endpoints/explore_saved_query_detail.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #90720      +/-   ##
==========================================
- Coverage   87.78%   87.78%   -0.01%     
==========================================
  Files       10274    10275       +1     
  Lines      582608   582701      +93     
  Branches    22567    22567              
==========================================
+ Hits       511423   511498      +75     
- Misses      70756    70774      +18     
  Partials      429      429              

@edwardgou-sentry edwardgou-sentry requested review from a team May 1, 2025 03:08
@edwardgou-sentry edwardgou-sentry marked this pull request as ready for review May 1, 2025 03:08
@edwardgou-sentry edwardgou-sentry requested a review from a team as a code owner May 1, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant