Skip to content

Commit

Permalink
feat(slo): delete slo instances (#165270)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Sep 5, 2023
1 parent 772bc0c commit 889f067
Show file tree
Hide file tree
Showing 11 changed files with 506 additions and 6 deletions.
10 changes: 10 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/slo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ const findSLOResponseSchema = t.type({
results: t.array(sloWithSummaryResponseSchema),
});

const deleteSLOInstancesParamsSchema = t.type({
body: t.type({ list: t.array(t.type({ sloId: sloIdSchema, instanceId: t.string })) }),
});

const fetchHistoricalSummaryParamsSchema = t.type({
body: t.type({ list: t.array(t.type({ sloId: sloIdSchema, instanceId: allOrAnyString })) }),
});
Expand Down Expand Up @@ -239,6 +243,9 @@ type UpdateSLOResponse = t.OutputOf<typeof updateSLOResponseSchema>;
type FindSLOParams = t.TypeOf<typeof findSLOParamsSchema.props.query>;
type FindSLOResponse = t.OutputOf<typeof findSLOResponseSchema>;

type DeleteSLOInstancesInput = t.OutputOf<typeof deleteSLOInstancesParamsSchema.props.body>;
type DeleteSLOInstancesParams = t.TypeOf<typeof deleteSLOInstancesParamsSchema.props.body>;

type FetchHistoricalSummaryParams = t.TypeOf<typeof fetchHistoricalSummaryParamsSchema.props.body>;
type FetchHistoricalSummaryResponse = t.OutputOf<typeof fetchHistoricalSummaryResponseSchema>;
type HistoricalSummaryResponse = t.OutputOf<typeof historicalSummarySchema>;
Expand Down Expand Up @@ -269,6 +276,7 @@ type KQLCustomIndicator = t.OutputOf<typeof kqlCustomIndicatorSchema>;
export {
createSLOParamsSchema,
deleteSLOParamsSchema,
deleteSLOInstancesParamsSchema,
findSLOParamsSchema,
findSLOResponseSchema,
getPreviewDataParamsSchema,
Expand All @@ -294,6 +302,8 @@ export type {
CreateSLOInput,
CreateSLOParams,
CreateSLOResponse,
DeleteSLOInstancesInput,
DeleteSLOInstancesParams,
FindSLOParams,
FindSLOResponse,
GetPreviewDataParams,
Expand Down
105 changes: 103 additions & 2 deletions x-pack/plugins/observability/docs/openapi/slo/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,74 @@
}
}
}
},
"/s/{spaceId}/api/observability/slos/_delete_instances": {
"post": {
"summary": "Batch delete rollup and summary data for the matching list of sloId and instanceId",
"operationId": "deleteSloInstancesOp",
"description": "You must have `all` privileges for the **SLOs** feature in the **Observability** section of the Kibana feature privileges.\n",
"tags": [
"slo"
],
"parameters": [
{
"$ref": "#/components/parameters/kbn_xsrf"
},
{
"$ref": "#/components/parameters/space_id"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/delete_slo_instances_request"
}
}
}
},
"responses": {
"204": {
"description": "Successful request"
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/400_response"
}
}
}
},
"401": {
"description": "Unauthorized response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/401_response"
}
}
}
},
"403": {
"description": "Unauthorized response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/403_response"
}
}
}
}
},
"servers": [
{
"url": "https://localhost:5601"
}
]
}
}
},
"components": {
Expand Down Expand Up @@ -1718,10 +1786,10 @@
"title": "Historical summary request",
"type": "object",
"required": [
"sloIds"
"list"
],
"properties": {
"sloIds": {
"list": {
"description": "The list of SLO identifiers to get the historical summary for",
"type": "array",
"items": {
Expand Down Expand Up @@ -1756,6 +1824,39 @@
}
}
}
},
"delete_slo_instances_request": {
"title": "Delete SLO instances request",
"description": "The delete SLO instances request takes a list of SLO id and instance id, then delete the rollup and summary data. This API can be used to remove the staled data of an instance SLO that no longer get updated.\n",
"type": "object",
"required": [
"list"
],
"properties": {
"list": {
"description": "An array of slo id and instance id",
"type": "array",
"items": {
"type": "object",
"required": [
"sloId",
"instanceId"
],
"properties": {
"sloId": {
"description": "The SLO unique identifier",
"type": "string",
"example": "8853df00-ae2e-11ed-90af-09bb6422b258"
},
"instanceId": {
"description": "The SLO instance identifier",
"type": "string",
"example": "8853df00-ae2e-11ed-90af-09bb6422b258"
}
}
}
}
}
}
}
}
Expand Down
69 changes: 67 additions & 2 deletions x-pack/plugins/observability/docs/openapi/slo/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,46 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/403_response'
/s/{spaceId}/api/observability/slos/_delete_instances:
post:
summary: Batch delete rollup and summary data for the matching list of sloId and instanceId
operationId: deleteSloInstancesOp
description: |
You must have `all` privileges for the **SLOs** feature in the **Observability** section of the Kibana feature privileges.
tags:
- slo
parameters:
- $ref: '#/components/parameters/kbn_xsrf'
- $ref: '#/components/parameters/space_id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/delete_slo_instances_request'
responses:
'204':
description: Successful request
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/400_response'
'401':
description: Unauthorized response
content:
application/json:
schema:
$ref: '#/components/schemas/401_response'
'403':
description: Unauthorized response
content:
application/json:
schema:
$ref: '#/components/schemas/403_response'
servers:
- url: https://localhost:5601
components:
securitySchemes:
basicAuth:
Expand Down Expand Up @@ -1190,9 +1230,9 @@ components:
title: Historical summary request
type: object
required:
- sloIds
- list
properties:
sloIds:
list:
description: The list of SLO identifiers to get the historical summary for
type: array
items:
Expand All @@ -1216,3 +1256,28 @@ components:
example: 0.9836
errorBudget:
$ref: '#/components/schemas/error_budget'
delete_slo_instances_request:
title: Delete SLO instances request
description: |
The delete SLO instances request takes a list of SLO id and instance id, then delete the rollup and summary data. This API can be used to remove the staled data of an instance SLO that no longer get updated.
type: object
required:
- list
properties:
list:
description: An array of slo id and instance id
type: array
items:
type: object
required:
- sloId
- instanceId
properties:
sloId:
description: The SLO unique identifier
type: string
example: 8853df00-ae2e-11ed-90af-09bb6422b258
instanceId:
description: The SLO instance identifier
type: string
example: 8853df00-ae2e-11ed-90af-09bb6422b258
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
title: Delete SLO instances request
description: >
The delete SLO instances request takes a list of SLO id and instance id, then delete the rollup and summary data.
This API can be used to remove the staled data of an instance SLO that no longer get updated.
type: object
required:
- list
properties:
list:
description: An array of slo id and instance id
type: array
items:
type: object
required:
- sloId
- instanceId
properties:
sloId:
description: The SLO unique identifier
type: string
example: 8853df00-ae2e-11ed-90af-09bb6422b258
instanceId:
description: The SLO instance identifier
type: string
example: 8853df00-ae2e-11ed-90af-09bb6422b258

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
title: Historical summary request
type: object
required:
- sloIds
- list
properties:
sloIds:
list:
description: The list of SLO identifiers to get the historical summary for
type: array
items:
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/observability/docs/openapi/slo/entrypoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ paths:
$ref: "paths/s@{spaceid}@api@slos@{sloid}@{disable}.yaml"
"/s/{spaceId}/internal/observability/slos/_historical_summary":
$ref: "paths/s@{spaceid}@api@slos@_historical_summary.yaml"
"/s/{spaceId}/api/observability/slos/_delete_instances":
$ref: "paths/s@{spaceid}@api@slos@_delete_instances.yaml"
components:
securitySchemes:
basicAuth:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
post:
summary: Batch delete rollup and summary data for the matching list of sloId and instanceId
operationId: deleteSloInstancesOp
description: >
You must have `all` privileges for the **SLOs** feature in the
**Observability** section of the Kibana feature privileges.
tags:
- slo
parameters:
- $ref: ../components/headers/kbn_xsrf.yaml
- $ref: ../components/parameters/space_id.yaml
requestBody:
required: true
content:
application/json:
schema:
$ref: '../components/schemas/delete_slo_instances_request.yaml'
responses:
'204':
description: Successful request
'400':
description: Bad request
content:
application/json:
schema:
$ref: '../components/schemas/400_response.yaml'
'401':
description: Unauthorized response
content:
application/json:
schema:
$ref: '../components/schemas/401_response.yaml'
'403':
description: Unauthorized response
content:
application/json:
schema:
$ref: '../components/schemas/403_response.yaml'
servers:
- url: https://localhost:5601
19 changes: 19 additions & 0 deletions x-pack/plugins/observability/server/routes/slo/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { errors } from '@elastic/elasticsearch';
import { failedDependency, forbidden } from '@hapi/boom';
import {
createSLOParamsSchema,
deleteSLOInstancesParamsSchema,
deleteSLOParamsSchema,
fetchHistoricalSummaryParamsSchema,
findSloDefinitionsParamsSchema,
Expand All @@ -26,6 +27,7 @@ import {
DefaultSummaryClient,
DefaultTransformManager,
DeleteSLO,
DeleteSLOInstances,
FindSLO,
GetSLO,
KibanaSavedObjectsSLORepository,
Expand Down Expand Up @@ -225,6 +227,22 @@ const findSLORoute = createObservabilityServerRoute({
},
});

const deleteSloInstancesRoute = createObservabilityServerRoute({
endpoint: 'POST /api/observability/slos/_delete_instances 2023-10-31',
options: {
tags: ['access:slo_write'],
},
params: deleteSLOInstancesParamsSchema,
handler: async ({ context, params }) => {
await assertPlatinumLicense(context);

const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const deleteSloInstances = new DeleteSLOInstances(esClient);

await deleteSloInstances.execute(params.body);
},
});

const findSloDefinitionsRoute = createObservabilityServerRoute({
endpoint: 'GET /internal/observability/slos/_definitions',
options: {
Expand Down Expand Up @@ -351,6 +369,7 @@ const getPreviewData = createObservabilityServerRoute({
export const sloRouteRepository = {
...createSLORoute,
...deleteSLORoute,
...deleteSloInstancesRoute,
...disableSLORoute,
...enableSLORoute,
...fetchHistoricalSummary,
Expand Down
Loading

0 comments on commit 889f067

Please sign in to comment.