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

[Endpoint] Integrate the Policy list with ingest datasources api #60548

Conversation

paul-tavares
Copy link
Contributor

@paul-tavares paul-tavares commented Mar 18, 2020

Summary

  • Remove the use of fake data generator
  • Uses the Ingest datasources REST API to retrieve a list of endpoint datasources (filters by datasource.package.name === 'endpoint')
  • Use Ingest datasources/{id} REST API to get details of a datasource
  • Adjust List view to show currently available data from API

endoing-policy-ingest-api-integration

Checklist

Delete any items that are not applicable to this PR.

@paul-tavares paul-tavares added WIP Work in progress v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 Team:Endpoint Management Feature:Endpoint Elastic Endpoint feature labels Mar 18, 2020
@paul-tavares paul-tavares self-assigned this Mar 18, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-management (Team:Endpoint Management)

@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Endpoint)

@paul-tavares paul-tavares marked this pull request as ready for review March 18, 2020 20:46
@paul-tavares paul-tavares requested a review from a team as a code owner March 18, 2020 20:46
* @param http
* @param options
*/
export const sendGetEndpoingDatasources = (
Copy link
Contributor

Choose a reason for hiding this comment

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

style suggestion: Endpoint is misspelled. Also, I'm not clear on the name of this function. Based on the doc comment, I would think endpointSpecificDatasource might be a good candidate for the name. Also, for clarity, would you consider adding an explicit return type?
I think Promise GetDatasourcesResponse> would be correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll change the name to fetchEndpointSpecificDatasources().
FYI - These are in fact Endpoint datasources - we will define them in the endpoint package and when creating a new one, the package.name will be set to endpoint and tie back to the package from where it was defined.

total,
},
});
dispatch({
Copy link
Contributor

Choose a reason for hiding this comment

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

would you consider moving the dispatch call outside the try block? If the reducer throws a runtime error, it'll be treated the same as if the HTTP call returned an error code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh - yes. good point. I personally like to keep the code inside of try {} blocks to a minimum since (I think) the JS compilers are not able to optimize that code. will move it out.

total,
},
});
} catch (err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since err will be any, the dispatch call accepts it even though the runtime value may not satisfy the expected payload type.

image

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 can't just pass the err through because the ApiServerError structure is in the body property of the error object returned by http.* methods, thus why I do the check below. I test this by adding a kuery param on the fetch above to make it fail 😞

}

if (action.type === 'userShownPolicyListServerFailedMessage') {
// Make sure that the apiError currently stored is the one the user was shown
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to understand the flow here. If an error is stored in state, the react view uses the toast services to show info about it, then dispatches this. If the error matches the one in state, we clear it.

What is the point of keeping track of that in state?

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 trying to protect against showing the same error multiple times - example: during a quick paginations. That being said, I just realized that useEffect() has the error set as the dependency, so it will not fire multiple times unless it changes. Will look at it a little closer and remove it is not needed (will change API fetching middleware/reducer to clear error on fetch)

// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
href={`${services.application.getUrlForApp('ingestManager')}#/configs/${version}`}
onClick={(ev: SyntheticEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for having the onClick here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It prevents a full browser refresh.

This might be avoidable - a few weeks ago one of the updates from the kibana-platform team was a change required by Plugins for how to use react-router. Mainly, I think they are now passing down to us an instance of their history which we should use in initializing our router (or just use react-router's sub-routes - maybe?). If we do use their history instance, then doing getting the history object from react-router (using the hook) and then doing a history.push might do the same thing as this code below.

I don't recall if we have an issue open to look into that routing change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW - @oatkiller question: I pinged the EUI team on why the @elastic/eui/href-or-on-click was enable, especially since we are mostly all using a router with history push. They said it was ok to turn it off. My question: should we turn it off across our plugin? (by introducing a .eslingrc.js file)

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Looking through the code I see a few places that are using a similar pattern.

I wrote this up a while ago, but would like your thoughts: oatkiller@d6861d8

Seeing that you're doing navigateToApp, instead of history.push, I don't think the commit would work for you out of the box. But I would like to have an easy way to reuse the logic that guards event.preventDefault

also @parkiino cause I was talking to her as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

re : changing lint rules. I've been contemplating changing lint rules since day 0. @stacey-gammon argued that having consistent rules across all of Kibana is worthwhile because it allows developers to contribute across the app with the same standards (and allows code to be theoretically copy-pasted around the app as well.)

In the past I used lint rules (and other forms of static analysis) heavily as a way to enforce consistency across the app, so it's something I still think about.

With that in mind, I think we should try to argue for the lint rules changes to happen Kibana-wide. If Kibana contributors at large disagree'd with our change, we could reevaluate then.

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 we should try to argue for the lint rules changes to happen Kibana-wide. If Kibana contributors at large disagree'd with our change, we could reevaluate then.

💯

For this particular issue, I think this should be a moot point once everything is converted to NP, there will no longer be the full page refresh navigating among apps. Though I'm surprised using navigateToApp somehow gets around the full page refresh. So maybe I am missing something else. cc @joshdover

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we're hitting the issue because we have not implemented the recent change in the NP to use the history instance provided by plugin mount() (this change #56705 )???
Will try that out to see if that is 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.

Ok, I tried it by using history.push() instead of navigateToApp() after making changes in our router to use the history instance passed by mount(), but still got full page refresh. Perhaps I'm missing something as to how we should interop with the core top-level router ( @joshdover ?? 😃 )

I'm laving in the code that uses navigateToApp() for now and will refactor if there is a better pattern to follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

From platform team:

Yea, we have an open issue to discuss about the best way to avoid that, and to allow 'plain' links to have the same behavior as navigateToApp . The onClick workaround used in the PR is the way to go for now unfortunately

Sorry for the extra work!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stacey-gammon no problem at all - appreciate the feedback.
Good to know that the platform team has this on their list of items to address in the future. The ability to "just handle it" is exactly what @chandlerprall suggested on Slack when I first approach the EUI team about possibly turning this ESLint rule off -

"...I recommend having an onClick at the document.body level that can programmatically interact with the router...."

@@ -25,14 +24,16 @@ export default function({ getPageObjects, getService }: FtrProviderContext) {
const policyTitle = await testSubjects.getVisibleText('policyViewTitle');
expect(policyTitle).to.equal('Policies');
});
it('shows policy count total', async () => {
// FIXME: Skipped until we can figure out how to load data for Ingest
it.skip('shows policy count total', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps just remove these tests? they'll be available in 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.

I'm thinking these will come right back in the not too far future.

@paul-tavares
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@paul-tavares paul-tavares merged commit 7983d1d into elastic:master Mar 20, 2020
@paul-tavares paul-tavares deleted the task/endpoint-150-policy-list-api-integration branch March 20, 2020 20:33
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 21, 2020
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 60548 or prevent reminders by adding the backport:skip label.

1 similar comment
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 60548 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

paul-tavares added a commit that referenced this pull request Mar 24, 2020
) (#60904)

* Use ingest API to get endpoint datasources

* Add `application` service to `KibanaContextProvider`

* Adjust Policy list to show data available from API

* Added ingest service + refactored middleware

* handle api failures/errors

* Removed policy list fake_data generator

* Fix typing

* Rename method + added explicit return type

* move dispatch outside of try block

* Removed unnecessary action

* Added FIXME comments with link to issue

* Skip some functional tests

* added tests for ingest service

* Policy list tests - turn it all off

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/endpoint/public/applications/endpoint/index.tsx
#	x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_list.tsx
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Endpoint Elastic Endpoint feature release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v8.0.0 WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants