Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

insights: persist patternType in db#63579

Merged
stefanhengl merged 2 commits into
mainfrom
sh/kq/insights
Jul 3, 2024
Merged

insights: persist patternType in db#63579
stefanhengl merged 2 commits into
mainfrom
sh/kq/insights

Conversation

@stefanhengl

@stefanhengl stefanhengl commented Jul 1, 2024

Copy link
Copy Markdown
Member

This PR refactors insights to support the upcoming Keyword Search GA.

New insights are always persisted with patternType:.

Queries of existing insights are updated with patternType:standard <query> if they don't already specify a pattern type. This reflects the current default of the Stream API and thus, merely makes the pattern type explicit.

Notes:

  • The Insights UI has a lot of query input fields, but there are only 2 fields which allow the user to freely specify a pattern type: the interactive insight on the landing page and the query input field in the "Track Changes" creation form.

Test plan:

  • new unit test
  • existing tests pass without changes
  • manual testing:
    • I created a couple of insights and checked that the pattern type is persisted in the db.
    • I experimented with different default pattern types.
    • I tested the workflow to create an insight from the search results page.
    • I created a "language" insights and ran the migration to make sure we don't set pattern type in those cases.

This PR refactors insights to support the upcoming Keyword Search GA.

New insights are persisted with `patternType:` appended to query.
Existing insights are not affected.

Test plan:
- new unit test
- existing tests pass without changes
@cla-bot cla-bot Bot added the cla-signed label Jul 1, 2024
@github-actions github-actions Bot added team/product-platform team/search-platform Issues owned by the search platform team labels Jul 1, 2024
query: values.seriesQuery,
query: hasPatternType(values.seriesQuery)
? values.seriesQuery
: `patterntype:${defaultPatternType} ${values.seriesQuery}`,

@stefanhengl stefanhengl Jul 1, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Putting "patterntype:" in front of the query matches what we do in "Detect and track patterns" (see here). Code Monitors and Search Jobs, for example, append the pattern type.

export type InsightDataSeriesData = Pick<InsightDataSeries, 'seriesId' | 'label' | 'points'>

export function generateLinkURL(query: string | null): string | undefined {
export function generateLinkURL(query: string | null, defaultPatternType: SearchPatternType): string | undefined {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This caused a lot of other changes because I had to propagate the default pattern type until I hit the first React FC.

@stefanhengl stefanhengl requested a review from a team July 1, 2024 15:44
@stefanhengl stefanhengl marked this pull request as ready for review July 1, 2024 15:45

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR looks good to me overall.

New insights are persisted with patternType: appended to query. Existing insights are not affected... Execution of insights relies on the defaults of the Stream API (currently "V3"). This means existing code insights without pattern type will keep executing with "standard" pattern type until we update the API.

It feels like we should migrate existing insights too. Otherwise, what will we do in "Phase 2" when we introduce V4 and no longer want to default to V3? Also this would match what we did for notebooks.

@stefanhengl

Copy link
Copy Markdown
Member Author

This PR looks good to me overall.

New insights are persisted with patternType: appended to query. Existing insights are not affected... Execution of insights relies on the defaults of the Stream API (currently "V3"). This means existing code insights without pattern type will keep executing with "standard" pattern type until we update the API.

It feels like we should migrate existing insights too. Otherwise, what will we do in "Phase 2" when we introduce V4 and no longer want to default to V3? Also this would match what we did for notebooks.

For Phase 1 it is not really necessary to migrate the queries. The PR works as-is for GA. Even for Phase 2 we can either migrate the old queries or update the call of Insights to the Stream API and set "V3".

Based on your comment, though, I assume you prefer to migrate the queries ;-) I added a migration which updates the queries. PTAL

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We discussed offline and agreed the migration was nice, and not too risky. This way, there's a consistency across all stored data, and we don't need to worry about fixing the version type to V3.

UPDATE insight_series SET query_old = query;

-- prefix query with patternType:standard if there is no patterntype: in the query
UPDATE insight_series

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Nice to learn how revert this type of migration.

@stefanhengl stefanhengl merged commit 9b4e70f into main Jul 3, 2024
@stefanhengl stefanhengl deleted the sh/kq/insights branch July 3, 2024 07:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/search-platform Issues owned by the search platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants