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

EMT-146: use ingest agent for status info #63921

Merged

Conversation

nnamdifrankie
Copy link
Contributor

@nnamdifrankie nnamdifrankie commented Apr 18, 2020

Summary

https://github.com/elastic/endpoint-app-team/issues/146

  • Expose the AgentStatus in the IngestManager setup contract
  • Update integration and unit tests
  • Add new unit tests

Checklist

Delete any items that are not applicable to this PR.

@nnamdifrankie nnamdifrankie added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.8.0 labels Apr 18, 2020
@nnamdifrankie nnamdifrankie requested a review from a team as a code owner April 18, 2020 00:46
@nnamdifrankie nnamdifrankie requested a review from a team April 18, 2020 00:46
@nnamdifrankie
Copy link
Contributor Author

@elasticmachine merge upstream

@nnamdifrankie
Copy link
Contributor Author

@elasticmachine merge upstream

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'd like to avoid the new AgentService and getAgentStatus this PR currently has. Ingest Manager already has an Agent Service. I'd like to use that and its current function signatures, or update them to make them more useful/consistent/whatever, rather than add export a different one.

I made a comment where I think it might work. Ingest Manager's handlers do the same await agent ... getAgentStatus pattern so I don't think it's unusual for Endpoint to do it.

If getStatusById is useful Ingest Manager could add/export that. I'd prefer either to adding this new function & signature.

Comment on lines 170 to 173
const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatus(
metadataRequestContext.requestHandlerContext,
hostMetadata.elastic.agent.id
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatus(
metadataRequestContext.requestHandlerContext,
hostMetadata.elastic.agent.id
);
const { endpointAppContext, requestHandlerContext } = metadataRequestContext;
const { getAgent, getAgentStatus } = endpointAppContext.agentService;
const agent = await getAgent(requestHandlerContext.core.savedObjects.client, hostMetadata.elastic.agent.id);
const status = await getAgentStatus(agent);

Copy link
Contributor

Choose a reason for hiding this comment

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

I won't be able to try this locally until Monday afternoon, but I think this will work. If so, we can avoid the new getAgentStatus this PR adds in Ingest Manager.

Copy link
Contributor Author

@nnamdifrankie nnamdifrankie Apr 20, 2020

Choose a reason for hiding this comment

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

@jfsiii Can we talk about this. I would think a wholesale service will be better that performs the functionality will be better. And this does not isolate from changes to how agent status is derived. With this approach we have too much knowledge of the internal working of Ingest. This will mean will do a wholesale export of the entire services directory?

Copy link
Contributor

@jfsiii jfsiii Apr 20, 2020

Choose a reason for hiding this comment

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

@nnamdifrankie sure, we can talk anytime. I'm available most days from 1pm-5pm ET.

Before then, I'll try to summary my understanding & suggestions.

As I understand it, this PR adds an Agent Service but Ingest Manager already has one

It also adds a function getAgentStatus which a) is a duplicate of an existing function and b) uses the existing services functions from Ingest.

I'd like to avoid both those issues and think we can do that by moving that function into services/agents/status, changing its name to something like getAgentStatusById, and have it accept a saved object client and string id. That's in line with lots of our other service functions.

That way, all you're really changing at this call site is the function name and the first argument. It's still only calling one function and Ingest is the one in control of that logic.

-    const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatus(
-      metadataRequestContext.requestHandlerContext,

+    const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatusById(
+      metadataRequestContext.requestHandlerContext.core.savedObjects.client,

Hope that helps. Reach out any time to talk more.

@nnamdifrankie
Copy link
Contributor Author

@elasticmachine merge upstream

@@ -148,6 +150,9 @@ export class IngestManagerPlugin implements Plugin<IngestManagerSetupContract> {
}
return deepFreeze({
esIndexPatternService: new ESIndexPatternSavedObjectService(),
agentService: {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should expose agentService during start, it's probably not going to work if you use it during setup

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching that @nchaulet. Yeah, I believe we're encouraged to put as much as possible in start. Especially anything that could Error.

Copy link
Contributor Author

@nnamdifrankie nnamdifrankie Apr 21, 2020

Choose a reason for hiding this comment

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

I think this is a setup dependency, because we do the route registration in the setup method which I believe is the place for this action. These are just service definitions are they are not consumed in the setup step but in the handlers. Also if ingest does not setup correctly, then the endpoint is also not supposed to work either at least with how we depend on the ingest plugin today.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jfsiii @nchaulet should we move esIndexPatternService too? That one is reading from the saved objects in kibana, I suppose that could error as well right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes esIndexPatternService should probably be moved to start too.
If it's too much refacto for this PR I am ok to have a follow up PR for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, yeah I was talking with @nnamdifrankie about that. Right now endpoint is accessing the ingest contract in the setup function because that's where the routes are being registered. If we move the contract to the start function I think we'd have to use a singleton or something to point to the ingest contract because I don't think we can register the endpoint routes in the start function. It seems like other plugins do this. An example is the encrypted saved objects: https://github.com/elastic/kibana/blob/master/x-pack/plugins/actions/server/plugin.ts#L243

Might be easier to do that in a follow up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jfsiii jfsiii self-requested a review April 21, 2020 17:11
);
hostStatus = HOST_STATUS_MAPPING.get(status) || HostStatus.ERROR;
} catch (e) {
if (e.isBoom && e.output.statusCode === 404) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the ingest api throw a boom?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if a saved object is not found is going throw a Boom error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes,
server log [10:02:10.301] [warning][endpoint][metadata][plugins] agent with id 023fa40c-411d-4188-a941-4147bfadd095 not found

@nnamdifrankie
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Changes look good from an endpoint side.

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.

Good to me for the ingest manager part

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.

🚀 from me. Especially with the linked follow up PR.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@nnamdifrankie nnamdifrankie merged commit 4ca8610 into elastic:master Apr 21, 2020
@nnamdifrankie nnamdifrankie deleted the EMT-146_use_agent_service_for_status branch April 21, 2020 19:51
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 22, 2020
* master: (29 commits)
  [Dashboard] Deangularize navbar, attempt nr. 2 (elastic#61611)
  refactor action filter creation utils (elastic#62969)
  Refresh index pattern list before redirecting (elastic#63329)
  [APM]fixing custom link unit tests (elastic#64045)
  [Ingest] EPM & Fleet are enabled when Ingest is enabled (elastic#64103)
  [Alerting] Fixed bug with no possibility to edit the index name after adding (elastic#64033)
  [Maps] Map settings: min and max zoom (elastic#63714)
  [kbn-storybook] Use raw loader for text files (elastic#64108)
  [EPM] /packages/{package} endpoint to support upgrades (elastic#63629)
  [SIEM] New Platform Saved Objects Registration (elastic#64029)
  [Endpoint] Hook to handle events needing navigation via Router (elastic#63863)
  Fixed small issue in clone functionality (elastic#64085)
  [Endpoint]EMT-146: use ingest agent for status info (elastic#63921)
  [SIEM] Server NP Followup (elastic#64010)
  Register uiSettings on New Platform (elastic#64015)
  [Reporting] Integration polling config with client code (elastic#63754)
  [Docs]7.7 SIEM doc updates (elastic#63951)
  [SIEM] [Cases] Tags suggestions (elastic#63878)
  Include datasource UUID in agent config yaml, adjust overflow height of yaml view (elastic#64027)
  [DOCS] Add file size setting for Data Visualizer (elastic#64006)
  ...
nnamdifrankie added a commit that referenced this pull request Apr 22, 2020
[Endpoint]EMT-146: use ingest agent for status info
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 22, 2020
…ana into task-manager/cancel-logging

* 'task-manager/cancel-logging' of github.com:gmmorris/kibana: (28 commits)
  [Dashboard] Deangularize navbar, attempt nr. 2 (elastic#61611)
  refactor action filter creation utils (elastic#62969)
  Refresh index pattern list before redirecting (elastic#63329)
  [APM]fixing custom link unit tests (elastic#64045)
  [Ingest] EPM & Fleet are enabled when Ingest is enabled (elastic#64103)
  [Alerting] Fixed bug with no possibility to edit the index name after adding (elastic#64033)
  [Maps] Map settings: min and max zoom (elastic#63714)
  [kbn-storybook] Use raw loader for text files (elastic#64108)
  [EPM] /packages/{package} endpoint to support upgrades (elastic#63629)
  [SIEM] New Platform Saved Objects Registration (elastic#64029)
  [Endpoint] Hook to handle events needing navigation via Router (elastic#63863)
  Fixed small issue in clone functionality (elastic#64085)
  [Endpoint]EMT-146: use ingest agent for status info (elastic#63921)
  [SIEM] Server NP Followup (elastic#64010)
  Register uiSettings on New Platform (elastic#64015)
  [Reporting] Integration polling config with client code (elastic#63754)
  [Docs]7.7 SIEM doc updates (elastic#63951)
  [SIEM] [Cases] Tags suggestions (elastic#63878)
  Include datasource UUID in agent config yaml, adjust overflow height of yaml view (elastic#64027)
  [DOCS] Add file size setting for Data Visualizer (elastic#64006)
  ...
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 v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants