Skip to content

Commit 06d1334

Browse files
committed
Adding optimizations for snapshot request
1 parent 09fd98a commit 06d1334

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_snaphot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function useSnapshot(
4444
interval: '1m',
4545
to: currentTime,
4646
from: currentTime - 1200 * 1000,
47-
lookbackSize: 20,
47+
lookbackSize: 5,
4848
};
4949

5050
const { error, loading, response, makeRequest } = useHTTPRequest<SnapshotNodeResponse>(

x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const findIntervalForMetrics = async (
3434

3535
const modules = await Promise.all(
3636
fields.map(
37-
async (field) => await getDatasetForField(client, field as string, options.indexPattern)
37+
async (field) =>
38+
await getDatasetForField(client, field as string, options.indexPattern, options.timerange)
3839
)
3940
);
4041

x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_dataset_for_field.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,31 @@ interface EventDatasetHit {
1717
export const getDatasetForField = async (
1818
client: ESSearchClient,
1919
field: string,
20-
indexPattern: string
20+
indexPattern: string,
21+
timerange: { field: string; to: number; from: number }
2122
) => {
2223
const params = {
2324
allowNoIndices: true,
2425
ignoreUnavailable: true,
2526
terminateAfter: 1,
2627
index: indexPattern,
2728
body: {
28-
query: { exists: { field } },
29+
query: {
30+
bool: {
31+
filter: [
32+
{ exists: { field } },
33+
{
34+
range: {
35+
[timerange.field]: {
36+
gte: timerange.from,
37+
lte: timerange.to,
38+
format: 'epoch_millis',
39+
},
40+
},
41+
},
42+
],
43+
},
44+
},
2945
size: 1,
3046
_source: ['event.dataset'],
3147
},

x-pack/plugins/infra/server/routes/snapshot/lib/create_timerange_with_interval.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ const aggregationsToModules = async (
7575
const fields = await Promise.all(
7676
uniqueFields.map(
7777
async (field) =>
78-
await getDatasetForField(client, field as string, options.sourceConfiguration.metricAlias)
78+
await getDatasetForField(client, field as string, options.sourceConfiguration.metricAlias, {
79+
...options.timerange,
80+
field: options.sourceConfiguration.fields.timestamp,
81+
})
7982
)
8083
);
8184
return fields.filter((f) => f) as string[];

x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ export const getNodes = async (
2323
snapshotRequest
2424
);
2525
const metricsApiResponse = await queryAllData(client, metricsApiRequest);
26-
return copyMissingMetrics(
27-
transformMetricsApiResponseToSnapshotResponse(
28-
metricsApiRequest,
29-
snapshotRequest,
30-
source,
31-
metricsApiResponse
32-
)
26+
const snapshotResponse = transformMetricsApiResponseToSnapshotResponse(
27+
metricsApiRequest,
28+
snapshotRequest,
29+
source,
30+
metricsApiResponse
3331
);
32+
return copyMissingMetrics(snapshotResponse);
3433
};

0 commit comments

Comments
 (0)