[Metrics UI] Add timerange and sorting to node detail metadata request (#81033)

This commit is contained in:
Chris Cowan 2020-10-21 08:10:31 -07:00 committed by GitHub
parent ab8bf782c3
commit 2a82bddfe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

View file

@ -58,7 +58,14 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => {
nameToFeature('metrics')
);
const info = await getNodeInfo(framework, requestContext, configuration, nodeId, nodeType);
const info = await getNodeInfo(
framework,
requestContext,
configuration,
nodeId,
nodeType,
timeRange
);
const cloudInstanceId = get(info, 'cloud.instance.id');
const cloudMetricsMetadata = cloudInstanceId

View file

@ -20,7 +20,8 @@ export const getNodeInfo = async (
requestContext: RequestHandlerContext,
sourceConfiguration: InfraSourceConfiguration,
nodeId: string,
nodeType: InventoryItemType
nodeType: InventoryItemType,
timeRange: { from: number; to: number }
): Promise<InfraMetadataInfo> => {
// If the nodeType is a Kubernetes pod then we need to get the node info
// from a host record instead of a pod. This is due to the fact that any host
@ -33,7 +34,8 @@ export const getNodeInfo = async (
requestContext,
sourceConfiguration,
nodeId,
nodeType
nodeType,
timeRange
);
if (kubernetesNodeName) {
return getNodeInfo(
@ -41,12 +43,14 @@ export const getNodeInfo = async (
requestContext,
sourceConfiguration,
kubernetesNodeName,
'host'
'host',
timeRange
);
}
return {};
}
const fields = findInventoryFields(nodeType, sourceConfiguration.fields);
const timestampField = sourceConfiguration.fields.timestamp;
const params = {
allowNoIndices: true,
ignoreUnavailable: true,
@ -55,9 +59,21 @@ export const getNodeInfo = async (
body: {
size: 1,
_source: ['host.*', 'cloud.*'],
sort: [{ [timestampField]: 'desc' }],
query: {
bool: {
filter: [{ match: { [fields.id]: nodeId } }],
filter: [
{ match: { [fields.id]: nodeId } },
{
range: {
[timestampField]: {
gte: timeRange.from,
lte: timeRange.to,
format: 'epoch_millis',
},
},
},
],
},
},
},

View file

@ -15,9 +15,11 @@ export const getPodNodeName = async (
requestContext: RequestHandlerContext,
sourceConfiguration: InfraSourceConfiguration,
nodeId: string,
nodeType: 'host' | 'pod' | 'container'
nodeType: 'host' | 'pod' | 'container',
timeRange: { from: number; to: number }
): Promise<string | undefined> => {
const fields = findInventoryFields(nodeType, sourceConfiguration.fields);
const timestampField = sourceConfiguration.fields.timestamp;
const params = {
allowNoIndices: true,
ignoreUnavailable: true,
@ -26,11 +28,21 @@ export const getPodNodeName = async (
body: {
size: 1,
_source: ['kubernetes.node.name'],
sort: [{ [timestampField]: 'desc' }],
query: {
bool: {
filter: [
{ match: { [fields.id]: nodeId } },
{ exists: { field: `kubernetes.node.name` } },
{
range: {
[timestampField]: {
gte: timeRange.from,
lte: timeRange.to,
format: 'epoch_millis',
},
},
},
],
},
},