{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/kibana/issues/44302","repository_url":"https://api.github.com/repos/elastic/kibana","labels_url":"https://api.github.com/repos/elastic/kibana/issues/44302/labels{/name}","comments_url":"https://api.github.com/repos/elastic/kibana/issues/44302/comments","events_url":"https://api.github.com/repos/elastic/kibana/issues/44302/events","html_url":"https://github.com/elastic/kibana/issues/44302","id":486518968,"node_id":"MDU6SXNzdWU0ODY1MTg5Njg=","number":44302,"title":"Scoped Elasticsearch client should automatically cancel ES requests when browser disconnects","user":{"login":"joshdover","id":1813008,"node_id":"MDQ6VXNlcjE4MTMwMDg=","avatar_url":"https://avatars2.githubusercontent.com/u/1813008?v=4","gravatar_id":"","url":"https://api.github.com/users/joshdover","html_url":"https://github.com/joshdover","followers_url":"https://api.github.com/users/joshdover/followers","following_url":"https://api.github.com/users/joshdover/following{/other_user}","gists_url":"https://api.github.com/users/joshdover/gists{/gist_id}","starred_url":"https://api.github.com/users/joshdover/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshdover/subscriptions","organizations_url":"https://api.github.com/users/joshdover/orgs","repos_url":"https://api.github.com/users/joshdover/repos","events_url":"https://api.github.com/users/joshdover/events{/privacy}","received_events_url":"https://api.github.com/users/joshdover/received_events","type":"User","site_admin":false},"labels":[{"id":635458035,"node_id":"MDU6TGFiZWw2MzU0NTgwMzU=","url":"https://api.github.com/repos/elastic/kibana/labels/Feature:New%20Platform","name":"Feature:New Platform","color":"0e8a16","default":false},{"id":470241278,"node_id":"MDU6TGFiZWw0NzAyNDEyNzg=","url":"https://api.github.com/repos/elastic/kibana/labels/Team:Platform","name":"Team:Platform","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-08-28T17:43:11Z","updated_at":"2019-09-06T13:08:57Z","closed_at":null,"author_association":"MEMBER","body":"When a browser request disconnects, we should cancel any pending requests to Elasticsearch that the browser request started. This could be done via the ScopedClient class that has access to the raw server request.\r\n\r\nThis would eliminate wasted Elasticsearch CPU cycles for results that will never be used.\r\n\r\nDoing this at the global ElasticsearchService level would allows us to have this behavior by default for all Elasticsearch requests, but we should also provide an escape hatch to opt-out of this behavior for a given request.\r\n\r\n### Example\r\n```ts\r\nrouter.get(\r\n  { path: 'my-route/', validation },\r\n  async (context, req, res) => {\r\n    const { dataClient } = context.core.elasticsearch;\r\n    \r\n    // This request would automatically cancel if the browser\r\n    // disconnects from Kibana early\r\n    const results = await dataClient.callForCurrentUser('search', query);\r\n    \r\n    // This request would not automatically cancel\r\n    const results = await dataClient.callForCurrentUser('search', query, {\r\n      cancelOnDisconnect: false\r\n    });\r\n  }\r\n);\r\n```\r\n\r\n\r\nRelated: https://github.com/elastic/kibana/pull/42764"},"comment":{"url":"https://api.github.com/repos/elastic/kibana/issues/comments/528847911","html_url":"https://github.com/elastic/kibana/issues/44302#issuecomment-528847911","issue_url":"https://api.github.com/repos/elastic/kibana/issues/44302","id":528847911,"node_id":"MDEyOklzc3VlQ29tbWVudDUyODg0NzkxMQ==","user":{"login":"stacey-gammon","id":16563603,"node_id":"MDQ6VXNlcjE2NTYzNjAz","avatar_url":"https://avatars3.githubusercontent.com/u/16563603?v=4","gravatar_id":"","url":"https://api.github.com/users/stacey-gammon","html_url":"https://github.com/stacey-gammon","followers_url":"https://api.github.com/users/stacey-gammon/followers","following_url":"https://api.github.com/users/stacey-gammon/following{/other_user}","gists_url":"https://api.github.com/users/stacey-gammon/gists{/gist_id}","starred_url":"https://api.github.com/users/stacey-gammon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stacey-gammon/subscriptions","organizations_url":"https://api.github.com/users/stacey-gammon/orgs","repos_url":"https://api.github.com/users/stacey-gammon/repos","events_url":"https://api.github.com/users/stacey-gammon/events{/privacy}","received_events_url":"https://api.github.com/users/stacey-gammon/received_events","type":"User","site_admin":false},"created_at":"2019-09-06T13:08:57Z","updated_at":"2019-09-06T13:08:57Z","author_association":"CONTRIBUTOR","body":"fwiw, I think this will block the new data access services from being in NP and replacing courier (https://github.com/elastic/kibana/issues/29215)."}}
{"actor":{"display_login":"stacey-gammon"}}