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

[Fleet] Show Count of Agent Policies on Integration Details #86916

Merged

Conversation

paul-tavares
Copy link
Contributor

@paul-tavares paul-tavares commented Dec 23, 2020

Summary

  • Show the total unique count of Agent Policies currently using the given Integration on the page header
  • Adds new API /api/fleet/epm/packages/{pkgName}/stats which returns summary of agent policies

image

Closes #86369

Checklist

@paul-tavares paul-tavares added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.12.0 Team:Defend Workflows “EDR Workflows” sub-team of Security Solution labels Dec 23, 2020
@paul-tavares paul-tavares self-assigned this Dec 23, 2020
@paul-tavares paul-tavares requested a review from a team December 23, 2020 20:32
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@@ -190,12 +224,27 @@ describe('when on integration detail', () => {
});
});

interface MockedApi {
interface MockedApi<
Copy link
Contributor Author

@paul-tavares paul-tavares Dec 23, 2020

Choose a reason for hiding this comment

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

Some of this here is refactoring which will facilitate breaking this out to a separate set of test utilities so that this approach can be used with other test areas of Fleet.
The mocked api interface could now also return the set of functions that are used to fulfill the API calls, which allow each test case to adjust them (if necessary) before rendering the UI. An example of this can be seen above on line 69-70

Copy link
Contributor

@jfsiii jfsiii left a comment

Choose a reason for hiding this comment

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

I appreciate the tests. Can we wait to merge this until we've had a chance to discuss the goal of the new endpoint and any alternative names / locations?

Alternatively, we could merge this knowing it's subject to change on further review

@paul-tavares
Copy link
Contributor Author

@jfsiii sure, we can wait on this until a broader discussion can be had. Thanks for looking at it.

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

Code looks good, and works as expected. It so nice to start to see some frontend tests in Fleet :)
We should probably add this endpoint to our Open API spec

@@ -29,6 +29,7 @@ export const EPM_API_ROUTES = {
DELETE_PATTERN: EPM_PACKAGES_ONE,
FILEPATH_PATTERN: `${EPM_PACKAGES_FILE}/{filePath*}`,
CATEGORIES_PATTERN: `${EPM_API_ROOT}/categories`,
SUMMARY_PATTERN: `${EPM_PACKAGES_MANY}/{pkgName}/summary`,
Copy link
Member

Choose a reason for hiding this comment

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

nitpick maybe change the name to something a little less generic /stats /usages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Let's go with /stats since @jen-huang also suggested that for the name

…add-used-by-counts

# Conflicts:
#	x-pack/plugins/fleet/server/routes/epm/handlers.ts
Copy link
Member

@pzl pzl left a comment

Choose a reason for hiding this comment

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

Functionally, seems all good.

Noted a few places that could be cleaned up

@@ -29,6 +29,7 @@ export const EPM_API_ROUTES = {
DELETE_PATTERN: EPM_PACKAGES_ONE,
FILEPATH_PATTERN: `${EPM_PACKAGES_FILE}/{filePath*}`,
CATEGORIES_PATTERN: `${EPM_API_ROOT}/categories`,
STATS_PATTERN: `${EPM_PACKAGES_MANY}/{pkgName}/stats`,
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be called summary elsewhere. Perhaps we should make the var names consistent, to mentally correlate them a bit better.

If the route already exists and is /stats, I can see giving the route's var name the same as the route itself. But then it's switched to called summary on the layer right outside that. Consider naming the pattern var name summary as well. Reduces the mental context switch to just here, next to the route, which is a little more concrete to reason about.

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 have renamed everything else *Stats* in order keep consistent with this decision here 😄 . Thanks for highlighting that - "me culpa" 😞

x-pack/plugins/fleet/server/routes/epm/index.ts Outdated Show resolved Hide resolved
updated_at: '2020-12-22T21:28:05.383Z',
version: 'WzE1NTAsMV0=',
score: 0,
},
Copy link
Member

Choose a reason for hiding this comment

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

Is this much mocking and setup really necessary for testing paging?

Copy link
Contributor Author

@paul-tavares paul-tavares Jan 7, 2021

Choose a reason for hiding this comment

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

yes and no. Some packge policies (integration policies) can have the same Agent Policy id (with the exception of Endpoint, every other integration can be added to agent policies multiple times). The multiples assigned to the same agent policy is to ensure the counts remain accurate (it should just be counted once)

let savedObjectsResponse: typeof savedObjects;

switch (page) {
case 1:
Copy link
Member

Choose a reason for hiding this comment

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

so in this mock.. if it's page 1, you return index 1, the second element.

If it's page 2, you return indices 1,2,3?

It's not clear why you're doing this. It also doesn't seem like any of these scenarios are necessary in the tests below.

unless this is strictly for making sure the getPackageUsageSummary call doesn't error, but then I think this could all be simpler

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 catch. This here (below) should be savedObjects[0].
the idea is:

  • page 1 - return first item in array
  • page 2 - return every other array item after the first one

Doing this ensures that paging through the data works and that it de-dups the packages that are assigned to the same agent policy

@paul-tavares paul-tavares requested a review from pzl January 7, 2021 20:03
@paul-tavares
Copy link
Contributor Author

Ok. I think I got all of @pzl comment in. Ready for another round of 👀

@paul-tavares
Copy link
Contributor Author

@elasticmachine merge upstream

// in order to not cause a circular dependency (package policy service imports from this module)
const packagePolicies = await savedObjectsClient.find<PackagePolicySOAttributes>({
type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
perPage: 1000,
Copy link
Member

Choose a reason for hiding this comment

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

72ba2307367a0de7

Copy link
Contributor

@jfsiii jfsiii left a comment

Choose a reason for hiding this comment

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

I see some lingering references to *Summary (mostly in fleet/sections/epm/screens/detail/index.test.tsx). I'd like to remove them before merging, but we can merge and follow up.

@paul-tavares
Copy link
Contributor Author

Thanks @jfsiii . I am fixing those now 🙂

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
fleet 458 459 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
fleet 967.9KB 969.0KB +1.2KB

Page load bundle

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

id before after diff
fleet 376.8KB 376.9KB +142.0B

History

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

@paul-tavares paul-tavares merged commit 02695ef into elastic:master Jan 12, 2021
@paul-tavares paul-tavares deleted the task/fleet-86369-add-used-by-counts branch January 12, 2021 12:56
paul-tavares added a commit that referenced this pull request Jan 13, 2021
…88068)

* component to show count of agent policies for integration
* API route and service to return stats of package usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution Team:Fleet Team label for Observability Data Collection Fleet team v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Add 'Used by # agent policies" to the Integration Details header
6 participants