kibana/x-pack/test/api_integration/apis/metrics_ui/metrics.ts
Carlos Crespo d79a38363a
[Infra UI] Cleanup host-specific Node Detail Page code (#166828)
closes: https://github.com/elastic/kibana/issues/166428

## Summary

This PR removes code that is no longer needed after replacing the Node
Details View for Host with the Asset Details.

### TSVB

The TSVB files were apparently only used to display charts in the Node
Details view. Due to the Asset Details using Lens to power the charts,
corresponding `host` TSVB formulas and configs are no longer needed.

Therefore, `host*`, `hostK8s*`, and `hostDocker*` (the latter appears to
have never been used) have been removed. Additionally, `aws*` from
`required_metrics` was also removed because it was host-specific.

### FE Components

The main change is in the `useMetadata` hook. I have changed the hook
signature, making `requiredMetrics` optional. This parameter is used to
process additional filtering and is only used in asset types that the
old Node Details page supports. Not passing it is not expected to break
other places that depend on this hook.

### Server

Removing TSVB files has a direct impact on the
`api/metrics/node_details` endpoint. This endpoint is only used to
provide data to the Node Details page. It returns a 400 error if an
invalid metric is passed - which will be the case for hosts

**Example Request:**
```json
POST kbn:api/metrics/node_details
{
  "metrics": [
    "hostK8sCpuCap",
    "hostSystemOverview"
  ],
  "nodeId": "gke-release-oblt-release-oblt-pool-c4163099-bcaj",
  "nodeType": "host",
  "timerange": {
    "from": 1695210522045,
    "to": 1695214122045,
    "interval": ">=1m"
  },
  "cloudId": "6106013995483209805",
  "sourceId": "default"
}
```

**Response:**
```json
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Failed to validate: \n  in metrics/0: \"hostK8sCpuCap\" does not match expected type \"podOverview\" | \"podCpuUsage\" | \"podMemoryUsage\" | \"podLogUsage\" | \"podNetworkTraffic\" | \"containerOverview\" | \"containerCpuKernel\" | \"containerCpuUsage\" | \"containerDiskIOOps\" | \"containerDiskIOBytes\" | \"containerMemory\" | \"containerNetworkTraffic\" | \"containerK8sOverview\" | \"containerK8sCpuUsage\" | \"containerK8sMemoryUsage\" | \"nginxHits\" | \"nginxRequestRate\" | \"nginxActiveConnections\" | \"nginxRequestsPerConnection\" | \"awsEC2CpuUtilization\" | \"awsEC2NetworkTraffic\" | \"awsEC2DiskIOBytes\" | \"awsS3TotalRequests\" | \"awsS3NumberOfObjects\" | \"awsS3BucketSize\" | \"awsS3DownloadBytes\" | \"awsS3UploadBytes\" | \"awsRDSCpuTotal\" | \"awsRDSConnections\" | \"awsRDSQueriesExecuted\" | \"awsRDSActiveTransactions\" | \"awsRDSLatency\" | \"awsSQSMessagesVisible\" | \"awsSQSMessagesDelayed\" | \"awsSQSMessagesSent\" | \"awsSQSMessagesEmpty\" | \"awsSQSOldestMessage\" | \"custom\"\n  in metrics/1: \"hostSystemOverview\" does not match expected type \"podOverview\" | \"podCpuUsage\" | \"podMemoryUsage\" | \"podLogUsage\" | \"podNetworkTraffic\" | \"containerOverview\" | \"containerCpuKernel\" | \"containerCpuUsage\" | \"containerDiskIOOps\" | \"containerDiskIOBytes\" | \"containerMemory\" | \"containerNetworkTraffic\" | \"containerK8sOverview\" | \"containerK8sCpuUsage\" | \"containerK8sMemoryUsage\" | \"nginxHits\" | \"nginxRequestRate\" | \"nginxActiveConnections\" | \"nginxRequestsPerConnection\" | \"awsEC2CpuUtilization\" | \"awsEC2NetworkTraffic\" | \"awsEC2DiskIOBytes\" | \"awsS3TotalRequests\" | \"awsS3NumberOfObjects\" | \"awsS3BucketSize\" | \"awsS3DownloadBytes\" | \"awsS3UploadBytes\" | \"awsRDSCpuTotal\" | \"awsRDSConnections\" | \"awsRDSQueriesExecuted\" | \"awsRDSActiveTransactions\" | \"awsRDSLatency\" | \"awsSQSMessagesVisible\" | \"awsSQSMessagesDelayed\" | \"awsSQSMessagesSent\" | \"awsSQSMessagesEmpty\" | \"awsSQSOldestMessage\" | \"custom\""
}
```

### How to Test
- Start a local Kibana instance pointing to an oblt cluster.
- Navigate to `Infrastructure`.
- Try different asset types and navigate to the Node Details view.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2023-09-28 12:39:04 +02:00

121 lines
3.7 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { first, last } from 'lodash';
import { InfraTimerangeInput } from '@kbn/infra-plugin/common/http_api/snapshot_api';
import { InventoryMetric } from '@kbn/infra-plugin/common/inventory_models/types';
import { NodeDetailsMetricDataResponse } from '@kbn/infra-plugin/common/http_api/node_details_api';
import { FtrProviderContext } from '../../ftr_provider_context';
import { DATES } from './constants';
const { min, max } = DATES['8.0.0'].pods_only;
interface NodeDetailsRequest {
metrics: InventoryMetric[];
nodeId: string;
nodeType: string;
sourceId: string;
timerange: InfraTimerangeInput;
cloudId?: string;
}
export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
describe('metrics', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/pods_only'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/pods_only'));
const fetchNodeDetails = async (
body: NodeDetailsRequest
): Promise<NodeDetailsMetricDataResponse | undefined> => {
const response = await supertest
.post('/api/metrics/node_details')
.set('kbn-xsrf', 'xxx')
.send(body)
.expect(200);
return response.body;
};
it('should basically work', async () => {
const data = fetchNodeDetails({
sourceId: 'default',
metrics: ['podCpuUsage'],
timerange: {
to: max,
from: min,
interval: '>=1m',
},
nodeId: '7d6d7955-f853-42b1-8613-11f52d0d2725',
nodeType: 'pod',
});
return data.then((resp) => {
if (!resp) {
return;
}
expect(resp.metrics.length).to.equal(1);
const metric = first(resp.metrics) as any;
expect(metric).to.have.property('id', 'podCpuUsage');
expect(metric).to.have.property('series');
const series = first(metric.series) as any;
expect(series).to.have.property('id', 'cpu');
expect(series).to.have.property('data');
const datapoint = last(series.data) as any;
expect(datapoint).to.have.property('timestamp', 1642698890000);
expect(datapoint).to.have.property('value', 0.544);
});
});
it('should support multiple metrics', async () => {
const data = fetchNodeDetails({
sourceId: 'default',
metrics: ['podCpuUsage', 'podMemoryUsage'],
timerange: {
to: max,
from: min,
interval: '>=1m',
},
nodeId: '7d6d7955-f853-42b1-8613-11f52d0d2725',
nodeType: 'pod',
});
return data.then((resp) => {
if (!resp) {
return;
}
expect(resp.metrics.length).to.equal(2);
});
});
it('should return multiple values for podOverview metric', () => {
const data = fetchNodeDetails({
sourceId: 'default',
metrics: ['podOverview'],
timerange: {
to: max,
from: min,
interval: '>=1m',
},
nodeId: '7d6d7955-f853-42b1-8613-11f52d0d2725',
nodeType: 'pod',
});
return data.then((resp) => {
if (!resp) {
return;
}
const podOverviewMetric = resp.metrics.find((metric) => metric.id === 'podOverview');
expect(podOverviewMetric?.series.length).to.be.greaterThan(1);
});
});
});
}