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

Add request duration to the Elasticsearch response logs #124208

Closed
Tracked by #134169
mshustov opened this issue Feb 1, 2022 · 7 comments
Closed
Tracked by #134169

Add request duration to the Elasticsearch response logs #124208

mshustov opened this issue Feb 1, 2022 · 7 comments
Labels
enhancement New value added to drive a business result Feature:Logging impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. loe:medium Medium Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@mshustov
Copy link
Contributor

mshustov commented Feb 1, 2022

You can find the motivation description and proposed format in the parent issue #119062.
This issue is created to track implementation progress.

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc enhancement New value added to drive a business result loe:medium Medium Level of Effort Feature:Logging labels Feb 1, 2022
@elasticmachine
Copy link
Contributor

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

@exalate-issue-sync exalate-issue-sync bot added the impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. label Feb 1, 2022
@pgayvallet
Copy link
Contributor

In #119062, you said

Unforatuntely, elasticsearch-js client doesn't seem to measure how long the response took. I'm erring on the side of adding this logic to the elasticsearch-js client since it manages the underlying connections. If @delvedor agrees, I will open an issue.

Is the implementation going to be performed in the client itself, or is this issue about a custom implementation in Kibana?

@mshustov
Copy link
Contributor Author

@delvedor would evaluate the possibility of implementing this logic on the transport level. elastic/elastic-transport-js#35 Depending on his decision, we either rely on the transport implementation or implement it in Kibana.

@mshustov
Copy link
Contributor Author

@delvedor doesn't think it's worth adding this feature on the transport level due to performance overhead. See elastic/elastic-transport-js#40
@mikecote told me the Response Ops team needs this functionality, and they are ready to implement it on the plugin level. We need to sync with @mikecote to align on the implementation. Ideally, Core will enhance the ES client with this functionality, and other plugins can access duration via observability events. In this way, the Core can leverage request duration for logging purposes, the Response Ops team can use request duration for their internal logic (stop executing a slow query. for example).
It doesn't seem that we can mutate observability event content, but we can store requestStartTimestamp time on the transport level:

class KibanaTransport extends Transport {
  async request (params, options = {}) {
    options.context = { requestStartTimestamp: Date.now() }
    return super.request(params, options)
  }
}
// in obs events:
const took = Date.now()- event.meta.context.startTime;

Although, it would be awesome if we find a way to calculate the duration only once in the Core.

@mshustov mshustov changed the title Add response duration to the Elasticsearch response logs Add request duration to the Elasticsearch response logs Feb 17, 2022
@mikecote
Copy link
Contributor

@mshustov, keep us posted, we will go with our custom wrapper method at this time, but as soon as you have something to use, we can look into refactoring.

the Response Ops team can use request duration for their internal logic (stop executing a slow query. for example).

Our intent for stopping slow queries is to stop them when task manager determines the task ran for too long (abort existing searches when task manager sends a cancel execution signal). So I believe an event approach may not suit this use case but not sure.

cc @elastic/response-ops-execution

@pgayvallet
Copy link
Contributor

Although, it would be awesome if we find a way to calculate the duration only once in the Core.

elastic/elastic-transport-js#40 is imho the exact implementation we'd like to have.

If we want to implement the same feature from within core, to have something like

const { body, meta } = await client.ping({}, { meta: true });
const { duration } = meta;

We can for sure implement the logic in our custom Transport, but we will also need a way to extend the TransportResult and/or DiagnosticResult type to add this new meta.duration field. I don't see any easy way to do what without an ugly declare module statement to overload the client's types, which I don't like one bit.

Also, if this field is added from within our transport, I wonder if it would also be added to the events which are, from my understanding, emitted from lower (but need to confirm that, cc @delvedor)

client.diagnostic.on('response', (error, event) => {
  // will event.meta.duration be populated here?
});

@pgayvallet
Copy link
Contributor

Parent was closed, closing this one too

@pgayvallet pgayvallet closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Logging impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. loe:medium Medium Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

4 participants