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 calendar routes to use new platform router #56264

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Jan 29, 2020

Summary

Related meta issue: #49743

Updates all calendar routes to use new platform router.

Adds an isLegacy parameter to the CalendarManager so that it's still compatible with other route creators using callWithRequest.

I've left the type of client passed in as any for now, as job routes will be updated very soon and we'll be able to remove that legacy parameter and remove the need to have both types in CalendarManager.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

- [ ] This was checked for breaking API changes and was labeled appropriately
- [ ] This includes a feature addition or change that requires a release note and was labeled appropriately

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@peteharverson peteharverson mentioned this pull request Jan 29, 2020
78 tasks

constructor(isLegacy: boolean, client: any) {
this.isLegacy = isLegacy;
this.client = client;
Copy link
Member

@jgowdyelastic jgowdyelastic Jan 29, 2020

Choose a reason for hiding this comment

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

it might be worth making the isLegacy check once here in the constructor and setting this.client as either client or client.ml!.mlClient.callAsCurrentUser
Or even making the check outside of this class and only passing in the correct client when instantiating the class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call- much better. Added the legacy check in the constructor here: e4c0e64639120c16c78f85258334091d4ec0c6ea

try {
const resp = await this.callWithRequest('ml.calendars', { calendarId });
let resp;
if (this.isLegacy === true) {
Copy link
Member

Choose a reason for hiding this comment

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

as per the previous comment, having these checks inside the class seems unnecessary and means we'll have to change them again at some point in the future.

Copy link
Member

Choose a reason for hiding this comment

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

I've just seen the comment on this PR referring to the need for compatibility with the still legacy job service, so please ignore the suggestion of moving these checks out side of the class.
I still think the check could be moved to the constructor, so it's only happening once also isLegacy wouldn't need to be stored.

try {
const calendarIds = request.params.calendarIds.split(',');

if (calendarIds.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

nit, this could be a ternary

this.callWithRequest = callWithRequest;
this.eventManager = new EventManager(callWithRequest);
private isLegacy: boolean;
private client: any;
Copy link
Member

@jgowdyelastic jgowdyelastic Jan 29, 2020

Choose a reason for hiding this comment

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

for recent classes that i've written i've started all private class members with an underscore.
I don't know if this is something we want to try to do everywhere. I quite like the naming convention as it makes it easy to spot private and public members.
Other parts of Kibana have adopted this pattern but it seems to depend on the developer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated naming these with the underscore - e4c0e64639120c16c78f85258334091d4ec0c6ea

@@ -6,17 +6,46 @@

import _ from 'lodash';
Copy link
Member

Choose a reason for hiding this comment

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

it looks like only difference is used from lodash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to only pull in difference e4c0e64639120c16c78f85258334091d4ec0c6ea

@@ -0,0 +1,94 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

it's strange that calenadar_manager has been marked as a js -> ts rename by git, but this file hasn't.
it would be useful to try to retain the git history

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I'm not sure why that's the case. I'll look into it.

Copy link
Member

@jgowdyelastic jgowdyelastic Jan 29, 2020

Choose a reason for hiding this comment

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

it looks ok now. it shows it as a moved file. one of your subsequent comments must have made the difference.
probably removing the churn by removing all the isLegacy checks

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.

LGTM.

Just one question - I guess the ts-ignore can be removed from the routes that have been converted to TS. This calendars one, plus the one for data_frame_analytics which has already been done?

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

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-new-platform-calendar-routes branch from 95785c2 to 9908a66 Compare January 29, 2020 18:07
@alvarezmelissa87
Copy link
Contributor Author

alvarezmelissa87 commented Jan 29, 2020

Functional test failures were being caused by a missing definition in the schema (in the route validation) for calendar_id (as both that and the camel case version are used sometimes) and for event_id. This was causing the endpoint to return an error. I've updated the schema to include both of those as optional and tested that it works. 0d9e425

Will address removing use of both calendar_id and calendarId in a follow up.

cc @peteharverson, @jgowdyelastic

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@jgowdyelastic
Copy link
Member

Tested and calendar editing issue is fixed. LGTM

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.

Latest edit LGTM

@alvarezmelissa87 alvarezmelissa87 merged commit fb334ef into elastic:master Jan 30, 2020
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Jan 30, 2020
…form router (elastic#56264)

* migrate calendar routes to NP

* add proper types for calendars and events

* set actual client in constructor so isLegacy is not stored

* remove unnecessary comments

* fix calendar schema for missing calendar_id and event_id properties
@alvarezmelissa87 alvarezmelissa87 deleted the ml-new-platform-calendar-routes branch January 30, 2020 13:28
alvarezmelissa87 added a commit that referenced this pull request Jan 30, 2020
…form router (#56264) (#56379)

* migrate calendar routes to NP

* add proper types for calendars and events

* set actual client in constructor so isLegacy is not stored

* remove unnecessary comments

* fix calendar schema for missing calendar_id and event_id properties
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.

5 participants