Skip to content

Commit

Permalink
[Metrics UI] Add time range to inventory metadata request
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Nov 17, 2020
1 parent 8a7af5b commit 09fd98a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
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,
});

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 @@ -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 } },
],
},
},
size: 0,
Expand Down

0 comments on commit 09fd98a

Please sign in to comment.