Skip to content

Commit

Permalink
[SLO] Implement federated views (#178050)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Apr 16, 2024
1 parent 7307987 commit 721d354
Show file tree
Hide file tree
Showing 206 changed files with 3,808 additions and 1,897 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export const HASH_TO_VERSION_MAP = {
'siem-ui-timeline-note|28393dfdeb4e4413393eb5f7ec8c5436': '10.0.0',
'siem-ui-timeline-pinned-event|293fce142548281599060e07ad2c9ddb': '10.0.0',
'siem-ui-timeline|f6739fd4b17646a6c86321a746c247ef': '10.1.0',
'slo-settings|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'slo|dc7f35c0cf07d71bb36f154996fe10c6': '10.1.0',
'space|c3aec2a5d4afcb75554fed96411170e1': '10.0.0',
'spaces-usage-stats|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-check-mappings-update-cli/current_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@
"tags",
"version"
],
"slo-settings": [],
"space": [
"name"
],
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-check-mappings-update-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,10 @@
}
}
},
"slo-settings": {
"dynamic": false,
"properties": {}
},
"space": {
"dynamic": false,
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import * as t from 'io-ts';
import { omitBy, isPlainObject, isEmpty } from 'lodash';
import { isLeft } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
import Boom from '@hapi/boom';
import { strictKeysRt } from '@kbn/io-ts-utils';
import { formatErrors } from '@kbn/securitysolution-io-ts-utils';
import { RouteParamsRT } from './typings';

interface KibanaRequestParams {
Expand All @@ -36,7 +36,7 @@ export function decodeRequestParams<T extends RouteParamsRT>(
const result = strictKeysRt(paramsRt).decode(paramMap);

if (isLeft(result)) {
throw Boom.badRequest(PathReporter.report(result)[0]);
throw Boom.badRequest(formatErrors(result.left).join('|'));
}

return result.right;
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-server-route-repository/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@kbn/core-http-request-handler-context-server",
"@kbn/core-http-server",
"@kbn/core-lifecycle-server",
"@kbn/logging"
"@kbn/logging",
"@kbn/securitysolution-io-ts-utils"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"siem-ui-timeline-note": "0a32fb776907f596bedca292b8c646496ae9c57b",
"siem-ui-timeline-pinned-event": "082daa3ce647b33873f6abccf340bdfa32057c8d",
"slo": "9a9995e4572de1839651c43b5fc4dc8276bb5815",
"slo-settings": "f6b5ed339470a6a2cda272bde1750adcf504a11b",
"space": "8de4ec513e9bbc6b2f1d635161d850be7747d38e",
"spaces-usage-stats": "3abca98713c52af8b30300e386c7779b3025a20e",
"synthetics-monitor": "5ceb25b6249bd26902c9b34273c71c3dce06dbea",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const previouslyRegisteredTypes = [
'siem-ui-timeline-note',
'siem-ui-timeline-pinned-event',
'slo',
'slo-settings',
'space',
'spaces-usage-stats',
'synthetics-monitor',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe('split .kibana index into multiple system indices', () => {
"siem-ui-timeline-note",
"siem-ui-timeline-pinned-event",
"slo",
"slo-settings",
"space",
"spaces-usage-stats",
"synthetics-monitor",
Expand Down
3 changes: 1 addition & 2 deletions x-pack/packages/kbn-slo-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

export * from './src/schema';
export * from './src/rest_specs';
export * from './src/models/duration';
export * from './src/models/pagination';
export * from './src/models';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* 2.0.
*/

export function useErrorBudgetActions() {}
export * from './pagination';
export * from './duration';
21 changes: 21 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';
import {
budgetingMethodSchema,
groupSummarySchema,
objectiveSchema,
timeWindowTypeSchema,
} from '../schema';

type BudgetingMethod = t.OutputOf<typeof budgetingMethodSchema>;
type TimeWindowType = t.OutputOf<typeof timeWindowTypeSchema>;
type GroupSummary = t.TypeOf<typeof groupSummarySchema>;
type Objective = t.OutputOf<typeof objectiveSchema>;

export type { BudgetingMethod, Objective, TimeWindowType, GroupSummary };
3 changes: 3 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
*/

export * from './slo';
export * from './routes';
export * from './indicators';
export * from './common';
60 changes: 60 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/indicators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import {
apmTransactionDurationIndicatorSchema,
apmTransactionErrorRateIndicatorSchema,
histogramIndicatorSchema,
indicatorSchema,
indicatorTypesSchema,
kqlCustomIndicatorSchema,
kqlWithFiltersSchema,
metricCustomIndicatorSchema,
querySchema,
syntheticsAvailabilityIndicatorSchema,
timesliceMetricBasicMetricWithField,
timesliceMetricDocCountMetric,
timesliceMetricIndicatorSchema,
timesliceMetricPercentileMetric,
} from '../schema';

type IndicatorType = t.OutputOf<typeof indicatorTypesSchema>;
type Indicator = t.OutputOf<typeof indicatorSchema>;

type APMTransactionErrorRateIndicator = t.OutputOf<typeof apmTransactionErrorRateIndicatorSchema>;
type APMTransactionDurationIndicator = t.OutputOf<typeof apmTransactionDurationIndicatorSchema>;

type SyntheticsAvailabilityIndicator = t.OutputOf<typeof syntheticsAvailabilityIndicatorSchema>;

type MetricCustomIndicator = t.OutputOf<typeof metricCustomIndicatorSchema>;
type TimesliceMetricIndicator = t.OutputOf<typeof timesliceMetricIndicatorSchema>;
type TimesliceMetricBasicMetricWithField = t.OutputOf<typeof timesliceMetricBasicMetricWithField>;
type TimesliceMetricDocCountMetric = t.OutputOf<typeof timesliceMetricDocCountMetric>;
type TimesclieMetricPercentileMetric = t.OutputOf<typeof timesliceMetricPercentileMetric>;

type HistogramIndicator = t.OutputOf<typeof histogramIndicatorSchema>;

type KQLCustomIndicator = t.OutputOf<typeof kqlCustomIndicatorSchema>;
type KqlWithFiltersSchema = t.TypeOf<typeof kqlWithFiltersSchema>;
type QuerySchema = t.TypeOf<typeof querySchema>;

export type {
APMTransactionDurationIndicator,
APMTransactionErrorRateIndicator,
SyntheticsAvailabilityIndicator,
IndicatorType,
Indicator,
MetricCustomIndicator,
TimesliceMetricIndicator,
TimesliceMetricBasicMetricWithField,
TimesclieMetricPercentileMetric,
TimesliceMetricDocCountMetric,
HistogramIndicator,
KQLCustomIndicator,
KqlWithFiltersSchema,
QuerySchema,
};
47 changes: 47 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/routes/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { indicatorSchema, timeWindowSchema } from '../../schema';
import { allOrAnyStringOrArray } from '../../schema/common';
import {
budgetingMethodSchema,
objectiveSchema,
optionalSettingsSchema,
sloIdSchema,
tagsSchema,
} from '../../schema/slo';

const createSLOParamsSchema = t.type({
body: t.intersection([
t.type({
name: t.string,
description: t.string,
indicator: indicatorSchema,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
objective: objectiveSchema,
}),
t.partial({
id: sloIdSchema,
settings: optionalSettingsSchema,
tags: tagsSchema,
groupBy: allOrAnyStringOrArray,
revision: t.number,
}),
]),
});

const createSLOResponseSchema = t.type({
id: sloIdSchema,
});

type CreateSLOInput = t.OutputOf<typeof createSLOParamsSchema.props.body>; // Raw payload sent by the frontend
type CreateSLOParams = t.TypeOf<typeof createSLOParamsSchema.props.body>; // Parsed payload used by the backend
type CreateSLOResponse = t.TypeOf<typeof createSLOResponseSchema>; // Raw response sent to the frontend

export { createSLOParamsSchema, createSLOResponseSchema };
export type { CreateSLOInput, CreateSLOParams, CreateSLOResponse };
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { sloIdSchema } from '../../schema/slo';

export * from './compute_burn_rate';
export * from './error_budget';
export * from './compute_sli';
export * from './compute_summary_status';
export * from './date_range';
export * from './validate_slo';
const deleteSLOParamsSchema = t.type({
path: t.type({
id: sloIdSchema,
}),
});

export { deleteSLOParamsSchema };
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';
import { sloIdSchema } from '../../schema/slo';

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

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

export { deleteSLOInstancesParamsSchema };
export type { DeleteSLOInstancesInput, DeleteSLOInstancesParams };
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import {
budgetingMethodSchema,
objectiveSchema,
sloIdSchema,
timeWindowSchema,
} from '../../schema';
import {
allOrAnyString,
allOrAnyStringOrArray,
dateType,
summarySchema,
} from '../../schema/common';

const fetchHistoricalSummaryParamsSchema = t.type({
body: t.type({
list: t.array(
t.intersection([
t.type({
sloId: sloIdSchema,
instanceId: t.string,
timeWindow: timeWindowSchema,
budgetingMethod: budgetingMethodSchema,
objective: objectiveSchema,
groupBy: allOrAnyStringOrArray,
revision: t.number,
}),
t.partial({ remoteName: t.string }),
])
),
}),
});

const historicalSummarySchema = t.intersection([
t.type({
date: dateType,
}),
summarySchema,
]);

const fetchHistoricalSummaryResponseSchema = t.array(
t.type({
sloId: sloIdSchema,
instanceId: allOrAnyString,
data: t.array(historicalSummarySchema),
})
);

type FetchHistoricalSummaryParams = t.TypeOf<typeof fetchHistoricalSummaryParamsSchema.props.body>;
type FetchHistoricalSummaryResponse = t.OutputOf<typeof fetchHistoricalSummaryResponseSchema>;
type HistoricalSummaryResponse = t.OutputOf<typeof historicalSummarySchema>;

export {
fetchHistoricalSummaryParamsSchema,
fetchHistoricalSummaryResponseSchema,
historicalSummarySchema,
};
export type {
FetchHistoricalSummaryParams,
FetchHistoricalSummaryResponse,
HistoricalSummaryResponse,
};
40 changes: 40 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/rest_specs/routes/find.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { sloWithDataResponseSchema } from '../slo';

const sortDirectionSchema = t.union([t.literal('asc'), t.literal('desc')]);
const sortBySchema = t.union([
t.literal('error_budget_consumed'),
t.literal('error_budget_remaining'),
t.literal('sli_value'),
t.literal('status'),
]);

const findSLOParamsSchema = t.partial({
query: t.partial({
filters: t.string,
kqlQuery: t.string,
page: t.string,
perPage: t.string,
sortBy: sortBySchema,
sortDirection: sortDirectionSchema,
}),
});

const findSLOResponseSchema = t.type({
page: t.number,
perPage: t.number,
total: t.number,
results: t.array(sloWithDataResponseSchema),
});

type FindSLOParams = t.TypeOf<typeof findSLOParamsSchema.props.query>;
type FindSLOResponse = t.OutputOf<typeof findSLOResponseSchema>;

export { findSLOParamsSchema, findSLOResponseSchema };
export type { FindSLOParams, FindSLOResponse };
Loading

0 comments on commit 721d354

Please sign in to comment.