Skip to content

Commit

Permalink
[ML] Fixing module setup error for insufficient index pattern privile…
Browse files Browse the repository at this point in the history
…ges (#55989) (#56024)
  • Loading branch information
jgowdyelastic authored Jan 27, 2020
1 parent fc8e614 commit b450e87
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export class DataRecognizer {
request
) {
this.savedObjectsClient = request.getSavedObjectsClient();
this.indexPatterns = await this.loadIndexPatterns();

// load the config from disk
const moduleConfig = await this.getModule(moduleId, jobPrefix);
Expand All @@ -303,7 +302,7 @@ export class DataRecognizer {

this.indexPatternName =
indexPatternName === undefined ? moduleConfig.defaultIndexPattern : indexPatternName;
this.indexPatternId = this.getIndexPatternId(this.indexPatternName);
this.indexPatternId = await this.getIndexPatternId(this.indexPatternName);

// the module's jobs contain custom URLs which require an index patten id
// but there is no corresponding index pattern, throw an error
Expand Down Expand Up @@ -450,12 +449,17 @@ export class DataRecognizer {
}

// returns a id based on an index pattern name
getIndexPatternId(name) {
if (this.indexPatterns && this.indexPatterns.saved_objects) {
const ip = this.indexPatterns.saved_objects.find(i => i.attributes.title === name);
async getIndexPatternId(name) {
try {
const indexPatterns = await this.loadIndexPatterns();
if (indexPatterns === undefined || indexPatterns.saved_objects === undefined) {
return;
}
const ip = indexPatterns.saved_objects.find(i => i.attributes.title === name);
return ip !== undefined ? ip.id : undefined;
} else {
return undefined;
} catch (error) {
mlLog.warn(`Error loading index patterns, ${error}`);
return;
}
}

Expand Down

0 comments on commit b450e87

Please sign in to comment.