Skip to content

Commit

Permalink
Remove extra logger, replace filter with reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Apr 13, 2021
1 parent 4cbb7b5 commit 3feb1f0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions x-pack/plugins/fleet/server/routes/data_streams/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { KibanaSavedObjectType } from '../../../common';
import type { GetDataStreamsResponse } from '../../../common';
import { getPackageSavedObjects } from '../../services/epm/packages/get';
import { defaultIngestErrorHandler } from '../../errors';
import { appContextService } from '../../services';

const DATA_STREAM_INDEX_PATTERN = 'logs-*-*,metrics-*-*,traces-*-*';

Expand Down Expand Up @@ -47,7 +46,6 @@ interface ESDataStreamStats {

export const getListHandler: RequestHandler = async (context, request, response) => {
const esClient = context.core.elasticsearch.client.asCurrentUser;
const logger = appContextService.getLogger();

const body: GetDataStreamsResponse = {
data_streams: [],
Expand Down Expand Up @@ -195,16 +193,22 @@ export const getListHandler: RequestHandler = async (context, request, response)
if (!packageMetadata[pkgName]) {
// then pick the dashboards from the package saved object
const packageDashboardIds = dashboardIdsByPackageName[pkgName] || [];
const packageDashboards = packageDashboardIds.map((dashboardId) => {
const packageDashboards = packageDashboardIds.reduce<
Array<{ id: string; title: string }>
>((dashboards, dashboardId) => {
const dashboard = allDashboardSavedObjectsById[dashboardId];
return dashboard
? { id: dashboard.id, title: dashboard.attributes.title || dashboard.id }
: undefined;
});
if (dashboard) {
dashboards.push({
id: dashboard.id,
title: dashboard.attributes.title || dashboard.id,
});
}
return dashboards;
}, []);

packageMetadata[pkgName] = {
version: pkgSavedObject.attributes?.version || '',
dashboards: packageDashboards.filter((dashboard) => !!dashboard),
dashboards: packageDashboards,
};
}

Expand All @@ -226,7 +230,6 @@ export const getListHandler: RequestHandler = async (context, request, response)
body,
});
} catch (error) {
logger.error(error);
return defaultIngestErrorHandler({ error, response });
}
};

0 comments on commit 3feb1f0

Please sign in to comment.