Skip to content

Commit

Permalink
Log reason for 404 in field existence check (#81315) (#81743)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Oct 28, 2020
1 parent 3625350 commit d16d005
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/server/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export class LensServerPlugin implements Plugin<{}, {}, {}, {}> {
private readonly kibanaIndexConfig: Observable<{ kibana: { index: string } }>;
private readonly telemetryLogger: Logger;

constructor(initializerContext: PluginInitializerContext) {
constructor(private initializerContext: PluginInitializerContext) {
this.kibanaIndexConfig = initializerContext.config.legacy.globalConfig$;
this.telemetryLogger = initializerContext.logger.get('usage');
}
setup(core: CoreSetup<PluginStartContract>, plugins: PluginSetupContract) {
setupSavedObjects(core);
setupRoutes(core);
setupRoutes(core, this.initializerContext.logger.get());
if (plugins.usageCollection && plugins.taskManager) {
registerLensUsageCollector(
plugins.usageCollection,
Expand Down
19 changes: 13 additions & 6 deletions x-pack/plugins/lens/server/routes/existing_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import Boom from 'boom';
import { schema } from '@kbn/config-schema';
import { ILegacyScopedClusterClient, SavedObject, RequestHandlerContext } from 'src/core/server';
import { CoreSetup } from 'src/core/server';
import { CoreSetup, Logger } from 'src/core/server';
import { BASE_API_URL } from '../../common';
import { IndexPatternAttributes, UI_SETTINGS } from '../../../../../src/plugins/data/server';

export function isBoomError(error: { isBoom?: boolean }): error is Boom {
return error.isBoom === true;
}

/**
* The number of docs to sample to determine field empty status.
*/
Expand All @@ -24,7 +28,7 @@ export interface Field {
script?: string;
}

export async function existingFieldsRoute(setup: CoreSetup) {
export async function existingFieldsRoute(setup: CoreSetup, logger: Logger) {
const router = setup.http.createRouter();

router.post(
Expand Down Expand Up @@ -52,14 +56,17 @@ export async function existingFieldsRoute(setup: CoreSetup) {
}),
});
} catch (e) {
logger.info(
`Field existence check failed: ${isBoomError(e) ? e.output.payload.message : e.message}`
);
if (e.status === 404) {
return res.notFound();
return res.notFound({ body: e.message });
}
if (e.isBoom) {
if (isBoomError(e)) {
if (e.output.statusCode === 404) {
return res.notFound();
return res.notFound({ body: e.output.payload.message });
}
return res.internalError(e.output.message);
return res.internalError({ body: e.output.payload.message });
} else {
return res.internalError({
body: Boom.internal(e.message || e.name),
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/lens/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup } from 'src/core/server';
import { CoreSetup, Logger } from 'src/core/server';
import { existingFieldsRoute } from './existing_fields';
import { initFieldsRoute } from './field_stats';
import { initLensUsageRoute } from './telemetry';

export function setupRoutes(setup: CoreSetup) {
existingFieldsRoute(setup);
export function setupRoutes(setup: CoreSetup, logger: Logger) {
existingFieldsRoute(setup, logger);
initFieldsRoute(setup);
initLensUsageRoute(setup);
}

0 comments on commit d16d005

Please sign in to comment.