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 views] Use versioned router for REST routes #158608

Merged
merged 49 commits into from
Jun 13, 2023

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented May 27, 2023

Summary

Version alllll the data view routes.

Best viewed with whitespace hidden - https://github.com/elastic/kibana/pull/158608/files?diff=unified&w=1

In this PR:

  • All REST (public and internal) routes are versioned
  • Internal routes are called with version specified
  • Internal and public routes are now stored in directories labeled as such
  • All routes have a response schema
  • All responses are typed with response types, separate from internal api types. This is to help prevent unacknowledged changes to the api.
  • Moves some functional tests from js => ts

For follow up PRs:

  • Move to internal path for internal routes
  • Proper typing and schema for fields_for_wildcard filter

Closes #157099
Closes #157100

@mattkime mattkime changed the title version create data view [data views] Use versioned router for REST routes May 27, 2023
@mattkime mattkime self-assigned this May 28, 2023
@mattkime mattkime added Feature:Data Views Data Views code and UI - index patterns before 8.0 Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:skip Skip the PR/issue when compiling release notes labels May 28, 2023
@mattkime mattkime marked this pull request as ready for review May 28, 2023 02:14
@mattkime mattkime requested a review from a team as a code owner May 28, 2023 02:14
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Looking good! Have some questions about the scope:

Is it required or not to pass INITIAL_REST_VERSION or 1 where that API is called?
Is it required or not to type API responses?

{
path,
validate: {},
version: '1', // INITIAL_REST_VERSION,
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
version: '1', // INITIAL_REST_VERSION,
version: '1',

@@ -38,6 +38,8 @@ export const parseFields = (fields: string | string[]): string[] => {
};

const path = '/api/index_patterns/_fields_for_wildcard';
const version = '1';
const access = 'internal';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it okay to keep /api in the path if it's an internal route?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ideally all internal routes should be prefixed with /internal, but I don't think we included this one in the audit either.

cc @thomasneirynck looks like /api/index_patterns/_fields_for_wildcard is another candidate for making internal.

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.

Did another round of reviewing and testing. The latest code changes seem good to me, but I'm still running into some issues hitting some endpoints.

The data view update endpoint returns 500:
dataview_update

I'm still getting a strange response from the data view delete endpoint:
dataview_delete

And the update runtime field endpoint returns 400:
runtime_update

timeSeriesDimension: schema.maybe(schema.boolean()),
});

const validate: FullValidationConfig<any, any, any> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious what the types marked any are for?

Copy link
Contributor Author

@mattkime mattkime Jun 7, 2023

Choose a reason for hiding this comment

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

export interface RouteValidatorConfig<P, Q, B> {
  /**
   * Validation logic for the URL params
   * @public
   */
  params?: RouteValidationSpec<P>;
  /**
   * Validation logic for the Query params
   * @public
   */
  query?: RouteValidationSpec<Q>;
  /**
   * Validation logic for the body payload
   * @public
   */
  body?: RouteValidationSpec<B>;
}

...I could probably do a better job using these

@mattkime
Copy link
Contributor Author

mattkime commented Jun 7, 2023

@davismcphee I must have fixed those and then unfixed them. At any rate, they should be working now. One item -

And the update runtime field endpoint returns 400:

The problem is a lack of type value. As best I can tell that poor error message is a bug in the schema validation error messages. Supply "type": "keyword", and it should work.

@@ -41,21 +41,6 @@ export default function ({ getService }: FtrProviderContext) {

expect(response4.status).to.be(404);
});
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 removed this test because there was a weird relationship between it at and the versioned router. The versioned router would provide a weird message even though the task completed successfully and this is the circumstance under which this test would pass. Now the api returns no body and I'm no longer testing for its emptiness - which wasn't registering as emptiness in this test for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

What was it registering as instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

res.ok() on the sender side results in an empty object for the body

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.

@davismcphee I must have fixed those and then unfixed them. At any rate, they should be working now. One item -

Tested again and looks like the issues are fixed now 👍 thanks! Just a couple of questions to answer first, then this will be good to merge on my end.

And the update runtime field endpoint returns 400:

The problem is a lack of type value. As best I can tell that poor error message is a bug in the schema validation error messages. Supply "type": "keyword", and it should work.

Yup, looks like that fixed it, thanks! Although the docs I pulled this example from show an update without the type prop: https://www.elastic.co/guide/en/kibana/master/data-views-runtime-field-api-update.html#data-views-runtime-field-update-example. Is it the docs that are wrong and need to be updated or did we used to allow updates without specifying the type?

@@ -41,21 +41,6 @@ export default function ({ getService }: FtrProviderContext) {

expect(response4.status).to.be(404);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

What was it registering as instead?

@mattkime
Copy link
Contributor Author

What was it registering as instead?

An empty object - I restored the test and it now checks for an empty object instead of an empty value.

@mattkime
Copy link
Contributor Author

@davismcphee You're right and the docs are right - I added validation that didn't allow updating a runtime field without specifying the type. I'll address this.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

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
dataViews 44.6KB 44.6KB +38.0B
Unknown metric groups

API count

id before after diff
@kbn/core-http-server 444 447 +3

ESLint disabled in files

id before after diff
dataViews 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
dataViews 13 14 +1
enterpriseSearch 20 22 +2
securitySolution 491 495 +4
total +7

History

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

cc @mattkime

@mattkime
Copy link
Contributor Author

@davismcphee I added a test for partial runtime field updates and fixed the corresponding schema issues.

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.

Latest code changes look good and the update runtime field endpoint works without type now. Thanks for updating/adding tests too! LGTM 👍

@mattkime mattkime merged commit 26d4ba5 into elastic:main Jun 13, 2023
@kibanamachine kibanamachine added v8.9.0 backport:skip This commit does not require backporting labels Jun 13, 2023
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 13, 2023
* main: (199 commits)
  [Lens] Add custom formatter within the Lens editor (elastic#158468)
  [Uptime] Hide app if no data is available (elastic#159118)
  [CodeEditor] Add grok highlighting (elastic#159334)
  Expose decoded cloudId components from the cloud plugin's contract (elastic#159442)
  [Profiling] Use collector and symbolizer integrations in the add data page (elastic#159481)
  [Infrastructure UI] Hosts View: Unified Search bar with auto-refresh enabled (elastic#157011)
  [APM] Add feature flag for not available apm schema (elastic#158911)
  [Lens] Remove deprecated componentWillReceiveProps usage (elastic#159502)
  [api-docs] 2023-06-13 Daily api_docs build (elastic#159536)
  [data views] Use versioned router for REST routes (elastic#158608)
  [maps] fix geo line source not loaded unless maps application is opened (elastic#159432)
  [Enterprise Search][Search application]Fix Create Api key url (elastic#159519)
  [Security Solution] Increase timeout for indexing hosts (elastic#159518)
  dashboard Reset button disable (elastic#159430)
  [Security Solution] Unskip Endpoint API tests after package fix (elastic#159484)
  [Synthetics] adjust alert timing (elastic#159511)
  [ResponseOps][rule registry] Remove usages of `refresh: true` (elastic#159252)
  Revert "Remove unused package (elastic#158597)"
  [Serverless] Adding config to disable authentication on task manager background worker utilization API (elastic#159505)
  Remove unused package (elastic#158597)
  ...
mattkime added a commit that referenced this pull request Jun 16, 2023
…#159758)

## Summary

Response validation is failing when there are field conflicts. Disable
response validation until a complete schema can be created.

Problem was introduced in #158608
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 Feature:Data Views Data Views code and UI - index patterns before 8.0 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.

[DataViews] internal routes must satisfy bwca [DataViews] public routes must satsify bwca
7 participants