Skip to content

Commit

Permalink
[8.16] fix(slo): Override transform _id to ensure uniqness (#198610) (#…
Browse files Browse the repository at this point in the history
…198699)

# Backport

This will backport the following commits from `main` to `8.16`:
- [fix(slo): Override transform _id to ensure uniqness
(#198610)](#198610)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Kevin
Delemme","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-01T15:36:41Z","message":"fix(slo):
Override transform _id to ensure uniqness
(#198610)","sha":"98db4d6f75f05eba1682e0e903bf2d9c909b37f2","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"title":"fix(slo):
Override transform _id to ensure
uniqness","number":198610,"url":"https://github.com/elastic/kibana/pull/198610","mergeCommit":{"message":"fix(slo):
Override transform _id to ensure uniqness
(#198610)","sha":"98db4d6f75f05eba1682e0e903bf2d9c909b37f2"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198610","number":198610,"mergeCommit":{"message":"fix(slo):
Override transform _id to ensure uniqness
(#198610)","sha":"98db4d6f75f05eba1682e0e903bf2d9c909b37f2"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kevin Delemme <[email protected]>
  • Loading branch information
kibanamachine and kdelemme authored Nov 1, 2024
1 parent 4cf7f33 commit ebe9f29
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 166 deletions.
31 changes: 30 additions & 1 deletion x-pack/packages/kbn-slo-schema/src/schema/slo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import * as t from 'io-ts';
import { Either } from 'fp-ts/Either';
import { allOrAnyStringOrArray, dateType } from './common';
import { durationType } from './duration';
import { indicatorSchema } from './indicators';
Expand Down Expand Up @@ -36,7 +37,35 @@ const groupBySchema = allOrAnyStringOrArray;

const optionalSettingsSchema = t.partial({ ...settingsSchema.props });
const tagsSchema = t.array(t.string);
const sloIdSchema = t.string;
// id cannot contain special characters and spaces
const sloIdSchema = new t.Type<string, string, unknown>(
'sloIdSchema',
t.string.is,
(input, context): Either<t.Errors, string> => {
if (typeof input === 'string') {
const valid = isValidId(input);
if (!valid) {
return t.failure(
input,
context,
'Invalid slo id, must be between 8 and 48 characters and contain only letters, numbers, hyphens, and underscores'
);
}

return t.success(input);
} else {
return t.failure(input, context);
}
},
t.identity
);

function isValidId(id: string): boolean {
const MIN_ID_LENGTH = 8;
const MAX_ID_LENGTH = 48;
const validLength = MIN_ID_LENGTH <= id.length && id.length <= MAX_ID_LENGTH;
return validLength && /^[a-z0-9-_]+$/.test(id);
}

const sloDefinitionSchema = t.type({
id: sloIdSchema,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/packages/kbn-slo-schema/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"kbn_references": [
"@kbn/std",
"@kbn/io-ts-utils"
"@kbn/io-ts-utils",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const getSLOPipelineTemplate = (slo: SLODefinition) => ({
id: getSLOPipelineId(slo.id, slo.revision),
description: `Ingest pipeline for SLO rollup data [id: ${slo.id}, revision: ${slo.revision}]`,
processors: [
{
set: {
field: '_id',
value: `{{{_id}}}-${slo.id}-${slo.revision}`,
},
},
{
set: {
field: 'event.ingested',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ebe9f29

Please sign in to comment.