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

[ingest] log error instead of throw #66254

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AppContextService {
private isProductionMode: boolean = false;
private kibanaVersion: string | undefined;
private cloud?: CloudSetup;
private logger?: Logger;
private logger: Logger | undefined;
private httpSetup?: HttpServiceSetup;

public async start(appContext: IngestManagerAppContext) {
Expand Down Expand Up @@ -53,7 +53,7 @@ class AppContextService {

public getSecurity() {
if (!this.security) {
throw new Error('Secury service not set.');
throw new Error('Security service not set.');
}
return this.security;
}
Expand All @@ -63,6 +63,9 @@ class AppContextService {
}

public getLogger() {
if (!this.logger) {
throw new Error('Logger not set.');
}
return this.logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Registry from '../../registry';
import { loadFieldsFromYaml, Fields, Field } from '../../fields/field';
import { getPackageKeysByStatus } from '../../packages/get';
import { InstallationStatus, RegistryPackage, CallESAsCurrentUser } from '../../../../types';
import { appContextService } from '../../../../services';

interface FieldFormatMap {
[key: string]: FieldFormatMapItem;
Expand Down Expand Up @@ -366,10 +367,11 @@ const getFieldFormatParams = (field: Field): FieldFormatParams => {
return params;
};

export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) =>
export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) => {
// create placeholder indices to supress errors in the kibana Dashboards app
// that no matching indices exist https://github.com/elastic/kibana/issues/62343
Promise.all(
const logger = appContextService.getLogger();
return Promise.all(
Object.keys(IndexPatternType).map(async indexPattern => {
const defaultIndexPatternName = indexPattern + INDEX_PATTERN_PLACEHOLDER_SUFFIX;
const indexExists = await callCluster('indices.exists', { index: defaultIndexPatternName });
Expand All @@ -386,9 +388,9 @@ export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) =>
},
});
} catch (putErr) {
// throw new Error(`${defaultIndexPatternName} could not be created`);
throw new Error(putErr);
logger.error(`${defaultIndexPatternName} could not be created`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the logger is indeed undefined, won't this result in an error?

Copy link
Contributor Author

@neptunian neptunian May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get in the plugin constructor and pass it to appContextService in the plugin start(). In what case would it be undefined? I added a check in the getLogger() where it throws an error if for some reason it were.

}
}
})
);
};