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

[Security Solution] update endpoint list api to support united index #112758

Merged
merged 3 commits into from
Sep 27, 2021

Conversation

joeypoon
Copy link
Member

Summary

metadata list api will now first attempt to query the united metadata index to save on extra fleet-agent queries.
if the index is not found, it will fallback to the existing query.
this PR is backwards compatible and will work even without endpoint package updates.

Checklist

For maintainers

@joeypoon joeypoon added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution auto-backport Deprecated - use backport:version if exact versions are needed v7.16.0 labels Sep 21, 2021
@joeypoon joeypoon requested a review from a team September 21, 2021 22:11
@@ -41,36 +41,42 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta
return 'online';
}

export function buildKueryForEnrollingAgents() {
return 'not (last_checkin:*)';
export function buildKueryForEnrollingAgents(path: string = '') {
Copy link
Member Author

Choose a reason for hiding this comment

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

adding an optional path to the fields since we copy .fleet-agents mapping but are additionally nesting it

async function fetchIndexPatterns(): Promise<IIndexPattern[]> {
// this needs to be called after endpointPackageVersion is loaded (getEndpointPackageInfo)
// or else wrong pattern might be loaded
async function fetchIndexPatterns(
Copy link
Member Author

Choose a reason for hiding this comment

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

use the endpoint package version to determine which index the kql bar should use for auto completion

return response.ok({
body: await mapToHostResultList(queryParams, hostListQueryResult, metadataRequestContext),
body: await legacyListMetadataQuery(
Copy link
Member Author

Choose a reason for hiding this comment

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

existing logic was just moved into this method with no change in logic.


const result = await context.core.elasticsearch.client.asCurrentUser.search<HostMetadata>(
queryParams
const { unitedIndexExists, unitedQueryResponse } = await queryUnitedIndex(
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the new query to the new united index

const filterIgnoredAgents =
ignoredAgentIds && ignoredAgentIds.length > 0
? {
must_not: { terms: { 'agent.id': ignoredAgentIds } },
Copy link
Member Author

Choose a reason for hiding this comment

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

do we need to support HostDetails... like the legacy query here? if this is being written by endpoint I'm guessing it's possible they can run an older version which still uses HostDetails?

@joeypoon joeypoon force-pushed the feature/united-transform branch 2 times, most recently from 0f95c98 to 1ee59e2 Compare September 22, 2021 14:48
@joeypoon joeypoon marked this pull request as ready for review September 22, 2021 14:48
@joeypoon joeypoon requested review from a team as code owners September 22, 2021 14:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

@joeypoon
Copy link
Member Author

@elasticmachine merge upstream

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Sep 22, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

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.

Fleet changes 🚀 (these strings interpolation seems a little fragile to me and we should probably move to another pattern like a query builder or other one day to have something more robust here, at least we have some functional tests that cover these queries)

@kevinlog
Copy link
Contributor

@joeypoon - awesome job on this so far.

I check it out, tried it, and found a few issues. Let me know if you have any questions.

Here are the cases I tested.

Original/backwards compatible mode

  • Enroll a single real Agent with Endpoint, Endpoint shows in Endpoint list ✅
  • Unenroll Agent, Endpoint is removed from Endpoint list ✅
  • Enroll Agent with Endpoint, Endpoint appears in list, remove Endpoint integration ONLY, Endpoint is removed from list ✅
  • Generate 100 docs with the generator, all docs appear in list ✅

New transforms

  • Enroll a single real Agent with Endpoint, Endpoint shows in Endpoint list ✅
  • Unenroll Agent, Endpoint is removed from Endpoint list ❌
    • The Endpoint record remained in the list while the Agent was removed from the Agents list
  • Enroll Agent with Endpoint, Endpoint appears in list, remove Endpoint integration ONLY, Endpoint is removed from list ✅
    • I tried this scenario a few times. I added the Endpoint integration to the Agent policy and deleted it a handful of times. It worked as expected each time
  • Generate 100 docs with the generator, all docs appear in list ❌ ❓
    • I saw some odd behavior on this one. I could see the docs coming into the destination indices, but the Endpoint list didn't render correctly. I think the generator may need to be updated? There are some screenshots below of the scenario.

You can see pagination and "Showing" number, but it doesn't render.
image

I can see the docs in the indices, so may it has to do with the shape of them?
image

@joeypoon joeypoon force-pushed the feature/united-transform branch 2 times, most recently from 7fea806 to 6730ea8 Compare September 23, 2021 21:30
@joeypoon
Copy link
Member Author

joeypoon commented Sep 23, 2021

thanks for checking @kevinlog

  • Unenroll Agent, Endpoint is removed from Endpoint list ❌

latest push should fix that one and also fixes the issue with generated docs kind of showing up in the list (they don't show up at all now, this is expected since generated docs don't currently merge in the endpoint metadata into the doc).

…ta index

metadata list api will now first attempt to query the united metadata index to save on extra fleet-agent queries.
if the index is not found, it will fallback to the existing query.
@joeypoon joeypoon force-pushed the feature/united-transform branch from 6730ea8 to c8e6451 Compare September 27, 2021 16:51
@joeypoon
Copy link
Member Author

endpoint generator also works with united index with latest commit 👌

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.

🐑 ?

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2224 2225 +1

Async chunks

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

id before after diff
securitySolution 4.2MB 4.2MB +231.0B

Page load bundle

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

id before after diff
fleet 132.4KB 132.3KB -15.0B
securitySolution 108.4KB 108.4KB +80.0B
total +65.0B

History

  • 💔 Build #155506 failed 6730ea8a7180508c7d6217c3561ced669bf6bc67
  • 💔 Build #155501 failed 7fea80600d02ac554a00165335146297a3cc70c5
  • 💚 Build #155084 succeeded 822942ddc8658a83c182f897f4cc63a5d72df496
  • 💔 Build #154997 failed 1ee59e2e1b5d3e72c99d4dd48a31179992780b20
  • 💔 Build #154790 failed 0f95c98a8b68f5298564735f01b11942416b306b

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

@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed 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.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants