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

enable execution_context by default #119932

Merged
merged 2 commits into from Dec 1, 2021

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Nov 30, 2021

Summary

Closes #102706
Since the last time @dmlemeshko conducted load testing, Kibana has made several changes that have a significant impact on execution_context performance: upgrade nodejs to v16 and enable async_hooks by default

So the new testing is necessary. We want to enableexecution_context by default to provide the best UX with Kibana query source propagation to the Elasticsearch server.

Benchmarks

I use the standard DemoJourney scenario from https://github.com/elastic/kibana-load-testing
95pt of the response time shows the difference within the statistical error.
main branch
2021-11-30_10-39-45
PR brach
2021-11-30_10-42-35

Plugin API changes

It might be hard in the distributed environment to understand what Kibana entity initiated a request to the Elasticsearch server. To overcome this problem we introduced a content of execution_context to attach domain-specific metadata to every request. execution_context propagates specified metadata from the Kibana browser app or Kibana server to the Elasticsearch server via x-opaque-id header emitted to the Elasticsearch slow logs. For further details check a troubleshooting guide here.

Execution context has the following interface:

export type KibanaExecutionContext = {
  /** Kibana application initated an operation.*/
  readonly type: string; // 'visualization' | 'actions' | 'server' | ..;
  /** public name of a user-facing feature */
  readonly name: string; // 'TSVB' | 'Lens' |  'action_execution' | ..;
  /** unique value to identify the source */
  readonly id: string;
  /** human readable description. For example, a vis title, action name */
  readonly description: string;
  /** in browser - url to navigate to a current page, on server - endpoint path, for task: task SO url */
  readonly url?: string;
  /** a context that spawned the current context. */
  parent?: KibanaExecutionContext;
};

Kibana plugin can attach request specific metadata to an outbound HTTP request on the client side as

const parentContext = {
  type: 'my-app',
  name: 'my-plugin-ui-feature',
  id: '42',
  description: 'Retrieve number of X for Y',
};
async function getData() {
  return await http.get('...', { headers: new ExecutionContextContainer(parentContext).toHeader() });

and on the server-side you need to wrap any async operation with withContext helper:

 const chainB = service.withContext({
  type: 'my-app-server',
  name: 'my-plugin-server-feature',
  id: '43',
  description: 'Query Z',
  },
 async () => {
   return  await esClient.search(...);
 }
);

Then, in Elasticsearch slow logs you might find a hint that a request was initiated by my-plugin-ui-feature feature of my-app application and proxied through my-plugin-server-feature features of my-app-server app:

x-opaque-id: ${requestId};kibana:my-app:my-plugin-ui-feature:42;my-app-server:my-plugin-server-feature:42

Checklist

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Overhead of execution context tracking might be higher than anticipated. Low High We will keep an eye on the result of performance testing conducted on CI to make sure the PR doesn't affect performance. Should we spot a problem starting from the date of the merge, we would revert the PR.

For maintainers

@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. backport:skip This commit does not require backporting labels Nov 30, 2021
@mshustov
Copy link
Contributor Author

@elasticmachine merge upstream

@mshustov mshustov marked this pull request as ready for review November 30, 2021 14:07
@mshustov mshustov requested a review from a team as a code owner November 30, 2021 14:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@mshustov mshustov added the v8.1.0 label Dec 1, 2021
Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@mshustov mshustov merged commit 5667523 into elastic:main Dec 1, 2021
@mshustov mshustov deleted the enable-execution-context branch December 1, 2021 13:31
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
gbamparop pushed a commit to gbamparop/kibana that referenced this pull request Jan 12, 2022
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting chore release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Measure performance overhead of tracing solution for Kibana server
5 participants