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

[ML] New Platform server shim: update annotation routes to use new platform router #57067

Conversation

alvarezmelissa87
Copy link
Contributor

Summary

Updates all annotation routes to use new platform router.

Checklist

Delete any items that are not applicable to this PR.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@peteharverson peteharverson mentioned this pull request Feb 7, 2020
78 tasks
@elasticmachine
Copy link
Contributor

💔 Build Failed


Test Failures

Kibana Pipeline / x-pack-intake-agent / X-Pack Jest Tests.x-pack/legacy/plugins/ml/server/models/annotation_service.annotation_service deleteAnnotation() should delete annotation

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has not failed recently on tracked branches


Stack Trace

TypeError: Cannot read property 'mlClient' of undefined
    at annotationProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.ts:72:41)
    at annotationServiceProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/index.ts:12:8)
    at Object.it (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.test.ts:38:36)
    at resolve (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
    at new Promise (<anonymous>)
    at mapper (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
    at promise.then (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:73:41)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Kibana Pipeline / x-pack-intake-agent / X-Pack Jest Tests.x-pack/legacy/plugins/ml/server/models/annotation_service.annotation_service getAnnotation() should get annotations for specific job

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has not failed recently on tracked branches


Stack Trace

TypeError: Cannot read property 'mlClient' of undefined
    at annotationProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.ts:72:41)
    at annotationServiceProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/index.ts:12:8)
    at Object.it (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.test.ts:58:34)
    at resolve (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
    at new Promise (<anonymous>)
    at mapper (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
    at promise.then (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:73:41)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Kibana Pipeline / x-pack-intake-agent / X-Pack Jest Tests.x-pack/legacy/plugins/ml/server/models/annotation_service.annotation_service getAnnotation() should throw and catch an error

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has not failed recently on tracked branches


Stack Trace

TypeError: Cannot read property 'mlClient' of undefined
    at annotationProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.ts:72:41)
    at annotationServiceProvider (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/index.ts:12:8)
    at Object.it (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/legacy/plugins/ml/server/models/annotation_service/annotation.test.ts:88:34)
    at Object.asyncJestTest (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)
    at resolve (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
    at new Promise (<anonymous>)
    at mapper (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
    at promise.then (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/jest-jasmine2/build/queueRunner.js:73:41)
    at process._tickCallback (internal/process/next_tick.js:68:7)

and 3 more failures, only showing the first 3.

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

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Looks good overall, just added some questions/suggestions.

@@ -67,7 +68,8 @@ export type callWithRequestType = (
params: annotationProviderParams
) => Promise<any>;

export function annotationProvider(callWithRequest: callWithRequestType) {
export function annotationProvider(context: RequestHandlerContext) {
const callAsCurrentUser = context.ml!.mlClient.callAsCurrentUser;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we work around this in another way? The styleguide says to avoid non-null assertions https://github.com/elastic/kibana/blob/master/STYLEGUIDE.md#avoid-non-null-assertions

Copy link
Member

@jgowdyelastic jgowdyelastic Feb 7, 2020

Choose a reason for hiding this comment

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

I agree, this has been bothering me too in the recent NP work.
Does ml need to be optional in our RequestHandlerContext interface? especially as we're asserting that it isn't optional in every route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding ml to the RequestHandlerContext interface was initially made optional to prevent issues with other plugins using RequestHandlerContext. This was the suggested definition from kibana-platform.
Had a chat with Josh about this and looks like they'll be improving this by adding a generic type arg to core.http.createRouter so you can specify your own type for RequestHandlerContext. The PR should be up soon. Then we'll be able to get rid of the non-null assertions. 🙌
So we're stuck with this for now but once that PR is in we can add the change in the next routes PR 👌

{
path: '/api/ml/annotations',
validate: {
body: schema.object({
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of moving all schema definitions to new_platform/annotations_schema.ts for consistency even if they are not as complex as the indexAnnotationSchema one?

{
path: '/api/ml/annotations/delete/{annotationId}',
validate: {
params: schema.object({ annotationId: schema.string() }),
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of moving all schema definitions to new_platform/annotations_schema.ts for consistency even if they are not as complex as the indexAnnotationSchema one?

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested these changes, and all works fine, apart from the annotations tab in the Jobs list where I am seeing this error:

image

}

const { indexAnnotation } = annotationServiceProvider(context);
const username = _.get(request, 'auth.credentials.username', ANNOTATION_USER_UNKNOWN);
Copy link
Contributor

Choose a reason for hiding this comment

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

There doesn't seem to be an auth object as part of the request with this NP switch, so this is always getting set to 'unknown'. We must have to get the logged in username some other way.

image

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 10, 2020

Choose a reason for hiding this comment

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

Looks like this is no longer available in the NP request object. It has to be accessed via the NP security plugin api - added in a4ad5a5

cc @peteharverson

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested latest edits and LGTM

@alvarezmelissa87
Copy link
Contributor Author

Thanks, everyone, for taking a look 😄 This is ready for a final check when you get a chance! cc @jgowdyelastic, @walterra

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@alvarezmelissa87 alvarezmelissa87 merged commit 9fd75db into elastic:master Feb 11, 2020
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 11, 2020
…atform router (elastic#57067)

* update annotation routes to use NP router

* create ts file for feature check

* update schema to allow null value for earliest/latestMs

* update annotations model test

* use NP security plugin to access user info
@alvarezmelissa87 alvarezmelissa87 deleted the ml-new-platform-annotation-routes branch February 11, 2020 18:43
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 11, 2020
…atform router (elastic#57067)

* update annotation routes to use NP router

* create ts file for feature check

* update schema to allow null value for earliest/latestMs

* update annotations model test

* use NP security plugin to access user info
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 11, 2020
* master: (27 commits)
  Include actions new platform plugin for codeowners (elastic#57252)
  [APM][docs] 7.6 documentation updates (elastic#57124)
  Expressions refactor (elastic#54342)
  [ML] New Platform server shim: update annotation routes to use new platform router  (elastic#57067)
  Remove injected ui app vars from Canvas (elastic#56190)
  update max_anomaly_score route schema to handle possible undefined values (elastic#57339)
  [Add panel flyout] Moving create new to the top of SavedObjectFinder (elastic#56428)
  Add mock of a legacy ui api to re-enable Canvas storybook (elastic#56673)
  [monitoring] Removes noisy event received log (elastic#57275)
  Remove use of copied MANAGEMENT_BREADCRUMBS and use `setBreadcrumbs` from management section's mount (elastic#57324)
  Advanced Settings management app to kibana platform plugin (elastic#56931)
  [ML] New Platform server shim: update recognize modules routes to use new platform router (elastic#57206)
  [ML] Fix overall stats for saved search on the Data Visualizer page (elastic#57312)
  [ML] [NP] Removing ui imports (elastic#56358)
  [SIEM] Fixes failing Cypress tests (elastic#57202)
  Create observability CODEOWNERS reference (elastic#57109)
  fix results service schema (elastic#57217)
  don't register a wrapper if browser side function exists. (elastic#57196)
  Ui Actions explorer example (elastic#57006)
  Fix update alert API to still work when AAD is out of sync (elastic#57039)
  ...
alvarezmelissa87 added a commit that referenced this pull request Feb 11, 2020
…atform router (#57067) (#57361)

* update annotation routes to use NP router

* create ts file for feature check

* update schema to allow null value for earliest/latestMs

* update annotations model test

* use NP security plugin to access user info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration :ml release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants