mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Uptime][Monitor Management] Make synthetics service monitors config sync task interval configurable (#122327) (#121233)
* Making synthetics service monitors config sync task interval configurable and reschedule the task on config update. #121233
This commit is contained in:
parent
3e91803d3a
commit
90532485f9
2 changed files with 27 additions and 13 deletions
|
@ -37,6 +37,7 @@ export const config: PluginConfigDescriptor = {
|
|||
password: schema.string(),
|
||||
manifestUrl: schema.string(),
|
||||
hosts: schema.maybe(schema.arrayOf(schema.string())),
|
||||
syncInterval: schema.maybe(schema.string()),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
ConcreteTaskInstance,
|
||||
TaskManagerSetupContract,
|
||||
TaskManagerStartContract,
|
||||
TaskInstance,
|
||||
} from '../../../../task_manager/server';
|
||||
import { UptimeServerSetup } from '../adapters';
|
||||
import { installSyntheticsIndexTemplates } from '../../rest_api/synthetics_service/install_index_templates';
|
||||
|
@ -37,6 +38,7 @@ import {
|
|||
const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_TYPE =
|
||||
'UPTIME:SyntheticsService:Sync-Saved-Monitor-Objects';
|
||||
const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID = 'UPTIME:SyntheticsService:sync-task';
|
||||
const SYNTHETICS_SERVICE_SYNC_INTERVAL_DEFAULT = '5m';
|
||||
|
||||
export class SyntheticsService {
|
||||
private logger: Logger;
|
||||
|
@ -125,27 +127,38 @@ export class SyntheticsService {
|
|||
});
|
||||
}
|
||||
|
||||
public scheduleSyncTask(taskManager: TaskManagerStartContract) {
|
||||
taskManager
|
||||
.ensureScheduled({
|
||||
public async scheduleSyncTask(
|
||||
taskManager: TaskManagerStartContract
|
||||
): Promise<TaskInstance | null> {
|
||||
const interval =
|
||||
this.config.unsafe.service.syncInterval ?? SYNTHETICS_SERVICE_SYNC_INTERVAL_DEFAULT;
|
||||
|
||||
try {
|
||||
await taskManager.removeIfExists(SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID);
|
||||
const taskInstance = await taskManager.ensureScheduled({
|
||||
id: SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID,
|
||||
taskType: SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_TYPE,
|
||||
schedule: {
|
||||
interval: '1m',
|
||||
interval,
|
||||
},
|
||||
params: {},
|
||||
state: {},
|
||||
scope: ['uptime'],
|
||||
})
|
||||
.then((_result) => {
|
||||
this.logger?.info(`Task ${SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID} scheduled. `);
|
||||
})
|
||||
.catch((e) => {
|
||||
this.logger?.error(
|
||||
`Error running task: ${SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID}, `,
|
||||
e?.message() ?? e
|
||||
);
|
||||
});
|
||||
|
||||
this.logger?.info(
|
||||
`Task ${SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID} scheduled with interval ${taskInstance.schedule?.interval}.`
|
||||
);
|
||||
|
||||
return taskInstance;
|
||||
} catch (e) {
|
||||
this.logger?.error(
|
||||
`Error running task: ${SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID}, `,
|
||||
e?.message() ?? e
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getOutput(request?: KibanaRequest) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue