Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [ML] Handling data recognizer saved object errors (#72447) #72631

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/common/types/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function getPluginPrivileges() {
catalogue: [PLUGIN_ID],
savedObject: {
all: [],
read: ['index-pattern', 'search'],
read: ['index-pattern', 'dashboard', 'search', 'visualization'],
},
};

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface KibanaObject {
title: string;
config: KibanaObjectConfig;
exists?: boolean;
error?: any;
}

export interface KibanaObjects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const KibanaObjects: FC<KibanaObjectItemProps> = memo(
</EuiTitle>
<EuiSpacer size="s" />
<ul>
{kibanaObjects.map(({ id, title, success, exists }, i) => (
{kibanaObjects.map(({ id, title, success, exists, error }, i) => (
<li key={id}>
<EuiFlexGroup alignItems="center" gutterSize="s">
<EuiFlexItem>
Expand All @@ -55,6 +55,11 @@ export const KibanaObjects: FC<KibanaObjectItemProps> = memo(
<EuiText size="s" color={exists ? 'subdued' : 'secondary'}>
{title}
</EuiText>
{success === false && error !== undefined && (
<EuiText size="xs" color="danger">
{error.message}
</EuiText>
)}
</EuiFlexItem>
{exists && (
<EuiFlexItem grow={false}>
Expand Down
30 changes: 28 additions & 2 deletions x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface RecognizeResult {
interface ObjectExistResult {
id: string;
type: string;
exists?: boolean;
}

interface ObjectExistResponse {
Expand Down Expand Up @@ -493,7 +494,13 @@ export class DataRecognizer {
// update the exists flag in the results
this.updateKibanaResults(results.kibana, savedObjects);
// create the savedObjects
saveResults.savedObjects = await this.saveKibanaObjects(savedObjects);
try {
saveResults.savedObjects = await this.saveKibanaObjects(savedObjects);
} catch (error) {
// only one error is returned for the bulk create saved object request
// so populate every saved object with the same error.
this.populateKibanaResultErrors(results.kibana, error.output?.payload);
}
}
// merge all the save results
this.updateResults(results, saveResults);
Expand Down Expand Up @@ -610,7 +617,26 @@ export class DataRecognizer {
(type) => {
kibanaSaveResults[type].forEach((resultItem) => {
const i = objectExistResults.find((o) => o.id === resultItem.id && o.type === type);
resultItem.exists = i !== undefined;
resultItem.exists = i !== undefined && i.exists;
});
}
);
}

// add an error object to every kibana saved object,
// if it doesn't already exist.
populateKibanaResultErrors(
kibanaSaveResults: DataRecognizerConfigResponse['kibana'],
error: any
) {
const errorObj =
error === undefined ? { message: 'Unknown error when creating saved object' } : error;
(Object.keys(kibanaSaveResults) as Array<keyof DataRecognizerConfigResponse['kibana']>).forEach(
(type) => {
kibanaSaveResults[type].forEach((resultItem) => {
if (resultItem.exists === false) {
resultItem.error = errorObj;
}
});
}
);
Expand Down