Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
31c0e58
Add initator field to backfill
nkhristinin Oct 6, 2025
b154793
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Oct 6, 2025
26daa71
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Oct 6, 2025
4c14e11
Fixes types
nkhristinin Oct 6, 2025
8e2c648
Merge branch 'backfill-iniator' of github.com:nkhristinin/kibana into…
nkhristinin Oct 6, 2025
65ed6f5
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Oct 6, 2025
213c9fb
update types
nkhristinin Oct 6, 2025
977f06e
Merge branch 'backfill-iniator' of github.com:nkhristinin/kibana into…
nkhristinin Oct 6, 2025
c3e43e7
Fix more types
nkhristinin Oct 7, 2025
4e19aa2
fix more types
nkhristinin Oct 7, 2025
981580e
Merge branch 'main' into backfill-iniator
elasticmachine Oct 7, 2025
fb677d6
Fix tests
nkhristinin Oct 8, 2025
a2853d8
Merge branch 'backfill-iniator' of github.com:nkhristinin/kibana into…
nkhristinin Oct 8, 2025
a74fce3
Add task, api, event log mappings
nkhristinin Oct 17, 2025
b65b5aa
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Oct 17, 2025
25c7ba1
Fix how task get space from request
nkhristinin Oct 22, 2025
bd19d50
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Oct 22, 2025
14839b1
Return default value for space
nkhristinin Oct 22, 2025
de66f16
use backfill initator constant
nkhristinin Oct 23, 2025
163655b
Some fixes
nkhristinin Oct 23, 2025
d84bd51
fix some unit tests
nkhristinin Oct 23, 2025
e6e0d53
Merge branch 'main' into gap-auto-fill-task
nkhristinin Oct 27, 2025
5f2be71
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Oct 27, 2025
62332f2
fixes
nkhristinin Oct 27, 2025
0f9f792
Merge branch 'main' into gap-auto-fill-task
nkhristinin Oct 27, 2025
4fc5880
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Oct 27, 2025
6e1efdf
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Oct 27, 2025
63a4f54
Fix tests and types
nkhristinin Oct 27, 2025
7f641e4
Change tests and fix how we check overlapps
nkhristinin Oct 28, 2025
bd4c92d
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Oct 28, 2025
dc56f7b
Simplify tets
nkhristinin Oct 28, 2025
ea5a982
Fix sorting gaps
nkhristinin Oct 28, 2025
9a49039
Fix types
nkhristinin Oct 29, 2025
27d8fa2
Some PR fixes
nkhristinin Oct 29, 2025
fc45533
Merge branch 'main' into gap-auto-fill-task
elasticmachine Oct 29, 2025
f64d923
Fix some tests
nkhristinin Oct 29, 2025
072ce05
fix amount of SO
nkhristinin Oct 29, 2025
050b4ca
Add some tests, fix types, and default values
nkhristinin Oct 29, 2025
688257c
fix more tets
nkhristinin Oct 29, 2025
cc0892c
some fixes
nkhristinin Oct 30, 2025
b22663d
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Oct 30, 2025
646c24c
update tests
nkhristinin Oct 30, 2025
478e0c7
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Oct 30, 2025
4020cf8
fix tests
nkhristinin Oct 31, 2025
292c0fa
Merge branch 'main' into gap-auto-fill-task
elasticmachine Oct 31, 2025
6da188b
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 3, 2025
529a9b3
Add read/write
nkhristinin Nov 4, 2025
186c110
Remove params for feature flag
nkhristinin Nov 4, 2025
78fba04
Update schema
nkhristinin Nov 4, 2025
8332730
Extract date from the loop
nkhristinin Nov 4, 2025
cdc2561
Use lodash for chunk
nkhristinin Nov 4, 2025
d82a383
Remove wasCanceled, use abortController
nkhristinin Nov 4, 2025
e18a29a
Default timeout
nkhristinin Nov 4, 2025
c94c1b8
Update tests
nkhristinin Nov 5, 2025
5ac0c42
Fix more tests
nkhristinin Nov 5, 2025
2ae242b
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 5, 2025
b614f28
Add cleanup of stuck gaps
nkhristinin Nov 6, 2025
cb1bb77
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine Nov 6, 2025
119a32d
Merge branch 'main' into gap-auto-fill-task
nkhristinin Nov 10, 2025
51afe46
Throw error if duplicate for rule type consumer
nkhristinin Nov 10, 2025
12de6ea
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine Nov 10, 2025
51ed5b3
fix types
nkhristinin Nov 10, 2025
2b7afdd
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 10, 2025
418ac39
update fields
nkhristinin Nov 10, 2025
25134a1
Changes from node scripts/check_mappings_update --fix
kibanamachine Nov 10, 2025
110d04d
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Nov 10, 2025
5998915
Update API path
nkhristinin Nov 11, 2025
5e2c09c
Rename amount_of_retries
nkhristinin Nov 11, 2025
7ff212e
Validate gap_fill_range
nkhristinin Nov 11, 2025
8157587
Ensure we are not leaking request
nkhristinin Nov 11, 2025
2bd5d0d
Remoe schedule task id
nkhristinin Nov 11, 2025
da6ab37
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 11, 2025
fd116c2
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Nov 11, 2025
efaab1e
Add rule types as param to get rules with gaps method
nkhristinin Nov 12, 2025
ebf94e1
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 12, 2025
3983a1c
Add get scheduler endpoint
nkhristinin Nov 14, 2025
7c4d001
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 14, 2025
91f0f50
Changes from node scripts/check_saved_objects
kibanamachine Nov 14, 2025
c592629
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 17, 2025
db0cd17
add delete endpoint
nkhristinin Nov 18, 2025
63c7a09
pr fixes
nkhristinin Nov 19, 2025
cb33530
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Nov 19, 2025
a2732bc
fix types
nkhristinin Nov 19, 2025
e817da2
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 19, 2025
0b1d7ac
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 19, 2025
c64c8b3
Add min size for rule types array
nkhristinin Nov 21, 2025
005d146
update tests
nkhristinin Nov 21, 2025
cc26f35
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Nov 21, 2025
de754bf
fix test
nkhristinin Nov 21, 2025
99ef613
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 21, 2025
61763d3
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 21, 2025
4d76346
Add comment for gap scheduler limit
nkhristinin Nov 22, 2025
25e216f
Update x-pack/platform/plugins/shared/alerting/server/application/rul…
nkhristinin Nov 22, 2025
4da6ad9
Rename variable
nkhristinin Nov 22, 2025
4b8bc74
Log if there error to create backfill
nkhristinin Nov 22, 2025
1371576
Update x-pack/platform/plugins/shared/alerting/server/backfill_client…
nkhristinin Nov 22, 2025
0d54d25
Rewrtie util function to reduce
nkhristinin Nov 22, 2025
578e046
Should remove task, if initalisation failed, as there no point re res…
nkhristinin Nov 22, 2025
88beab9
Validate that rule types is registred
nkhristinin Nov 22, 2025
95169c0
Change name
nkhristinin Nov 22, 2025
6296289
add validation for task interval
nkhristinin Nov 22, 2025
a1462b0
Chnge log level for gap task
nkhristinin Nov 23, 2025
1b4c83b
Extract status logic and change how it's calculated
nkhristinin Nov 23, 2025
0f5db8e
clean up cleanup function a bit
nkhristinin Nov 23, 2025
ff562e3
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 23, 2025
751e1c7
remove check for rule id
nkhristinin Nov 24, 2025
99748ea
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 24, 2025
ff30a37
Merge branch 'gap-auto-fill-task' into gap-auto-fill-task-api-ui
nkhristinin Nov 24, 2025
58650e0
update route
nkhristinin Nov 24, 2025
10592f2
make rule types and scope required in responses
nkhristinin Nov 24, 2025
4731e48
make scope required in ruletypes API
nkhristinin Nov 24, 2025
28e1e0b
fix tests
nkhristinin Nov 24, 2025
3ae97c1
Add scope to SO
nkhristinin Nov 24, 2025
c3ee98a
Log error message for cleanup of SO
nkhristinin Nov 24, 2025
d03a277
fix tests for scope
nkhristinin Nov 24, 2025
90873c5
clean tests from update SO
nkhristinin Nov 24, 2025
a52f0b2
update tests and add use case for custom id
nkhristinin Nov 24, 2025
6c6cc56
Fix how we get name for create gap scheduler
nkhristinin Nov 24, 2025
7dc07c9
Add maxRulesToFetch for getRuleIdsWithGaps
nkhristinin Nov 24, 2025
103c9c8
Fix more tests and types for scope
nkhristinin Nov 24, 2025
aa6df6a
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine Nov 24, 2025
be8e319
Merge branch 'main' into gap-auto-fill-task
nkhristinin Nov 25, 2025
cd350a1
Update file paths after files moved
nkhristinin Nov 25, 2025
179591b
fix tests and types
nkhristinin Nov 25, 2025
fe1bdd4
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine Nov 25, 2025
fec3dfc
Add validation for lookback limit
nkhristinin Nov 25, 2025
cbbc161
update file paths
nkhristinin Nov 25, 2025
a9d9786
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 25, 2025
11ae994
update message
nkhristinin Nov 25, 2025
4f96e72
move check for remainin backdill inside gap loop
nkhristinin Nov 25, 2025
96a8896
fix tests
nkhristinin Nov 25, 2025
f54ab39
Update schedule backfill message
nkhristinin Nov 25, 2025
0d57b63
update tests
nkhristinin Nov 25, 2025
7166908
Extract process rules and gap into functions
nkhristinin Nov 25, 2025
d712d57
Merge branch 'main' into gap-auto-fill-task
elasticmachine Nov 25, 2025
1a79b57
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine Nov 25, 2025
983be8f
Merge branch 'gap-auto-fill-task' into gap-auto-fill-task-api-ui
nkhristinin Nov 26, 2025
99c7108
update url
nkhristinin Nov 26, 2025
41d131f
Update path
nkhristinin Nov 26, 2025
275a718
Add gap auto fille / modal / status
nkhristinin Nov 26, 2025
d9913d9
Add cy tests
nkhristinin Nov 26, 2025
93358c8
use lodash group
nkhristinin Nov 26, 2025
7949fc5
change how we set update field
nkhristinin Nov 26, 2025
d8d992c
Improve addChunkResultsToAggregation
nkhristinin Nov 26, 2025
9cbaf7f
add validation for duplicate rule types
nkhristinin Nov 26, 2025
5bc0348
refactor cancellation
nkhristinin Nov 26, 2025
0ca2a76
Merge branch 'main' into gap-auto-fill-task
nkhristinin Nov 26, 2025
9ad3195
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine Nov 26, 2025
3e77636
fix test
nkhristinin Nov 26, 2025
6f4ef97
Merge branch 'gap-auto-fill-task' of github.com:nkhristinin/kibana in…
nkhristinin Nov 26, 2025
6b77f76
add get gap auto schduler logs endpoint
nkhristinin Nov 27, 2025
d0f3fa1
Merge branch 'gap-auto-fill-task' into gap-auto-fill-task-api-ui
nkhristinin Nov 27, 2025
4fbf1b9
Add logger UI
nkhristinin Nov 29, 2025
1e1b973
Merge branch 'main' into gap-auto-fill-task-api-ui
nkhristinin Nov 29, 2025
598fe47
Add feature flag
nkhristinin Nov 30, 2025
da5a467
Add callout
nkhristinin Nov 30, 2025
a525775
add tests and make logs route post
nkhristinin Dec 1, 2025
707cfaa
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine Dec 1, 2025
bc8906e
fix lint errors
nkhristinin Dec 1, 2025
4cf46c9
add platinum license check
nkhristinin Dec 1, 2025
b907060
fix tests
nkhristinin Dec 1, 2025
eab9aaa
Support no gaps status
nkhristinin Dec 1, 2025
1743cdc
fix cy tests
nkhristinin Dec 2, 2025
4f7d4a6
Merge branch 'gap-auto-fill-task-api-ui' of github.com:nkhristinin/ki…
nkhristinin Dec 2, 2025
8027070
Fix types
nkhristinin Dec 2, 2025
6828719
fix type
nkhristinin Dec 2, 2025
71a7b7f
fix tests
nkhristinin Dec 2, 2025
3fba6fd
fix tests
nkhristinin Dec 2, 2025
2784fc9
fix cypress tests
nkhristinin Dec 2, 2025
fe01d5f
Merge branch 'main' into gap-auto-fill-task-api-ui
elasticmachine Dec 2, 2025
0d7f1a8
Merge branch 'main' into gap-auto-fill-task-api-ui
elasticmachine Dec 3, 2025
afb28f1
change licencse to enterprise
nkhristinin Dec 3, 2025
456d93c
remove serverless tag for basic license cypress tests
nkhristinin Dec 3, 2025
1e61142
Merge branch 'gap-auto-fill-task-api-ui' of github.com:nkhristinin/ki…
nkhristinin Dec 3, 2025
a9272db
Merge branch 'main' into gap-auto-fill-task-api-ui
elasticmachine Dec 3, 2025
bb04e68
reduce amount of requests
nkhristinin Dec 3, 2025
4168a0b
api threat enabled param on creation
nkhristinin Dec 3, 2025
0ed43aa
Disable button on save
nkhristinin Dec 3, 2025
ea7c2e6
also disabeld when load gap scheduler config
nkhristinin Dec 3, 2025
95ee9e1
simplify buildRuleTypeUnion
nkhristinin Dec 3, 2025
c38a154
remove serverlss tag for cy test
nkhristinin Dec 3, 2025
8b7970f
Merge branch 'gap-auto-fill-task-api-ui' of github.com:nkhristinin/ki…
nkhristinin Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ export const gapAutoFillSchedulerLimits = {
},
minScheduleIntervalInMs: 60 * 1000,
} as const;

export const GAP_AUTO_FILL_STATUS = {
SUCCESS: 'success',
ERROR: 'error',
SKIPPED: 'skipped',
NO_GAPS: 'no_gaps',
} as const;

export type GapAutoFillStatus = (typeof GAP_AUTO_FILL_STATUS)[keyof typeof GAP_AUTO_FILL_STATUS];
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export { alertDeleteCategoryIds } from './alert_delete';
export type { BackfillInitiator } from './backfill';
export { backfillInitiator } from './backfill';
export { gapAutoFillSchedulerLimits } from './gap_auto_fill_scheduler';
export { GAP_AUTO_FILL_STATUS } from './gap_auto_fill_scheduler';
export type { GapAutoFillStatus } from './gap_auto_fill_scheduler';
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/shared/alerting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export {
systemConnectorActionRefPrefix,
} from './action_ref_prefix';
export { gapStatus } from './constants';

export { GAP_AUTO_FILL_STATUS } from './constants';
export type { GapAutoFillStatus } from './constants';
export {
mappingFromFieldMap,
getComponentTemplateFromFieldMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,44 @@

export {
gapAutoFillSchedulerBodySchema,
gapAutoFillSchedulerUpdateBodySchema,
gapAutoFillSchedulerResponseSchema,
getGapAutoFillSchedulerParamsSchema,
gapAutoFillSchedulerLogEntrySchema,
gapAutoFillSchedulerLogsResponseSchema,
gapAutoFillSchedulerLogsRequestQuerySchema,
} from './schemas/latest';
export type {
GapAutoFillSchedulerRequestBody,
GapAutoFillSchedulerResponseBody,
GapAutoFillSchedulerResponse,
UpdateGapAutoFillSchedulerRequestBody,
UpdateGapAutoFillSchedulerResponse,
GetGapAutoFillSchedulerParams,
GapAutoFillSchedulerLogEntry,
GapAutoFillSchedulerLogsResponseBody,
GapAutoFillSchedulerLogsResponse,
GapAutoFillSchedulerLogsRequestQuery,
} from './types/latest';

export {
gapAutoFillSchedulerBodySchema as gapAutoFillSchedulerBodySchemaV1,
gapAutoFillSchedulerUpdateBodySchema as gapAutoFillSchedulerUpdateBodySchemaV1,
gapAutoFillSchedulerResponseSchema as gapAutoFillSchedulerResponseSchemaV1,
getGapAutoFillSchedulerParamsSchema as getGapAutoFillSchedulerParamsSchemaV1,
gapAutoFillSchedulerLogEntrySchema as gapAutoFillSchedulerLogEntrySchemaV1,
gapAutoFillSchedulerLogsResponseSchema as gapAutoFillSchedulerLogsResponseSchemaV1,
gapAutoFillSchedulerLogsRequestQuerySchema as gapAutoFillSchedulerLogsRequestQuerySchemaV1,
} from './schemas/v1';
export type {
GapAutoFillSchedulerRequestBody as GapAutoFillSchedulerRequestBodyV1,
GapAutoFillSchedulerResponseBody as GapAutoFillSchedulerResponseBodyV1,
GapAutoFillSchedulerResponse as GapAutoFillSchedulerResponseV1,
UpdateGapAutoFillSchedulerRequestBody as UpdateGapAutoFillSchedulerRequestBodyV1,
UpdateGapAutoFillSchedulerResponse as UpdateGapAutoFillSchedulerResponseV1,
GetGapAutoFillSchedulerParams as GetGapAutoFillSchedulerParamsV1,
GapAutoFillSchedulerLogEntry as GapAutoFillSchedulerLogEntryV1,
GapAutoFillSchedulerLogsResponseBody as GapAutoFillSchedulerLogsResponseBodyV1,
GapAutoFillSchedulerLogsResponse as GapAutoFillSchedulerLogsResponseV1,
GapAutoFillSchedulerLogsRequestQuery as GapAutoFillSchedulerLogsRequestQueryV1,
} from './types/v1';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,51 @@ import { parseDuration } from '../../../../../parse_duration';

const { maxBackfills, numRetries, minScheduleIntervalInMs } = gapAutoFillSchedulerLimits;

const validateGapAutoFillSchedulerPayload = (
gapFillRange: string,
schedule: { interval: string },
ruleTypes: { type: string; consumer: string }[]
) => {
const now = new Date();
const parsed = dateMath.parse(gapFillRange, { forceNow: now });
if (!parsed || !parsed.isValid()) {
return 'gap_fill_range is invalid';
}

const maxLookbackExpression = `now-${MAX_SCHEDULE_BACKFILL_LOOKBACK_WINDOW_DAYS}d`;
const lookbackLimit = dateMath.parse(maxLookbackExpression, { forceNow: now });
if (!lookbackLimit || !lookbackLimit.isValid()) {
return 'gap_fill_range is invalid';
}

if (parsed.isBefore(lookbackLimit)) {
return `gap_fill_range cannot look back more than ${MAX_SCHEDULE_BACKFILL_LOOKBACK_WINDOW_DAYS} days`;
}

try {
const intervalMs = parseDuration(schedule.interval);
if (intervalMs < minScheduleIntervalInMs) {
return 'schedule.interval must be at least 1 minute';
}
} catch (error) {
return `schedule.interval is invalid: ${(error as Error).message}`;
}

// Duplicate check for rule_types
const seen = new Set<string>();
for (const ruleType of ruleTypes) {
const key = `${ruleType.type}:${ruleType.consumer}`;
if (seen.has(key)) {
return `rule_types contains duplicate entry: type="${ruleType.type}" consumer="${ruleType.consumer}"`;
}
seen.add(key);
}
};

export const getGapAutoFillSchedulerParamsSchema = schema.object({
id: schema.string(),
});

export const gapAutoFillSchedulerBodySchema = schema.object(
{
id: schema.maybe(schema.string()),
Expand All @@ -34,41 +79,41 @@ export const gapAutoFillSchedulerBodySchema = schema.object(
),
},
{
validate({ gap_fill_range: gapFillRange, schedule, rule_types: ruleTypes }) {
const now = new Date();
const parsed = dateMath.parse(gapFillRange, { forceNow: now });
if (!parsed || !parsed.isValid()) {
return 'gap_fill_range is invalid';
}

const maxLookbackExpression = `now-${MAX_SCHEDULE_BACKFILL_LOOKBACK_WINDOW_DAYS}d`;
const lookbackLimit = dateMath.parse(maxLookbackExpression, { forceNow: now });
if (!lookbackLimit || !lookbackLimit.isValid()) {
return 'gap_fill_range is invalid';
}

if (parsed.isBefore(lookbackLimit)) {
return `gap_fill_range cannot look back more than ${MAX_SCHEDULE_BACKFILL_LOOKBACK_WINDOW_DAYS} days`;
}

try {
const intervalMs = parseDuration(schedule.interval);
if (intervalMs < minScheduleIntervalInMs) {
return 'schedule.interval must be at least 1 minute';
}
} catch (error) {
return `schedule.interval is invalid: ${(error as Error).message}`;
}
validate(payload) {
return validateGapAutoFillSchedulerPayload(
payload.gap_fill_range,
payload.schedule,
payload.rule_types
);
},
}
);

// Duplicate check for rule_types
const seen = new Set<string>();
for (const ruleType of ruleTypes) {
const key = `${ruleType.type}:${ruleType.consumer}`;
if (seen.has(key)) {
return `rule_types contains duplicate entry: type="${ruleType.type}" consumer="${ruleType.consumer}"`;
}
seen.add(key);
}
export const gapAutoFillSchedulerUpdateBodySchema = schema.object(
{
name: schema.string(),
enabled: schema.boolean(),
gap_fill_range: schema.string(),
max_backfills: schema.number({ min: 1, max: 5000 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be

Suggested change
max_backfills: schema.number({ min: 1, max: 5000 }),
max_backfills: schema.number(maxBackfills),

num_retries: schema.number({ min: 1 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be

Suggested change
num_retries: schema.number({ min: 1 }),
num_retries: schema.number(numRetries),

schedule: schema.object({
interval: schema.string(),
}),
scope: schema.arrayOf(schema.string()),
rule_types: schema.arrayOf(
schema.object({
type: schema.string(),
consumer: schema.string(),
})
),
},
{
validate(payload) {
return validateGapAutoFillSchedulerPayload(
payload.gap_fill_range,
payload.schedule,
payload.rule_types
);
},
}
);
Expand All @@ -95,3 +140,48 @@ export const gapAutoFillSchedulerResponseSchema = schema.object({
created_at: schema.string(),
updated_at: schema.string(),
});

export const gapAutoFillSchedulerLogsRequestQuerySchema = schema.object({
start: schema.string(),
end: schema.string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we validate that these are valid dates?

page: schema.number({ defaultValue: 1, min: 1 }),
per_page: schema.number({ defaultValue: 50, min: 1, max: 1000 }),
sort_field: schema.oneOf([schema.literal('@timestamp')], { defaultValue: '@timestamp' }),
sort_direction: schema.oneOf([schema.literal('asc'), schema.literal('desc')], {
defaultValue: 'desc',
}),
statuses: schema.maybe(
schema.arrayOf(
schema.oneOf([
schema.literal('success'),
schema.literal('error'),
schema.literal('skipped'),
schema.literal('no_gaps'),
])
)
),
});

export const gapAutoFillSchedulerLogEntrySchema = schema.object({
id: schema.string(),
timestamp: schema.maybe(schema.string()),
status: schema.maybe(schema.string()),
message: schema.maybe(schema.string()),
results: schema.maybe(
schema.arrayOf(
schema.object({
rule_id: schema.maybe(schema.string()),
processed_gaps: schema.maybe(schema.number()),
status: schema.maybe(schema.string()),
error: schema.maybe(schema.string()),
})
)
),
});

export const gapAutoFillSchedulerLogsResponseSchema = schema.object({
data: schema.arrayOf(gapAutoFillSchedulerLogEntrySchema),
total: schema.number(),
page: schema.number(),
per_page: schema.number(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,38 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import type { gapAutoFillSchedulerBodySchemaV1, gapAutoFillSchedulerResponseSchemaV1 } from '..';
import type {
gapAutoFillSchedulerBodySchemaV1,
gapAutoFillSchedulerResponseSchemaV1,
gapAutoFillSchedulerUpdateBodySchemaV1,
getGapAutoFillSchedulerParamsSchemaV1,
gapAutoFillSchedulerLogEntrySchemaV1,
gapAutoFillSchedulerLogsResponseSchemaV1,
gapAutoFillSchedulerLogsRequestQuerySchemaV1,
} from '..';

export type GapAutoFillSchedulerRequestBody = TypeOf<typeof gapAutoFillSchedulerBodySchemaV1>;
export type UpdateGapAutoFillSchedulerRequestBody = TypeOf<
typeof gapAutoFillSchedulerUpdateBodySchemaV1
>;
export type GapAutoFillSchedulerResponseBody = TypeOf<typeof gapAutoFillSchedulerResponseSchemaV1>;

export type GetGapAutoFillSchedulerParams = TypeOf<typeof getGapAutoFillSchedulerParamsSchemaV1>;
export interface GapAutoFillSchedulerResponse {
body: GapAutoFillSchedulerResponseBody;
}

export interface UpdateGapAutoFillSchedulerResponse {
body: GapAutoFillSchedulerResponseBody;
}

export type GapAutoFillSchedulerLogEntry = TypeOf<typeof gapAutoFillSchedulerLogEntrySchemaV1>;
export type GapAutoFillSchedulerLogsResponseBody = TypeOf<
typeof gapAutoFillSchedulerLogsResponseSchemaV1
>;
export interface GapAutoFillSchedulerLogsResponse {
body: GapAutoFillSchedulerLogsResponseBody;
}

export type GapAutoFillSchedulerLogsRequestQuery = TypeOf<
typeof gapAutoFillSchedulerLogsRequestQuerySchemaV1
>;
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,37 @@ Payload summary: ${JSON.stringify(otherParams, (key, value) =>
savedObjectOptions
);

try {
await taskManager.ensureScheduled(
{
id: so.id,
taskType: GAP_AUTO_FILL_SCHEDULER_TASK_TYPE,
schedule: params.schedule,
scope: params.scope ?? [],
params: {
configId: so.id,
spaceId: context.spaceId,
},
state: {},
},
{
request: params.request,
}
);
} catch (e) {
context.logger.error(
`Failed to schedule task for gap auto fill scheduler ${so.id}. Will attempt to delete the saved object.`
);
if (params.enabled) {
try {
await soClient.delete(GAP_AUTO_FILL_SCHEDULER_SAVED_OBJECT_TYPE, so.id);
} catch (deleteError) {
await taskManager.ensureScheduled(
{
id: so.id,
taskType: GAP_AUTO_FILL_SCHEDULER_TASK_TYPE,
schedule: params.schedule,
scope: params.scope ?? [],
params: {
configId: so.id,
spaceId: context.spaceId,
},
state: {},
},
{
request: params.request,
}
);
} catch (e) {
context.logger.error(
`Failed to delete gap auto fill saved object for gap auto fill scheduler ${so.id}.`
`Failed to schedule task for gap auto fill scheduler ${so.id}. Will attempt to delete the saved object.`
);
try {
await soClient.delete(GAP_AUTO_FILL_SCHEDULER_SAVED_OBJECT_TYPE, so.id);
} catch (deleteError) {
context.logger.error(
`Failed to delete gap auto fill saved object for gap auto fill scheduler ${so.id}.`
);
}
throw e;
}
throw e;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test for creating a scheduler that's disabled?


// Log successful creation
Expand Down
Loading