-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Ingest Manager] Don't retain POST /setup results. fixes #74587 #75372
Merged
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bf2196d
add retries for registry requests.
73a7e04
Fix TS issue. Add link to node-fetch error docs
a565c02
Restore some accidentally deleted code.
877ecd7
Add more comments. Remove logging.
2a2fd17
Merge branch 'master' into registry-retry
elasticmachine bf973b7
Merge branch 'master' into registry-retry
elasticmachine 3440dd7
Add tests for plugin setup service & handlers
f6a8272
Add tests for Registry retry logic
44ed63b
Extract setup retry logic to separate function/file
a077988
Add tests for setup retry logic
ab56cfa
Merge branch 'master' into registry-retry
elasticmachine 85cf9b8
More straightforward(?) tests for setup caching
b7ce43e
Merge branch 'master' into registry-retry
elasticmachine 27a0252
Revert cached setup. Still limit 1 call at a time
e220bbd
Merge branch 'master' into registry-retry
elasticmachine 409ef85
Merge branch 'master' into registry-retry
elasticmachine a7d7261
New name & tests for one-at-a-time /setup behavior
a6bd2d2
More (better?) renaming
fe66914
Fix name in test description
3a89cde
Fix spelling typo.
deafa13
Remove registry retry code & tests
a913911
Use async fn's .catch to avoid unhandled rejection
55d7bba
Merge branch 'master' of github.com:elastic/kibana into 74587-retry-f…
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
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/ingest_manager/server/routes/setup/handlers.test.ts
This file contains 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,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { xpackMocks } from '../../../../../../x-pack/mocks'; | ||
import { httpServerMock } from 'src/core/server/mocks'; | ||
import { PostIngestSetupResponse } from '../../../common'; | ||
import { RegistryError } from '../../errors'; | ||
import { createAppContextStartContractMock } from '../../mocks'; | ||
import { ingestManagerSetupHandler } from './handlers'; | ||
import { appContextService } from '../../services/app_context'; | ||
import { setupIngestManager } from '../../services/setup'; | ||
|
||
jest.mock('../../services/setup', () => { | ||
return { | ||
setupIngestManager: jest.fn(), | ||
}; | ||
}); | ||
|
||
const mockSetupIngestManager = setupIngestManager as jest.MockedFunction<typeof setupIngestManager>; | ||
|
||
describe('ingestManagerSetupHandler', () => { | ||
let context: ReturnType<typeof xpackMocks.createRequestHandlerContext>; | ||
let response: ReturnType<typeof httpServerMock.createResponseFactory>; | ||
let request: ReturnType<typeof httpServerMock.createKibanaRequest>; | ||
|
||
beforeEach(async () => { | ||
context = xpackMocks.createRequestHandlerContext(); | ||
response = httpServerMock.createResponseFactory(); | ||
request = httpServerMock.createKibanaRequest({ | ||
method: 'post', | ||
path: '/api/ingest_manager/setup', | ||
}); | ||
// prevents `Logger not set.` and other appContext errors | ||
appContextService.start(createAppContextStartContractMock()); | ||
}); | ||
|
||
afterEach(async () => { | ||
jest.clearAllMocks(); | ||
appContextService.stop(); | ||
}); | ||
|
||
it('POST /setup succeeds w/200 and body of resolved value', async () => { | ||
mockSetupIngestManager.mockImplementation(() => Promise.resolve({ isIntialized: true })); | ||
await ingestManagerSetupHandler(context, request, response); | ||
|
||
const expectedBody: PostIngestSetupResponse = { isInitialized: true }; | ||
expect(response.customError).toHaveBeenCalledTimes(0); | ||
expect(response.ok).toHaveBeenCalledWith({ body: expectedBody }); | ||
}); | ||
|
||
it('POST /setup fails w/500 on custom error', async () => { | ||
mockSetupIngestManager.mockImplementation(() => | ||
Promise.reject(new Error('SO method mocked to throw')) | ||
); | ||
await ingestManagerSetupHandler(context, request, response); | ||
|
||
expect(response.customError).toHaveBeenCalledTimes(1); | ||
expect(response.customError).toHaveBeenCalledWith({ | ||
statusCode: 500, | ||
body: { | ||
message: 'SO method mocked to throw', | ||
}, | ||
}); | ||
}); | ||
|
||
it('POST /setup fails w/502 on RegistryError', async () => { | ||
mockSetupIngestManager.mockImplementation(() => | ||
Promise.reject(new RegistryError('Registry method mocked to throw')) | ||
); | ||
|
||
await ingestManagerSetupHandler(context, request, response); | ||
expect(response.customError).toHaveBeenCalledTimes(1); | ||
expect(response.customError).toHaveBeenCalledWith({ | ||
statusCode: 502, | ||
body: { | ||
message: 'Registry method mocked to throw', | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#74507 (comment)