forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infrastructure UI] Improve metrics settings error handling (elastic#…
…146272) Closes [elastic#145238](elastic#145238) ## Summary These changes add validation to the Metric Indices passed into the Metrics settings page. New validation is added both in the UI and in the endpoint, performing the following checks: - Index pattern is not an empty string - Index pattern does not contain empty spaces (start, middle, end) (the pattern is not trimmed) - Index pattern does not contain empty entries, comma-separated values should have an acceptable value. In case the value is not valid, the UI will render an appropriate error message. If the `PATCH /api/metrics/source/{sourceId}` request to update the value is manually sent with an invalid value, the server will respond with a 400 status code and an error message. Also, for retro compatibility and to not block the user when the configuration can't be successfully retrieved, in case of internal error the `GET /api/metrics/source/{sourceId}` will return a 404 and on the UI, instead of rendering a blank page, the user will see the empty form and will be able to re-insert the right values. ## Testing Navigate to `Inventory`-> Click on `Settings` on the topbar -> Start writing different metric indices in the Metric Indices field. ### Editing Metric Indices validation https://user-images.githubusercontent.com/34506779/203763021-0f4d8926-ffa4-448a-a038-696732158f4e.mov ### Missing/Broken configuration response https://user-images.githubusercontent.com/34506779/203763120-ffc91cd3-9bf4-43da-a04f-5561ceabf591.mov Co-authored-by: Marco Antonio Ghiani <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
a44304e
commit ddcbf73
Showing
8 changed files
with
161 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/kbn-io-ts-utils/src/index_pattern_rt/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { indexPatternRt } from '.'; | ||
import { isRight } from 'fp-ts/lib/Either'; | ||
|
||
describe('indexPatternRt', () => { | ||
test('passes on valid index pattern strings', () => { | ||
expect(isRight(indexPatternRt.decode('logs-*'))).toBe(true); | ||
expect(isRight(indexPatternRt.decode('logs-*,filebeat-*'))).toBe(true); | ||
}); | ||
|
||
test('fails if the pattern is an empty string', () => { | ||
expect(isRight(indexPatternRt.decode(''))).toBe(false); | ||
}); | ||
|
||
test('fails if the pattern contains empty spaces', () => { | ||
expect(isRight(indexPatternRt.decode(' '))).toBe(false); | ||
expect(isRight(indexPatternRt.decode(' logs-*'))).toBe(false); | ||
expect(isRight(indexPatternRt.decode('logs-* '))).toBe(false); | ||
expect(isRight(indexPatternRt.decode('logs-*, filebeat-*'))).toBe(false); | ||
}); | ||
|
||
test('fails if the pattern contains empty comma-separated entries', () => { | ||
expect(isRight(indexPatternRt.decode(',logs-*'))).toBe(false); | ||
expect(isRight(indexPatternRt.decode('logs-*,'))).toBe(false); | ||
expect(isRight(indexPatternRt.decode('logs-*,,filebeat-*'))).toBe(false); | ||
expect(isRight(indexPatternRt.decode('logs-*,,,filebeat-*'))).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import * as rt from 'io-ts'; | ||
|
||
export const isEmptyString = (value: string) => value === ''; | ||
|
||
export const containsSpaces = (value: string) => value.includes(' '); | ||
|
||
export const containsEmptyEntries = (value: string) => value.split(',').some(isEmptyString); | ||
|
||
export const validateIndexPattern = (indexPattern: string) => { | ||
return ( | ||
!isEmptyString(indexPattern) && | ||
!containsSpaces(indexPattern) && | ||
!containsEmptyEntries(indexPattern) | ||
); | ||
}; | ||
|
||
export interface IndexPatternBrand { | ||
readonly IndexPattern: unique symbol; | ||
} | ||
|
||
type IndexPattern = rt.Branded<string, IndexPatternBrand>; | ||
|
||
export const indexPatternRt = rt.brand( | ||
rt.string, | ||
(pattern): pattern is IndexPattern => validateIndexPattern(pattern), | ||
'IndexPattern' | ||
); | ||
|
||
export type IndexPatternType = rt.TypeOf<typeof indexPatternRt>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters