Skip to content

Commit

Permalink
Adding optimizations for snapshot request
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Nov 18, 2020
1 parent 09fd98a commit 06d1334
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useSnapshot(
interval: '1m',
to: currentTime,
from: currentTime - 1200 * 1000,
lookbackSize: 20,
lookbackSize: 5,
};

const { error, loading, response, makeRequest } = useHTTPRequest<SnapshotNodeResponse>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const findIntervalForMetrics = async (

const modules = await Promise.all(
fields.map(
async (field) => await getDatasetForField(client, field as string, options.indexPattern)
async (field) =>
await getDatasetForField(client, field as string, options.indexPattern, options.timerange)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,31 @@ interface EventDatasetHit {
export const getDatasetForField = async (
client: ESSearchClient,
field: string,
indexPattern: string
indexPattern: string,
timerange: { field: string; to: number; from: number }
) => {
const params = {
allowNoIndices: true,
ignoreUnavailable: true,
terminateAfter: 1,
index: indexPattern,
body: {
query: { exists: { field } },
query: {
bool: {
filter: [
{ exists: { field } },
{
range: {
[timerange.field]: {
gte: timerange.from,
lte: timerange.to,
format: 'epoch_millis',
},
},
},
],
},
},
size: 1,
_source: ['event.dataset'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ const aggregationsToModules = async (
const fields = await Promise.all(
uniqueFields.map(
async (field) =>
await getDatasetForField(client, field as string, options.sourceConfiguration.metricAlias)
await getDatasetForField(client, field as string, options.sourceConfiguration.metricAlias, {
...options.timerange,
field: options.sourceConfiguration.fields.timestamp,
})
)
);
return fields.filter((f) => f) as string[];
Expand Down
13 changes: 6 additions & 7 deletions x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ export const getNodes = async (
snapshotRequest
);
const metricsApiResponse = await queryAllData(client, metricsApiRequest);
return copyMissingMetrics(
transformMetricsApiResponseToSnapshotResponse(
metricsApiRequest,
snapshotRequest,
source,
metricsApiResponse
)
const snapshotResponse = transformMetricsApiResponseToSnapshotResponse(
metricsApiRequest,
snapshotRequest,
source,
metricsApiResponse
);
return copyMissingMetrics(snapshotResponse);
};

0 comments on commit 06d1334

Please sign in to comment.