Skip to content

Commit

Permalink
feat(composite_slo): Implement delete, update and get routes (#158599)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Jun 5, 2023
1 parent 291f399 commit ecaa06d
Show file tree
Hide file tree
Showing 53 changed files with 1,918 additions and 176 deletions.
24 changes: 13 additions & 11 deletions packages/kbn-slo-schema/src/rest_specs/composite_slo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
budgetingMethodSchema,
compositeSloIdSchema,
dateType,
rollingTimeWindowSchema,
objectiveSchema,
summarySchema,
tagsSchema,
targetSchema,
timeWindowSchema,
weightedAverageCompositeMethodSchema,
weightedAverageSourceSchema,
} from '../schema';
Expand All @@ -23,9 +23,9 @@ const createCompositeSLOParamsSchema = t.type({
body: t.intersection([
t.type({
name: t.string,
timeWindow: rollingTimeWindowSchema,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
objective: targetSchema,
objective: objectiveSchema,
compositeMethod: weightedAverageCompositeMethodSchema,
sources: t.array(weightedAverageSourceSchema),
}),
Expand All @@ -40,9 +40,9 @@ const createCompositeSLOResponseSchema = t.type({
const compositeSLOResponseSchema = t.type({
id: compositeSloIdSchema,
name: t.string,
timeWindow: rollingTimeWindowSchema,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
objective: targetSchema,
objective: objectiveSchema,
compositeMethod: weightedAverageCompositeMethodSchema,
sources: t.array(weightedAverageSourceSchema),
tags: tagsSchema,
Expand All @@ -63,9 +63,9 @@ const updateCompositeSLOParamsSchema = t.type({
name: t.string,
compositeMethod: weightedAverageCompositeMethodSchema,
sources: t.array(weightedAverageSourceSchema),
timeWindow: rollingTimeWindowSchema,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
objective: targetSchema,
objective: objectiveSchema,
tags: tagsSchema,
}),
});
Expand All @@ -90,7 +90,6 @@ const sortDirectionSchema = t.union([t.literal('asc'), t.literal('desc')]);
const sortBySchema = t.literal('creationTime');
const findCompositeSLOParamsSchema = t.partial({
query: t.partial({
name: t.string,
page: t.string,
perPage: t.string,
sortBy: sortBySchema,
Expand All @@ -107,7 +106,7 @@ const findCompositeSLOResponseSchema = t.type({

type CreateCompositeSLOInput = t.OutputOf<typeof createCompositeSLOParamsSchema.props.body>; // Raw payload sent by the frontend
type CreateCompositeSLOParams = t.TypeOf<typeof createCompositeSLOParamsSchema.props.body>; // Parsed payload used by the backend
type CreateCompositeSLOResponse = t.TypeOf<typeof createCompositeSLOResponseSchema>; // Raw response sent to the frontend
type CreateCompositeSLOResponse = t.OutputOf<typeof createCompositeSLOResponseSchema>; // Raw response sent to the frontend

type GetCompositeSLOResponse = t.OutputOf<typeof getCompositeSLOResponseSchema>;

Expand All @@ -116,14 +115,17 @@ type FindCompositeSLOResponse = t.OutputOf<typeof findCompositeSLOResponseSchema

type UpdateCompositeSLOInput = t.OutputOf<typeof updateCompositeSLOParamsSchema.props.body>;
type UpdateCompositeSLOParams = t.TypeOf<typeof updateCompositeSLOParamsSchema.props.body>;
type UpdateCompositeSLOResponse = t.TypeOf<typeof updateCompositeSLOResponseSchema>;
type UpdateCompositeSLOResponse = t.OutputOf<typeof updateCompositeSLOResponseSchema>;

export {
compositeSLOResponseSchema,
createCompositeSLOParamsSchema,
deleteCompositeSLOParamsSchema,
findCompositeSLOParamsSchema,
findCompositeSLOResponseSchema,
getCompositeSLOParamsSchema,
updateCompositeSLOParamsSchema,
updateCompositeSLOResponseSchema,
};

export type {
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-slo-schema/src/schema/composite_slo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import * as t from 'io-ts';

import { dateType } from './common';
import { budgetingMethodSchema, sloIdSchema, tagsSchema, targetSchema } from './slo';
import { rollingTimeWindowSchema } from './time_window';
import { budgetingMethodSchema, objectiveSchema, sloIdSchema, tagsSchema } from './slo';
import { timeWindowSchema } from './time_window';

const compositeSloIdSchema = t.string;

Expand All @@ -24,10 +24,10 @@ const weightedAverageSourceSchema = t.type({
const compositeSloSchema = t.type({
id: compositeSloIdSchema,
name: t.string,
timeWindow: rollingTimeWindowSchema,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
compositeMethod: weightedAverageCompositeMethodSchema,
objective: targetSchema,
objective: objectiveSchema,
sources: t.array(weightedAverageSourceSchema),
tags: tagsSchema,
createdAt: dateType,
Expand Down
27 changes: 27 additions & 0 deletions x-pack/plugins/observability/dev_docs/composite_slo.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,30 @@ curl --request POST \
}
}'
```


Delete a composite SLO:

```
curl --request DELETE \
--url http://localhost:5601/kibana/api/observability/composite_slos/7ba92850-fbd6-11ed-8eb2-037af7d0dfa6 \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--header 'Content-Type: application/json' \
--header 'kbn-xsrf: oui'
```

Update an existing composite SLO:

```
curl --request PUT \
--url http://localhost:5601/kibana/api/observability/composite_slos/01af9e10-fbf1-11ed-83f3-01ffee47b374 \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--header 'Content-Type: application/json' \
--header 'kbn-xsrf: oui' \
--data '{
"name": "new composite slo name",
"objective": {
"target": 0.90
}
}'
```
Loading

0 comments on commit ecaa06d

Please sign in to comment.