-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs UI] log rate setup index validation (#50008)
* Scaffold API endpoint * Implement the API endpoint * Implement API client * Set error messages in `useAnalysisSetupState` * Show validation errors next to the submit button * Check for setup errors regarding the selected indexes * Call validation only once Enrich the `availableIndices` array with validation information to show it later in the form. * Ensure validation runs before showing the indices * Adjust naming conventions - Replace `index_pattern` with `indices`, since it means something different in kibana. - Group validation actions under the `validation` namespace. * Move index error messages to the `InitialConfigurationStep` * Move error messages to the UI layer * Move validation call to `useAnalysisSetupState` * Pass timestamp as a parameter of `useAnalysisSetupState` * Fix regression with the index names in the API response * Use `_field_caps` api * s/timestamp/timestampField/g * Tweak error messages * Move `ValidationIndicesUIError` to `log_analysis_setup_state` * Track validation status It's safer to rely on the state of the promise instead of treating an empty array as "loading" * Handle network errors * Use individual `<EuiCheckbox />` elements for the indices This allows to disable individual checkboxes * Pass the whole `validatedIndices` array to the inner objects This will make easier to determine which indeces have errors in the checkbox list itself and simplify the state we keep track of. * Disable indices with errors Show a tooltip above the disabled index to explain why it cannot be selected. * Pass indices to the API as an array * Show overlay while the validation loads * Wrap tooltips on a `block` element Prevents the checkboxes from collapsing on the same line * Use the right dependencies for `useEffect => validateIndices()` * Restore formatter function name * Simplify mapping of selected indices to errors * s/checked/isSelected/g * Make errors field-generic * Allow multiple errors per index * Simplify code a bit
- Loading branch information
Alejandro Fernández
authored
Nov 25, 2019
1 parent
c7f8086
commit 2acc287
Showing
19 changed files
with
487 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*/ | ||
|
||
export * from './results'; | ||
export * from './validation'; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/common/http_api/log_analysis/validation/index.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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './indices'; |
51 changes: 51 additions & 0 deletions
51
x-pack/legacy/plugins/infra/common/http_api/log_analysis/validation/indices.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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
|
||
export const LOG_ANALYSIS_VALIDATION_INDICES_PATH = '/api/infra/log_analysis/validation/indices'; | ||
|
||
/** | ||
* Request types | ||
*/ | ||
export const validationIndicesRequestPayloadRT = rt.type({ | ||
data: rt.type({ | ||
timestampField: rt.string, | ||
indices: rt.array(rt.string), | ||
}), | ||
}); | ||
|
||
export type ValidationIndicesRequestPayload = rt.TypeOf<typeof validationIndicesRequestPayloadRT>; | ||
|
||
/** | ||
* Response types | ||
* */ | ||
export const validationIndicesErrorRT = rt.union([ | ||
rt.type({ | ||
error: rt.literal('INDEX_NOT_FOUND'), | ||
index: rt.string, | ||
}), | ||
rt.type({ | ||
error: rt.literal('FIELD_NOT_FOUND'), | ||
index: rt.string, | ||
field: rt.string, | ||
}), | ||
rt.type({ | ||
error: rt.literal('FIELD_NOT_VALID'), | ||
index: rt.string, | ||
field: rt.string, | ||
}), | ||
]); | ||
|
||
export type ValidationIndicesError = rt.TypeOf<typeof validationIndicesErrorRT>; | ||
|
||
export const validationIndicesResponsePayloadRT = rt.type({ | ||
data: rt.type({ | ||
errors: rt.array(validationIndicesErrorRT), | ||
}), | ||
}); | ||
|
||
export type ValidationIndicesResponsePayload = rt.TypeOf<typeof validationIndicesResponsePayloadRT>; |
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ | |
"boom": "7.3.0", | ||
"lodash": "^4.17.15" | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...k/legacy/plugins/infra/public/containers/logs/log_analysis/api/index_patterns_validate.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,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { fold } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { identity } from 'fp-ts/lib/function'; | ||
import { kfetch } from 'ui/kfetch'; | ||
|
||
import { | ||
LOG_ANALYSIS_VALIDATION_INDICES_PATH, | ||
validationIndicesRequestPayloadRT, | ||
validationIndicesResponsePayloadRT, | ||
} from '../../../../../common/http_api'; | ||
|
||
import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; | ||
|
||
export const callIndexPatternsValidate = async (timestampField: string, indices: string[]) => { | ||
const response = await kfetch({ | ||
method: 'POST', | ||
pathname: LOG_ANALYSIS_VALIDATION_INDICES_PATH, | ||
body: JSON.stringify( | ||
validationIndicesRequestPayloadRT.encode({ data: { timestampField, indices } }) | ||
), | ||
}); | ||
|
||
return pipe( | ||
validationIndicesResponsePayloadRT.decode(response), | ||
fold(throwErrors(createPlainError), identity) | ||
); | ||
}; |
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
Oops, something went wrong.