Skip to content

[Code] distributed Code abstraction#41374

Merged
spacedragon merged 3 commits intoelastic:masterfrom
spacedragon:code_ha
Jul 31, 2019
Merged

[Code] distributed Code abstraction#41374
spacedragon merged 3 commits intoelastic:masterfrom
spacedragon:code_ha

Conversation

@spacedragon
Copy link
Copy Markdown
Contributor

@spacedragon spacedragon commented Jul 17, 2019

Summary

https://github.com/elastic/code/issues/1449

Basically, this PR provides an RPC style abstraction layer to dispatch resource-aware request to

  1. local kibana instance
  2. Code Node in the mutli-code mode
  3. kibana-ha node( in future)

How to

define a service definition object like the following:

export const GitServiceDefinition = {
  fileTree: {
    request: {} as {
      uri: string;
      path: string;
      revision: string;
      skip: number;
      limit: number;
      withParents: boolean;
      depth: number;
      flatten: boolean;
    },
    response: {} as FileTree,
  },
};

register it

  distributedCode.registerHandler(GitServiceDefinition, /* service implementation */);

consuming it

  // get the service
  const gitService = distributedCode.serviceFor(GitServiceDefinition);
 // locate the endpoint by request and resource uri
  const endpoint = await distributedCode.locate(req, uri);
// invoke service method
  const result = await gitService.fileTree(endpoint,  params)

Checklist

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

- [ ] This was checked for cross-browser compatibility, including a check against IE11
- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support

For maintainers

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/code

@spacedragon spacedragon force-pushed the code_ha branch 6 times, most recently from 0f17e2e to 42a21e2 Compare July 23, 2019 11:15
@spacedragon spacedragon marked this pull request as ready for review July 23, 2019 11:17
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elastic elastic deleted a comment from elasticmachine Jul 23, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown
Contributor

@mw-ding mw-ding left a comment

Choose a reason for hiding this comment

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

mostly good. leave some comments for discussions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these refactoring could possibly bring a bunch of conflicts with the new platform migration PR. since you have already done, let's just let it be. But please do not add more refactoring of the existing code now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm actually not very like the refactoring here, I think those code can be deleted if we use Dependency Injection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, that could save us from copying/pasting some instances around. let's do it in a separate one maybe after the new platform migration refactoring is done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: might as well add a logging for non-code-node here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another comment here is that since you have already introduced an adapter layer (CodeNodeAdapter, LocalAdapter), we can just leave the non-code-node logic into the abstraction of the adapter by creating a new adapter for non-code-node (e.g. RemoteHandlerAdapter so that we don't need to have a different initNonCodeNode function here. The init logic in my mind should look like

let adapter = null;
if (code node) {
   adapter = new CodeNodeAdapter(...);
} else if (non code node) {
   adapter = new RemoteHandlerAdapter(codeNodeUrl, ...)
} else {
  adapter = new LocalHandlerAdapter(...);
}

const codeServices = new CodeServices(adapter);
await initCodeNode(..., codeServices, ...)

Hopefully, this is more readable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that you already have a NonCodeNodeAdapter there, just replace RemoteHandlerAdapter to NonCodeNodeAdapter in the comment above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In non-code mode, I really don't want to initiate any local resource related code(git queue, etc). That's why initNonCodeNode exists

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: implementation -> implement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: a brief comment on that serverHandler will always be null here since it will be overridden by the request forwarding.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like Endpoint and RequestContext are pretty much the same thing based on this PR. The implementations of toContext() of each endpoints can be moved into their constructors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right, the endpoint was designed to represent the target kibana node address we are sending to. Here in Local and Multi-node mode, the address is always the same. So, they look like the same thing.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown
Contributor

@mw-ding mw-ding left a comment

Choose a reason for hiding this comment

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

LG. We might want to hold merging this PR to master until the 7.3 has been officially released just in case backporting code to 7.3 branch. Also, might need another quick sync on resolving conflicts with the new platform migration PR: #41192 (comment)

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@spacedragon spacedragon merged commit 0c8159f into elastic:master Jul 31, 2019
spacedragon pushed a commit to spacedragon/kibana that referenced this pull request Jul 31, 2019
* [Code] distributed Code abstraction
spacedragon pushed a commit that referenced this pull request Jul 31, 2019
* [Code] distributed Code abstraction
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jul 31, 2019
…-or-edit-existing-rollup-job

* 'master' of github.com:elastic/kibana: (114 commits)
  [ML] Fixing empty index pattern list (elastic#42299)
  [Markdown] Shim new platform - cleanup plugin (elastic#41760)
  [Code] Enable hierarchicalDocumentSymbolSupport for java language server (elastic#42233)
  Add New Platform mocks for data plugin (elastic#42261)
  Http server route handler implementation (elastic#41894)
  [SR] Allow custom index pattern to be used instead of selectable list when choosing indices to restore (elastic#41534)
  [Code] distributed Code abstraction (elastic#41374)
  [SIEM] Sets page titles to the current page you are on  (elastic#42157)
  Saved Objects export API stable type order (elastic#42310)
  cancellation of interpreter execution (elastic#40238)
  [SIEM] Fixes a crash when Machine Learning influencers is an undefined value (elastic#42198)
  Changed the job to work with a dedicated index (elastic#42297)
  FTR: fix testSubjects.missingOrFail (elastic#42290)
  Increase retry timeout to prevent flaky tests (elastic#42291)
  Spaces - make space a hidden saved object type (elastic#41688)
  Allow applications to register feature privileges which are excluded from the base privileges (elastic#41300)
  Disable flaky log column reorder test (elastic#42285)
  Fixing add element in element reducer (elastic#42276)
  Fix infinite loop (elastic#42228)
  [Maps][File upload] Remove geojson deep clone logic, handle on maps side (elastic#41835)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants