Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics UI] Optimizations for Snapshot and Inventory Metadata #83596

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/http_api/inventory_meta_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const InventoryMetaResponseRT = rt.type({
export const InventoryMetaRequestRT = rt.type({
sourceId: rt.string,
nodeType: ItemTypeRT,
currentTime: rt.number,
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
});

export type InventoryMetaRequest = rt.TypeOf<typeof InventoryMetaRequestRT>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const Layout = () => {
<>
<TopActionContainer ref={topActionMeasureRef}>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center" gutterSize="m">
<Toolbar nodeType={nodeType} />
<Toolbar nodeType={nodeType} currentTime={currentTime} />
<EuiFlexItem grow={false}>
<IntervalLabel intervalAsString={intervalAsString} />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ const wrapToolbarItems = (

interface Props {
nodeType: InventoryItemType;
currentTime: number;
}

export const Toolbar = ({ nodeType }: Props) => {
export const Toolbar = ({ nodeType, currentTime }: Props) => {
const { sourceId } = useSourceContext();
const { accounts, regions } = useInventoryMeta(sourceId, nodeType);
const { accounts, regions } = useInventoryMeta(sourceId, nodeType, currentTime);
const ToolbarItems = findToolbar(nodeType);
return wrapToolbarItems(ToolbarItems, accounts, regions);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
} from '../../../../../common/http_api/inventory_meta_api';
import { InventoryItemType } from '../../../../../common/inventory_models/types';

export function useInventoryMeta(sourceId: string, nodeType: InventoryItemType) {
export function useInventoryMeta(
sourceId: string,
nodeType: InventoryItemType,
currentTime: number
) {
const decodeResponse = (response: any) => {
return pipe(
InventoryMetaResponseRT.decode(response),
Expand All @@ -29,6 +33,7 @@ export function useInventoryMeta(sourceId: string, nodeType: InventoryItemType)
JSON.stringify({
sourceId,
nodeType,
currentTime,
}),
decodeResponse
);
Expand Down
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,
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
};

const { error, loading, response, makeRequest } = useHTTPRequest<SnapshotNodeResponse>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const initInventoryMetaRoute = (libs: InfraBackendLibs) => {
},
async (requestContext, request, response) => {
try {
const { sourceId, nodeType } = pipe(
const { sourceId, nodeType, currentTime } = pipe(
InventoryMetaRequestRT.decode(request.body),
fold(throwErrors(Boom.badRequest), identity)
);
Expand All @@ -46,7 +46,8 @@ export const initInventoryMetaRoute = (libs: InfraBackendLibs) => {
framework,
requestContext,
configuration,
nodeType
nodeType,
currentTime
);

return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const getCloudMetadata = async (
framework: KibanaFramework,
req: RequestHandlerContext,
sourceConfiguration: InfraSourceConfiguration,
nodeType: InventoryItemType
nodeType: InventoryItemType,
currentTime: number
): Promise<CloudMetaData> => {
const model = findInventoryModel(nodeType);

Expand All @@ -36,7 +37,18 @@ export const getCloudMetadata = async (
body: {
query: {
bool: {
must: [{ match: { 'event.module': model.requiredModule } }],
must: [
{
range: {
[sourceConfiguration.fields.timestamp]: {
gte: currentTime - 86400000, // 24 hours ago
lte: currentTime,
format: 'epoch_millis',
},
},
},
{ match: { 'event.module': model.requiredModule } },
],
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
},
},
size: 0,
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',
},
},
},
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
],
},
},
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);
};