[UA] Move Kibana stacktrace from UI to logs (#33150)

This commit is contained in:
Josh Dover 2019-03-20 12:16:38 -05:00 committed by GitHub
parent 2a10de423c
commit 14cce19c67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 8 deletions

View file

@ -25,6 +25,7 @@ import {
describe('reindexService', () => {
let actions: jest.Mocked<any>;
let callCluster: jest.Mock;
let log: jest.Mock;
let xpackInfo: { feature: jest.Mocked<any> };
let service: ReindexService;
@ -52,6 +53,7 @@ describe('reindexService', () => {
runWhileIndexGroupLocked: jest.fn(async (group: string, f: any) => f({ attributes: {} })),
};
callCluster = jest.fn();
log = jest.fn();
xpackInfo = {
feature: jest.fn(() => ({
isAvailable() {
@ -62,7 +64,8 @@ describe('reindexService', () => {
},
})),
};
service = reindexServiceFactory(callCluster as any, xpackInfo as any, actions);
service = reindexServiceFactory(callCluster as any, xpackInfo as any, actions, log);
});
describe('hasRequiredPrivileges', () => {
@ -580,6 +583,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.created);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=true',
method: 'POST',
@ -594,6 +598,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.created);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=true',
method: 'POST',
@ -617,6 +622,7 @@ describe('reindexService', () => {
expect(
updatedOp.attributes.errorMessage!.includes('Could not stop ML jobs')
).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=true',
method: 'POST',
@ -638,6 +644,7 @@ describe('reindexService', () => {
expect(
updatedOp.attributes.errorMessage!.includes('Some nodes are not on minimum version')
).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
// Should not have called ML endpoint at all
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=true',
@ -690,6 +697,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.created);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_stop',
method: 'POST',
@ -704,6 +712,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.created);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_stop',
method: 'POST',
@ -725,6 +734,7 @@ describe('reindexService', () => {
expect(
updatedOp.attributes.errorMessage!.includes('Could not stop Watcher')
).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_stop',
method: 'POST',
@ -760,6 +770,7 @@ describe('reindexService', () => {
);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
it('fails if setting updates fail', async () => {
@ -770,6 +781,7 @@ describe('reindexService', () => {
);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
});
@ -804,6 +816,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.readonly);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
it('fails if create index fails', async () => {
@ -815,6 +828,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.readonly);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
// Original index should have been set back to allow reads.
expect(callCluster).toHaveBeenCalledWith('indices.putSettings', {
@ -859,6 +873,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.newIndexCreated);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
});
@ -916,6 +931,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.reindexStarted);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
});
@ -999,6 +1015,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.reindexCompleted);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
it('fails if switching aliases fails', async () => {
@ -1007,6 +1024,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.reindexCompleted);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage).not.toBeNull();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
});
});
@ -1075,6 +1093,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=false',
method: 'POST',
@ -1090,6 +1109,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=false',
method: 'POST',
@ -1110,6 +1130,7 @@ describe('reindexService', () => {
expect(
updatedOp.attributes.errorMessage!.includes('Could not resume ML jobs')
).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).toHaveBeenCalledWith('transport.request', {
path: '/_ml/set_upgrade_mode?enabled=false',
method: 'POST',
@ -1176,6 +1197,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_start',
method: 'POST',
@ -1191,6 +1213,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).not.toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_start',
method: 'POST',
@ -1211,6 +1234,7 @@ describe('reindexService', () => {
expect(
updatedOp.attributes.errorMessage!.includes('Could not start Watcher')
).toBeTruthy();
expect(log).toHaveBeenCalledWith(['upgrade_assistant', 'error'], expect.any(String));
expect(callCluster).toHaveBeenCalledWith('transport.request', {
path: '/_watcher/_start',
method: 'POST',

View file

@ -6,6 +6,7 @@
import Boom from 'boom';
import { Server } from 'hapi';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import { XPackInfo } from 'x-pack/plugins/xpack_main/server/lib/xpack_info';
import {
@ -98,7 +99,8 @@ export interface ReindexService {
export const reindexServiceFactory = (
callCluster: CallCluster,
xpackInfo: XPackInfo,
actions: ReindexActions
actions: ReindexActions,
log: Server['log']
): ReindexService => {
// ------ Utility functions
@ -575,10 +577,15 @@ export const reindexServiceFactory = (
break;
}
} catch (e) {
log(
['upgrade_assistant', 'error'],
`Reindexing step failed: ${e instanceof Error ? e.stack : e.toString()}`
);
// Trap the exception and add the message to the object so the UI can display it.
lockedReindexOp = await actions.updateReindexOp(lockedReindexOp, {
status: ReindexStatus.failed,
errorMessage: e instanceof Error ? e.stack : e.toString(),
errorMessage: e.toString(),
});
// Cleanup any changes, ignoring any errors.

View file

@ -57,7 +57,8 @@ export class ReindexWorker {
this.reindexService = reindexServiceFactory(
this.callWithInternalUser,
this.xpackInfo,
reindexActionsFactory(this.client, this.callWithInternalUser)
reindexActionsFactory(this.client, this.callWithInternalUser),
this.log
);
ReindexWorker.workerSingleton = this;
@ -161,7 +162,7 @@ export class ReindexWorker {
const fakeRequest = { headers: credential } as Request;
const callCluster = this.callWithRequest.bind(null, fakeRequest) as CallCluster;
const actions = reindexActionsFactory(this.client, callCluster);
const service = reindexServiceFactory(callCluster, this.xpackInfo, actions);
const service = reindexServiceFactory(callCluster, this.xpackInfo, actions, this.log);
reindexOp = await swallowExceptions(service.processNextStep, this.log)(reindexOp);
// Update credential store with most recent state.

View file

@ -74,7 +74,12 @@ export function registerReindexIndicesRoutes(
const { indexName } = request.params;
const callCluster = callWithRequest.bind(null, request) as CallCluster;
const reindexActions = reindexActionsFactory(client, callCluster);
const reindexService = reindexServiceFactory(callCluster, xpackInfo, reindexActions);
const reindexService = reindexServiceFactory(
callCluster,
xpackInfo,
reindexActions,
server.log
);
try {
if (!(await reindexService.hasRequiredPrivileges(indexName))) {
@ -118,7 +123,12 @@ export function registerReindexIndicesRoutes(
const { indexName } = request.params;
const callCluster = callWithRequest.bind(null, request) as CallCluster;
const reindexActions = reindexActionsFactory(client, callCluster);
const reindexService = reindexServiceFactory(callCluster, xpackInfo, reindexActions);
const reindexService = reindexServiceFactory(
callCluster,
xpackInfo,
reindexActions,
server.log
);
try {
const hasRequiredPrivileges = await reindexService.hasRequiredPrivileges(indexName);
@ -157,7 +167,12 @@ export function registerReindexIndicesRoutes(
const { indexName } = request.params;
const callCluster = callWithRequest.bind(null, request) as CallCluster;
const reindexActions = reindexActionsFactory(client, callCluster);
const reindexService = reindexServiceFactory(callCluster, xpackInfo, reindexActions);
const reindexService = reindexServiceFactory(
callCluster,
xpackInfo,
reindexActions,
server.log
);
try {
await reindexService.cancelReindexing(indexName);