Skip to content

Commit

Permalink
Merge branch 'main' into fix_esql_inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson authored Aug 28, 2024
2 parents 255c680 + 6bb38c8 commit 710f493
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ function setUptimeAppStatus(
} else {
const hasUptimePrivileges = coreStart.application.capabilities.uptime?.show;
if (hasUptimePrivileges) {
const indexStatusPromise = UptimeDataHelper(coreStart).indexStatus('now-7d', 'now');
const indexStatusPromise = UptimeDataHelper(coreStart).indexStatus('now-7d/d', 'now/d');
indexStatusPromise.then((indexStatus) => {
if (indexStatus.indexExists) {
registerUptimeRoutesWithNavigation(coreStart, pluginsStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,97 @@ describe('TaskManagerRunner', () => {
);
expect(onTaskEvent).toHaveBeenCalledTimes(2);
});

test('emits TaskEvent when failing to update a recurring task', async () => {
const id = _.random(1, 20).toString();
const runAt = minutesFromNow(_.random(5));
const onTaskEvent = jest.fn();
const { runner, instance, store } = await readyToRunStageSetup({
onTaskEvent,
instance: {
id,
schedule: { interval: '1m' },
},
definitions: {
bar: {
title: 'Bar!',
createTaskRunner: () => ({
async run() {
return { runAt, state: {} };
},
}),
},
},
});

const error = new Error('fail');

store.update.mockImplementation(() => {
throw error;
});

await expect(runner.run()).rejects.toThrowError('fail');

expect(onTaskEvent).toHaveBeenCalledWith(
withAnyTiming(
asTaskRunEvent(
id,
asErr({
task: instance,
persistence: TaskPersistence.Recurring,
result: TaskRunResult.Failed,
isExpired: false,
error,
})
)
)
);
});

test('emits TaskEvent when failing to update a non-recurring task', async () => {
const id = _.random(1, 20).toString();
const runAt = minutesFromNow(_.random(5));
const onTaskEvent = jest.fn();
const { runner, instance, store } = await readyToRunStageSetup({
onTaskEvent,
instance: {
id,
},
definitions: {
bar: {
title: 'Bar!',
createTaskRunner: () => ({
async run() {
return { runAt, state: {} };
},
}),
},
},
});

const error = new Error('fail');

store.update.mockImplementation(() => {
throw error;
});

await expect(runner.run()).rejects.toThrowError('fail');

expect(onTaskEvent).toHaveBeenCalledWith(
withAnyTiming(
asTaskRunEvent(
id,
asErr({
task: instance,
persistence: TaskPersistence.NonRecurring,
result: TaskRunResult.Failed,
isExpired: false,
error,
})
)
)
);
});
});

test('does not update saved object if task expires', async () => {
Expand Down
64 changes: 39 additions & 25 deletions x-pack/plugins/task_manager/server/task_running/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,40 +719,54 @@ export class TaskManagerRunner implements TaskRunner {
await eitherAsync(
result,
async ({ runAt, schedule, taskRunError }: SuccessfulRunResult) => {
const processedResult = {
task,
persistence:
schedule || task.schedule ? TaskPersistence.Recurring : TaskPersistence.NonRecurring,
result: await (runAt || schedule || task.schedule
? this.processResultForRecurringTask(result)
: this.processResultWhenDone()),
};

// Alerting task runner returns SuccessfulRunResult with taskRunError
// when the alerting task fails, so we check for this condition in order
// to emit the correct task run event for metrics collection
// taskRunError contains the "source" (TaskErrorSource) data
if (!!taskRunError) {
debugLogger.debug(`Emitting task run failed event for task ${this.taskType}`);
const taskPersistence =
schedule || task.schedule ? TaskPersistence.Recurring : TaskPersistence.NonRecurring;
try {
const processedResult = {
task,
persistence: taskPersistence,
result: await (runAt || schedule || task.schedule
? this.processResultForRecurringTask(result)
: this.processResultWhenDone()),
};

// Alerting task runner returns SuccessfulRunResult with taskRunError
// when the alerting task fails, so we check for this condition in order
// to emit the correct task run event for metrics collection
// taskRunError contains the "source" (TaskErrorSource) data
if (!!taskRunError) {
debugLogger.debug(`Emitting task run failed event for task ${this.taskType}`);
this.onTaskEvent(
asTaskRunEvent(
this.id,
asErr({ ...processedResult, isExpired: taskHasExpired, error: taskRunError }),
taskTiming
)
);
} else {
this.onTaskEvent(
asTaskRunEvent(
this.id,
asOk({ ...processedResult, isExpired: taskHasExpired }),
taskTiming
)
);
}
} catch (err) {
this.onTaskEvent(
asTaskRunEvent(
this.id,
asErr({
...processedResult,
task,
persistence: taskPersistence,
result: TaskRunResult.Failed,
isExpired: taskHasExpired,
error: taskRunError,
error: err,
}),
taskTiming
)
);
} else {
this.onTaskEvent(
asTaskRunEvent(
this.id,
asOk({ ...processedResult, isExpired: taskHasExpired }),
taskTiming
)
);
throw err;
}
},
async ({ error }: FailedRunResult) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ({ getService, getPageObjects }) {
});
it('it should be able to access remote data', async () => {
await PageObjects.console.monaco.enterText(
'\nGET ftr-remote:makelogs工程-*/_search\n {\n "query": {\n "bool": {\n "must": [\n {"match": {"extension" : "jpg"} \n}\n}\n}\n}\n}'
'\nGET ftr-remote:makelogs工程-*/_search\n {\n "query": {\n "bool": {\n "must": [\n {"match": {"extension" : "jpg"} \n}\n]\n}\n}\n}'
);
await PageObjects.console.clickPlay();
await retry.try(async () => {
Expand Down

0 comments on commit 710f493

Please sign in to comment.