Skip to content

[SLO] Bulk Purge SLI data#218287

Merged
baileycash-elastic merged 30 commits intoelastic:mainfrom
baileycash-elastic:slo-210025
Apr 22, 2025
Merged

[SLO] Bulk Purge SLI data#218287
baileycash-elastic merged 30 commits intoelastic:mainfrom
baileycash-elastic:slo-210025

Conversation

@baileycash-elastic
Copy link
Contributor

@baileycash-elastic baileycash-elastic commented Apr 15, 2025

Summary

Resolves #210025

Introduces starter API for bulk purging of SLI data.
docs coming pending review
Users can submit a list of SLO ids for which they would like to purge rollup data, as well as a purge policy:

    "purgePolicy": {
        "purgeType": "fixed_age",
        "age": "1w"
    }
    "purgePolicy": {
        "purgeType": "fixed_time",
        "age": "2025-04-01T00:00:00Z"
    }

@baileycash-elastic baileycash-elastic changed the title Slo 210025 [SLO] Bulk Purge SLI data Apr 15, 2025
@baileycash-elastic baileycash-elastic added Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. backport:prev-major v9.1.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 16, 2025
tweaks and tests
@baileycash-elastic baileycash-elastic marked this pull request as ready for review April 16, 2025 16:33
@baileycash-elastic baileycash-elastic requested review from a team as code owners April 16, 2025 16:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

Comment on lines 25 to 37
const bulkPurgeRollupSchema = t.intersection([
t.partial({
query: t.partial({
force: t.string,
}),
}),
t.type({
body: t.type({
ids: t.array(t.string),
purgePolicy,
}),
}),
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be simpler to move force into the body as well

const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const purgeRollupData = new PurgeRollupData(esClient, repository);

await purgeRollupData.execute(params);
Copy link
Contributor

Choose a reason for hiding this comment

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

params contains body and query, which are considered implementation details of the route handler. The PurgeRollupData service should not know anything about a body or a query (http specific)

Also, if we move force into the body, you can then use a Params type like:

type BulkPurgeRollupDataParams = t.TypeOf<typeof bulkPurgeRollupSchema.props.body>;

Copy link
Contributor

@kdelemme kdelemme left a comment

Choose a reason for hiding this comment

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

Just a few naming convention, imports and schema/type to fix. And use the slo list from the repository for the delete by query ids

Comment on lines 105 to 109
if (purgePolicy.purgeType === 'fixed_age') {
return `now-${purgePolicy.age.format()}`;
} else {
return purgePolicy.timestamp.toISOString();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add an assertNever(purgeType);?


private async validatePurgePolicy(params: PurgeRollupSchemaType) {
const { ids, purgePolicy } = params;
const slos = await this.repository.findAllByIds(ids);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should fetch the slo list outside of the validation, and provide it to this function, and also use the sloList in the deleteByQuery: { 'slo.id': map(sloList, "id") }. so we don't delete slo that the user should not have access to.

bool: {
filter: [
{
terms: { 'slo.id': params.ids },
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't delete SLOs that the user should not have access to.

Suggested change
terms: { 'slo.id': params.ids },
terms: { 'slo.id': map(sloList, "id") },

Comment on lines 83 to 89
return moment(timestamp).isAfter(
moment(Date.now()).startOf(slo.timeWindow.duration.unit)
);
} else {
return moment(timestamp).isAfter(
moment(Date.now()).subtract(slo.timeWindow.duration.asSeconds(), 's')
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: create moment(timestamp) once outside the some predicate, so we don't recreate one every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very fair

import { KibanaSavedObjectsSLORepository } from '../../services';

export const purgeRollupDataRoute = createSloServerRoute({
endpoint: 'POST /api/observability/slos/_purge_rollup 2023-10-31',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
endpoint: 'POST /api/observability/slos/_purge_rollup 2023-10-31',
endpoint: 'POST /api/observability/slos/_bulk_purge_rollup 2023-10-31',

import { durationType } from './duration';
import { indicatorSchema } from './indicators';
import { timeWindowSchema } from './time_window';
import { bulkPurgeRollupSchema } from '../rest_specs/routes/bulk_purge_rollup';
Copy link
Contributor

Choose a reason for hiding this comment

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

don't import the rest_specs here.

type PurgePolicyType = t.TypeOf<typeof purgePolicy>;
type PurgeRollupSchemaType = t.TypeOf<typeof bulkPurgeRollupSchema.props.body>;

export type { PurgePolicyType, PurgeRollupSchemaType };
Copy link
Contributor

Choose a reason for hiding this comment

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

add export * from './bulk_purge_rollup'; into rest_specs/routes/index.ts

});

type PurgePolicyType = t.TypeOf<typeof purgePolicy>;
type PurgeRollupSchemaType = t.TypeOf<typeof bulkPurgeRollupSchema.props.body>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you name the schema and type like the other schemas to be consistent, and introduce the response type as well e.g.

const  bulkPurgeRollupParamsSchema = t.type({ ... })

const bulkPurgeRollupResponseSchema = t.type({ taskId: t.string });

type BulkPurgeRollupInput = t.OutputOf<typeof bulkPurgeRollupParamsSchema.props.body>;
type BulkPurgeRollupParams = t.TypeOf<typeof bulkPurgeRollupParamsSchema.props.body>;
type BulkPurgeRollupResponse = t.TypeOf<typeof bulkPurgeRollupResponseSchema.props.body>;

import { PurgeRollupData } from '../../services/purge_rollup_data';
import { KibanaSavedObjectsSLORepository } from '../../services';

export const purgeRollupDataRoute = createSloServerRoute({
Copy link
Contributor

Choose a reason for hiding this comment

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

can you name that bulkPurgeRollupRoute to be consistent with the types and url


public async execute(
params: PurgeRollupSchemaType
): Promise<{ taskId: DeleteByQueryResponse['task'] }> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the BulkPurgeRollupResponse here

@baileycash-elastic baileycash-elastic marked this pull request as draft April 16, 2025 21:51
@baileycash-elastic baileycash-elastic marked this pull request as ready for review April 17, 2025 13:30
Copy link
Contributor

@kdelemme kdelemme left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the changes

@kdelemme
Copy link
Contributor

@baileycash-elastic Can you merge main in, and use the new getScopedClient(request) from the route handler?

Copy link
Contributor

@csr csr left a comment

Choose a reason for hiding this comment

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

x-pack/test/api_integration/deployment_agnostic/services/slo_api.ts purge endpoint change LGTM.

@baileycash-elastic baileycash-elastic enabled auto-merge (squash) April 22, 2025 14:33
@baileycash-elastic baileycash-elastic merged commit 2df2e78 into elastic:main Apr 22, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.18, 8.19

https://github.com/elastic/kibana/actions/runs/14605402192

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
observability 1289 1290 +1
slo 1118 1119 +1
synthetics 1187 1188 +1
total +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/slo-schema 188 193 +5

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 1.3MB 1.3MB +264.0B
slo 911.3KB 911.5KB +224.0B
synthetics 954.6KB 954.9KB +254.0B
total +742.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observability 94.5KB 94.5KB +1.0B
synthetics 27.1KB 27.1KB -2.0B
total -1.0B
Unknown metric groups

API count

id before after diff
@kbn/slo-schema 188 193 +5

History

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.17 Backport failed because of merge conflicts
8.18 Backport failed because of merge conflicts
8.19 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.19:
- [Cloud Connector] Add cloud_connectors config in Agentless API (#215421)
- [streams][content pack] archive format and portable dashboards (#217288)

Manual backport

To create the backport manually run:

node scripts/backport --pr 218287

Questions ?

Please refer to the Backport tool documentation

@kdelemme kdelemme added backport:version Backport to applied version labels v8.19.0 and removed backport:prev-major labels Apr 22, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.18, 8.19

https://github.com/elastic/kibana/actions/runs/14605533214

@kdelemme
Copy link
Contributor

@baileycash-elastic I've removed the backport:prev-major. we should only backport to 9.1 and 8.19

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.17 Backport failed because of merge conflicts
8.18 Backport failed because of merge conflicts
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 218287

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Apr 23, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 218287 locally

@baileycash-elastic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

baileycash-elastic added a commit to baileycash-elastic/kibana that referenced this pull request Apr 24, 2025
## Summary

Resolves elastic#210025

Introduces starter API for bulk purging of SLI data.
**docs coming pending review**
Users can submit a list of SLO ids for which they would like to purge
rollup data, as well as a purge policy:

```
    "purgePolicy": {
        "purgeType": "fixed_age",
        "age": "1w"
    }
```

```
    "purgePolicy": {
        "purgeType": "fixed_time",
        "age": "2025-04-01T00:00:00Z"
    }
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 2df2e78)

# Conflicts:
#	oas_docs/output/kibana.yaml
#	x-pack/solutions/observability/plugins/slo/docs/openapi/slo/bundled.json
#	x-pack/solutions/observability/plugins/slo/docs/openapi/slo/bundled.yaml
#	x-pack/solutions/observability/plugins/slo/docs/openapi/slo/entrypoint.yaml
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @baileycash-elastic

baileycash-elastic added a commit that referenced this pull request Apr 25, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[SLO] Bulk Purge SLI data
(#218287)](#218287)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Bailey
Cash","email":"bailey.cash@elastic.co"},"sourceCommit":{"committedDate":"2025-04-22T21:58:31Z","message":"[SLO]
Bulk Purge SLI data (#218287)\n\n## Summary\n\nResolves #210025
\n\nIntroduces starter API for bulk purging of SLI data. \n**docs coming
pending review**\nUsers can submit a list of SLO ids for which they
would like to purge\nrollup data, as well as a purge policy:\n\n```\n
\"purgePolicy\": {\n \"purgeType\": \"fixed_age\",\n \"age\": \"1w\"\n
}\n```\n\n```\n \"purgePolicy\": {\n \"purgeType\": \"fixed_time\",\n
\"age\": \"2025-04-01T00:00:00Z\"\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2df2e7890698677b617660a0919a3d277add6fb4","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0"],"title":"[SLO]
Bulk Purge SLI
data","number":218287,"url":"https://github.com/elastic/kibana/pull/218287","mergeCommit":{"message":"[SLO]
Bulk Purge SLI data (#218287)\n\n## Summary\n\nResolves #210025
\n\nIntroduces starter API for bulk purging of SLI data. \n**docs coming
pending review**\nUsers can submit a list of SLO ids for which they
would like to purge\nrollup data, as well as a purge policy:\n\n```\n
\"purgePolicy\": {\n \"purgeType\": \"fixed_age\",\n \"age\": \"1w\"\n
}\n```\n\n```\n \"purgePolicy\": {\n \"purgeType\": \"fixed_time\",\n
\"age\": \"2025-04-01T00:00:00Z\"\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2df2e7890698677b617660a0919a3d277add6fb4"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218287","number":218287,"mergeCommit":{"message":"[SLO]
Bulk Purge SLI data (#218287)\n\n## Summary\n\nResolves #210025
\n\nIntroduces starter API for bulk purging of SLI data. \n**docs coming
pending review**\nUsers can submit a list of SLO ids for which they
would like to purge\nrollup data, as well as a purge policy:\n\n```\n
\"purgePolicy\": {\n \"purgeType\": \"fixed_age\",\n \"age\": \"1w\"\n
}\n```\n\n```\n \"purgePolicy\": {\n \"purgeType\": \"fixed_time\",\n
\"age\": \"2025-04-01T00:00:00Z\"\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2df2e7890698677b617660a0919a3d277add6fb4"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Kevin Delemme <kevin.delemme@elastic.co>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Apr 25, 2025
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
## Summary

Resolves elastic#210025 

Introduces starter API for bulk purging of SLI data. 
**docs coming pending review**
Users can submit a list of SLO ids for which they would like to purge
rollup data, as well as a purge policy:

```
    "purgePolicy": {
        "purgeType": "fixed_age",
        "age": "1w"
    }
```

```
    "purgePolicy": {
        "purgeType": "fixed_time",
        "age": "2025-04-01T00:00:00Z"
    }
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SLO] [Management] (bulk) purge rolled-up data

6 participants