Skip to content

Commit

Permalink
[9.0] [Snapshot and restore] Avoid duplicated error messages (#209316) (
Browse files Browse the repository at this point in the history
#209455)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Snapshot and restore] Avoid duplicated error messages
(#209316)](#209316)

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

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

<!--BACKPORT [{"author":{"name":"Sonia Sanz
Vivas","email":"sonia.sanzvivas@elastic.co"},"sourceCommit":{"committedDate":"2025-02-04T07:26:08Z","message":"[Snapshot
and restore] Avoid duplicated error messages (#209316)\n\nFixes
https://github.com/elastic/kibana/issues/187065\n\n## Summary\nIn the
repository creation endpoint, when the validation failed, we
were\nshowing duplicated errors. This was caused by how the validation
schema\nwas build. This PR refactors the duplication schema so it
doesn't\nduplicate the nama field.\n\n### How to test\n\n* RunES with
yarn es snapshot --license=trial -E\npath.repo=/tmp/es-backups\n*
Navigate to repos list and try creating a new repo\n* Fill the name
input with an string longer than 1000 chars.\n* Verify the error message
when saving the repo is not duplicated\n\n### Screenshot\n<img
width=\"1032\" alt=\"Screenshot 2025-02-03 at 15 24
27\"\nsrc=\"https://github.com/user-attachments/assets/75231f68-a13e-44bf-8d8a-be488c9f25e5\"\n/>","sha":"8d46aff46bb59b7b417d348fd3a1343e560ec413","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Kibana
Management","release_note:skip","Feature:Snapshot and
Restore","v9.0.0","backport:prev-minor","v8.18.0","v9.1.0","v8.19.0"],"title":"[Snapshot
and restore] Avoid duplicated error
messages","number":209316,"url":"https://github.com/elastic/kibana/pull/209316","mergeCommit":{"message":"[Snapshot
and restore] Avoid duplicated error messages (#209316)\n\nFixes
https://github.com/elastic/kibana/issues/187065\n\n## Summary\nIn the
repository creation endpoint, when the validation failed, we
were\nshowing duplicated errors. This was caused by how the validation
schema\nwas build. This PR refactors the duplication schema so it
doesn't\nduplicate the nama field.\n\n### How to test\n\n* RunES with
yarn es snapshot --license=trial -E\npath.repo=/tmp/es-backups\n*
Navigate to repos list and try creating a new repo\n* Fill the name
input with an string longer than 1000 chars.\n* Verify the error message
when saving the repo is not duplicated\n\n### Screenshot\n<img
width=\"1032\" alt=\"Screenshot 2025-02-03 at 15 24
27\"\nsrc=\"https://github.com/user-attachments/assets/75231f68-a13e-44bf-8d8a-be488c9f25e5\"\n/>","sha":"8d46aff46bb59b7b417d348fd3a1343e560ec413"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/209316","number":209316,"mergeCommit":{"message":"[Snapshot
and restore] Avoid duplicated error messages (#209316)\n\nFixes
https://github.com/elastic/kibana/issues/187065\n\n## Summary\nIn the
repository creation endpoint, when the validation failed, we
were\nshowing duplicated errors. This was caused by how the validation
schema\nwas build. This PR refactors the duplication schema so it
doesn't\nduplicate the nama field.\n\n### How to test\n\n* RunES with
yarn es snapshot --license=trial -E\npath.repo=/tmp/es-backups\n*
Navigate to repos list and try creating a new repo\n* Fill the name
input with an string longer than 1000 chars.\n* Verify the error message
when saving the repo is not duplicated\n\n### Screenshot\n<img
width=\"1032\" alt=\"Screenshot 2025-02-03 at 15 24
27\"\nsrc=\"https://github.com/user-attachments/assets/75231f68-a13e-44bf-8d8a-be488c9f25e5\"\n/>","sha":"8d46aff46bb59b7b417d348fd3a1343e560ec413"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sonia Sanz Vivas <sonia.sanzvivas@elastic.co>
  • Loading branch information
kibanamachine and SoniaSanzV authored Feb 4, 2025
1 parent 1908387 commit 777c22c
Showing 1 changed file with 16 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,13 @@ export const policySchema = schema.object({
// Only validate required settings, everything else is optional
const fsRepositorySettings = schema.object({ location: schema.string() }, { unknowns: 'allow' });

const fsRepositorySchema = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: fsRepositorySettings,
});

const readOnlyRepositorySettings = schema.object({
url: schema.string(),
});

const readOnlyRepository = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: readOnlyRepositorySettings,
});

// Only validate required settings, everything else is optional
const s3RepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' });

const s3Repository = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: s3RepositorySettings,
});

// Only validate required settings, everything else is optional
const hdsRepositorySettings = schema.object(
{
Expand All @@ -99,30 +81,27 @@ const hdsRepositorySettings = schema.object(
{ unknowns: 'allow' }
);

const hdsfRepository = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: hdsRepositorySettings,
});

const azureRepositorySettings = schema.object({}, { unknowns: 'allow' });

const azureRepository = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: azureRepositorySettings,
});

// Only validate required settings, everything else is optional
const gcsRepositorySettings = schema.object({ bucket: schema.string() }, { unknowns: 'allow' });

const gcsRepository = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: gcsRepositorySettings,
});
const sourceRepositorySettings = schema.oneOf([
fsRepositorySettings,
readOnlyRepositorySettings,
s3RepositorySettings,
hdsRepositorySettings,
azureRepositorySettings,
gcsRepositorySettings,
schema.object(
{
delegateType: schema.string(),
},
{ unknowns: 'allow' }
),
]);

const sourceRepository = schema.object({
export const repositorySchema = schema.object({
name: schema.string({ maxLength: 1000 }),
type: schema.string(),
settings: schema.oneOf([
Expand All @@ -132,25 +111,10 @@ const sourceRepository = schema.object({
hdsRepositorySettings,
azureRepositorySettings,
gcsRepositorySettings,
schema.object(
{
delegateType: schema.string(),
},
{ unknowns: 'allow' }
),
sourceRepositorySettings,
]),
});

export const repositorySchema = schema.oneOf([
fsRepositorySchema,
readOnlyRepository,
sourceRepository,
s3Repository,
hdsfRepository,
azureRepository,
gcsRepository,
]);

export const restoreSettingsSchema = schema.object({
indices: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])),
renamePattern: schema.maybe(schema.string()),
Expand Down

0 comments on commit 777c22c

Please sign in to comment.