Skip to content

Commit

Permalink
[Fleet] Use data stream name in query to get data stream info (elasti…
Browse files Browse the repository at this point in the history
…c#115805)

* reduce number of backing indices we query

* remove unused import

* revert to using data stream name
  • Loading branch information
hop-dev authored Oct 26, 2021
1 parent 3246018 commit 73dd334
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions x-pack/plugins/fleet/server/routes/data_streams/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import type { estypes } from '@elastic/elasticsearch';
import { keyBy, keys, merge } from 'lodash';
import type { RequestHandler, SavedObjectsBulkGetObject } from 'src/core/server';
import type { RequestHandler } from 'src/core/server';

import type { DataStream } from '../../types';
import { KibanaSavedObjectType } from '../../../common';
Expand All @@ -15,7 +15,6 @@ import { getPackageSavedObjects } from '../../services/epm/packages/get';
import { defaultIngestErrorHandler } from '../../errors';

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

interface ESDataStreamInfo {
name: string;
timestamp_field: {
Expand Down Expand Up @@ -94,17 +93,12 @@ export const getListHandler: RequestHandler = async (context, request, response)
const allDashboardSavedObjectsResponse = await context.core.savedObjects.client.bulkGet<{
title?: string;
}>(
Object.values(dashboardIdsByPackageName).reduce<SavedObjectsBulkGetObject[]>(
(allDashboards, dashboardIds) => {
return allDashboards.concat(
dashboardIds.map((id) => ({
id,
type: KibanaSavedObjectType.dashboard,
fields: ['title'],
}))
);
},
[]
Object.values(dashboardIdsByPackageName).flatMap((dashboardIds) =>
dashboardIds.map((id) => ({
id,
type: KibanaSavedObjectType.dashboard,
fields: ['title'],
}))
)
);
// Ignore dashboards not found
Expand Down Expand Up @@ -142,12 +136,12 @@ export const getListHandler: RequestHandler = async (context, request, response)
const {
body: { aggregations: dataStreamAggs },
} = await esClient.search({
index: dataStream.indices.map((index) => index.index_name),
index: dataStream.name,
body: {
size: 0,
query: {
bool: {
must: [
filter: [
{
exists: {
field: 'data_stream.namespace',
Expand Down Expand Up @@ -234,7 +228,7 @@ export const getListHandler: RequestHandler = async (context, request, response)
return dataStreamResponse;
});

// Return final data streams objects sorted by last activity, decending
// Return final data streams objects sorted by last activity, descending
// After filtering out data streams that are missing dataset/namespace/type fields
body.data_streams = (await Promise.all(dataStreamPromises))
.filter(({ dataset, namespace, type }) => dataset && namespace && type)
Expand Down

0 comments on commit 73dd334

Please sign in to comment.