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

[data / saved query] BWCA all the routes #158790

Merged
merged 21 commits into from
Jun 19, 2023

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented May 31, 2023

Summary

All routes

  • Use versioned router
  • Moved to internal path
  • Validate responses
  • All responses are typed with response types, separate from internal api types. This is to help prevent unacknowledged changes to the api.
  • Version is included in all requests

@mattkime mattkime changed the title add versioning to all routes [data / saved query] BWCA all the routes Jun 3, 2023
@mattkime mattkime added release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Jun 3, 2023
@mattkime mattkime self-assigned this Jun 3, 2023
* These types are used to define the shape of the response from the saved query API
*/

// @ts-expect-error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this is necessary - this type is essentially copied from MatchAllFilterMeta where it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bizarrely, this seems to be caused by Filter being an interface instead of a type. It looks like that's why packages/kbn-es-query/src/filters/build_filters/types.ts uses a type with // eslint-disable-next-line @typescript-eslint/consistent-type-definitions instead:

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type Filter = {
$state?: {
store: FilterStateStore;
};
meta: FilterMeta;
query?: Record<string, any>;
};

I have no idea why the compiler doesn't like this though 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm mostly confused because I made sure my copied Filter is also a type and yet the compiler still complains.

@mattkime mattkime marked this pull request as ready for review June 3, 2023 05:06
@mattkime mattkime requested review from a team as code owners June 3, 2023 05:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

The changes are looking good overall, just a couple of validation issues to fix up and a few comments.

src/plugins/data/server/query/routes.ts Outdated Show resolved Hide resolved
src/plugins/data/server/query/routes.ts Outdated Show resolved Hide resolved
* These types are used to define the shape of the response from the saved query API
*/

// @ts-expect-error
Copy link
Contributor

Choose a reason for hiding this comment

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

Bizarrely, this seems to be caused by Filter being an interface instead of a type. It looks like that's why packages/kbn-es-query/src/filters/build_filters/types.ts uses a type with // eslint-disable-next-line @typescript-eslint/consistent-type-definitions instead:

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type Filter = {
$state?: {
store: FilterStateStore;
};
meta: FilterMeta;
query?: Record<string, any>;
};

I have no idea why the compiler doesn't like this though 🤔

src/plugins/data/server/query/route_types.ts Outdated Show resolved Hide resolved
src/plugins/data/server/query/route_types.ts Show resolved Hide resolved
src/plugins/data/server/query/routes.ts Outdated Show resolved Hide resolved
src/plugins/data/server/query/routes.ts Show resolved Hide resolved
@mattkime mattkime requested a review from a team as a code owner June 13, 2023 10:08
@mattkime
Copy link
Contributor Author

@davismcphee I overlooked this for a few days, its ready for another looks.

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Tested again locally and all is working as expected now 👍 thanks for the changes, LGTM!

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Changes LGTM!

@kertal
Copy link
Member

kertal commented Jun 19, 2023

@elasticmachine merge upstream

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

Looks great 🚀 and works well as well. Left a comment about something I was not sure.

@@ -15,7 +17,7 @@ export const createSavedQuery = (
) =>
rootRequest<SavedQuery>({
method: 'POST',
url: '/api/saved_query/_create',
url: `${SAVED_QUERY_BASE_URL}/_create`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure so I am writing here for your consideration if you think it makes sense for security solution to use createQuery function instead of calling this API directly.

Although, if we go down that way, createQuery would need to expose version as well so that users can easily pass it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either the REST api should be used or the plugin api contract. This looks like a test setup - REST api usage looks fine to me but your team might also decide something different.

@mattkime mattkime enabled auto-merge (squash) June 19, 2023 13:47
@mattkime mattkime merged commit 9e74fcf into elastic:main Jun 19, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #2 / Detection response view Open in timeline "after each" hook for "opens timeline with correct query count for hosts by alert severity table"
  • [job] [logs] Investigations - Security Solution Tests #2 / Detection response view Open in timeline "after each" hook for "opens timeline with correct query count for open alerts by rule table"
  • [job] [logs] Security Solution Tests #2 / Detection response view Open in timeline opens timeline with correct query count for hosts by alert severity table
  • [job] [logs] Investigations - Security Solution Tests #2 / Detection response view Open in timeline opens timeline with correct query count for open alerts by rule table

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 404.7KB 404.8KB +89.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
data 52 54 +2
enterpriseSearch 13 15 +2
securitySolution 411 415 +4
total +8

Total ESLint disabled count

id before after diff
data 54 56 +2
enterpriseSearch 14 16 +2
securitySolution 494 498 +4
total +8

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime

@kibanamachine kibanamachine added v8.9.0 backport:skip This commit does not require backporting labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants