-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[NP] KibanaRequest provides request abortion event #55061
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02344aa
add aborted$ observable to KibanaRequest
mshustov 98a5e5c
complete observable on request end
mshustov a48c47f
update docs
mshustov a934445
Merge branch 'master' into issue-44302-abort-events
mshustov 983e2be
update test suit names
mshustov 45142cf
Merge branch 'master' into issue-44302-abort-events
mshustov 19cb1f3
always finish subscription
mshustov 5ed4fc8
Merge branch 'master' into issue-44302-abort-events
mshustov 8607136
address comments
mshustov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.kibanarequest.events.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [KibanaRequest](./kibana-plugin-server.kibanarequest.md) > [events](./kibana-plugin-server.kibanarequest.events.md) | ||
|
|
||
| ## KibanaRequest.events property | ||
|
|
||
| Request events [KibanaRequestEvents](./kibana-plugin-server.kibanarequestevents.md) | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| readonly events: KibanaRequestEvents; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-server.kibanarequestevents.aborted_.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [KibanaRequestEvents](./kibana-plugin-server.kibanarequestevents.md) > [aborted$](./kibana-plugin-server.kibanarequestevents.aborted_.md) | ||
|
|
||
| ## KibanaRequestEvents.aborted$ property | ||
|
|
||
| Observable that emits once if and when the request has been aborted. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| aborted$: Observable<void>; | ||
| ``` |
20 changes: 20 additions & 0 deletions
20
docs/development/core/server/kibana-plugin-server.kibanarequestevents.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [KibanaRequestEvents](./kibana-plugin-server.kibanarequestevents.md) | ||
|
|
||
| ## KibanaRequestEvents interface | ||
|
|
||
| Request events. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| export interface KibanaRequestEvents | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | [aborted$](./kibana-plugin-server.kibanarequestevents.aborted_.md) | <code>Observable<void></code> | Observable that emits once if and when the request has been aborted. | | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import supertest from 'supertest'; | ||
|
|
||
| import { HttpService } from '../http_service'; | ||
|
|
||
| import { contextServiceMock } from '../../context/context_service.mock'; | ||
| import { loggingServiceMock } from '../../logging/logging_service.mock'; | ||
| import { createHttpServer } from '../test_utils'; | ||
|
|
||
| let server: HttpService; | ||
|
|
||
| let logger: ReturnType<typeof loggingServiceMock.create>; | ||
| const contextSetup = contextServiceMock.createSetupContract(); | ||
|
|
||
| const setupDeps = { | ||
| context: contextSetup, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| logger = loggingServiceMock.create(); | ||
|
|
||
| server = createHttpServer({ logger }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await server.stop(); | ||
| }); | ||
|
|
||
| const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); | ||
| describe('KibanaRequest', () => { | ||
| describe('events', () => { | ||
| describe('aborted$', () => { | ||
| it('emits once and completes when request aborted', async done => { | ||
| expect.assertions(1); | ||
| const { server: innerServer, createRouter } = await server.setup(setupDeps); | ||
| const router = createRouter('/'); | ||
|
|
||
| const nextSpy = jest.fn(); | ||
| router.get({ path: '/', validate: false }, async (context, request, res) => { | ||
| request.events.aborted$.subscribe({ | ||
| next: nextSpy, | ||
| complete: () => { | ||
| expect(nextSpy).toHaveBeenCalledTimes(1); | ||
| done(); | ||
| }, | ||
| }); | ||
|
|
||
| // prevents the server to respond | ||
| await delay(30000); | ||
| return res.ok({ body: 'ok' }); | ||
| }); | ||
|
|
||
| await server.start(); | ||
|
|
||
| const incomingRequest = supertest(innerServer.listener) | ||
| .get('/') | ||
| // end required to send request | ||
| .end(); | ||
|
|
||
| setTimeout(() => incomingRequest.abort(), 50); | ||
| }); | ||
|
|
||
| it('completes & does not emit when request handled', async () => { | ||
| const { server: innerServer, createRouter } = await server.setup(setupDeps); | ||
| const router = createRouter('/'); | ||
|
|
||
| const nextSpy = jest.fn(); | ||
| const completeSpy = jest.fn(); | ||
| router.get({ path: '/', validate: false }, async (context, request, res) => { | ||
| request.events.aborted$.subscribe({ | ||
| next: nextSpy, | ||
| complete: completeSpy, | ||
| }); | ||
|
|
||
| return res.ok({ body: 'ok' }); | ||
| }); | ||
|
|
||
| await server.start(); | ||
|
|
||
| await supertest(innerServer.listener).get('/'); | ||
|
|
||
| expect(nextSpy).toHaveBeenCalledTimes(0); | ||
| expect(completeSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('completes & does not emit when request rejected', async () => { | ||
| const { server: innerServer, createRouter } = await server.setup(setupDeps); | ||
| const router = createRouter('/'); | ||
|
|
||
| const nextSpy = jest.fn(); | ||
| const completeSpy = jest.fn(); | ||
| router.get({ path: '/', validate: false }, async (context, request, res) => { | ||
| request.events.aborted$.subscribe({ | ||
| next: nextSpy, | ||
| complete: completeSpy, | ||
| }); | ||
|
|
||
| return res.badRequest(); | ||
| }); | ||
|
|
||
| await server.start(); | ||
|
|
||
| await supertest(innerServer.listener).get('/'); | ||
|
|
||
| expect(nextSpy).toHaveBeenCalledTimes(0); | ||
| expect(completeSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.