kibana/x-pack/plugins/infra/public/metrics_overview_fetchers.ts
Chris Cowan 91b727f412
[Metrics UI] Observability Overview Host Summary (#90879)
* [Metrics UI] Observability Overview Host Summary

* Adding UI elements

* Adding logos

* Changing the size of the request

* Change to new ECS fields for network traffic

* Adding logos to HostLink component

* Round seconds

* fixing data handler test

* Fixing test for metrics_overview_fetchers

* Adding types for SVG to observability

* Adding i18n support to table labels

* removing unused translations

* move back to host.network.(in,out).bytes

* Adding changes to source from #95334

* Fixing source type

* Removing unintentional change.

* Maybe, fixing types

* removing svg typings

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-04-06 08:38:12 -07:00

61 lines
2.1 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.
*/
/*
* Copyright
* 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 { FetchDataParams, MetricsFetchDataResponse } from '../../observability/public';
import { TopNodesRequest, TopNodesResponse } from '../common/http_api/overview_api';
import { InfraClientCoreSetup } from './types';
export const createMetricsHasData = (
getStartServices: InfraClientCoreSetup['getStartServices']
) => async () => {
const [coreServices] = await getStartServices();
const { http } = coreServices;
const results = await http.get<{ hasData: boolean }>('/api/metrics/source/default/hasData');
return results.hasData;
};
export const createMetricsFetchData = (
getStartServices: InfraClientCoreSetup['getStartServices']
) => async ({ absoluteTime, bucketSize }: FetchDataParams): Promise<MetricsFetchDataResponse> => {
const [coreServices] = await getStartServices();
const { http } = coreServices;
const makeRequest = async (overrides: Partial<TopNodesRequest> = {}) => {
const { start, end } = absoluteTime;
const overviewRequest: TopNodesRequest = {
sourceId: 'default',
bucketSize,
size: 5,
timerange: {
from: start,
to: end,
},
...overrides,
};
const results = await http.post<TopNodesResponse>('/api/metrics/overview/top', {
body: JSON.stringify(overviewRequest),
});
return {
appLink: `/app/metrics/inventory?waffleTime=(currentTime:${end},isAutoReloading:!f)`,
series: results.series,
sort: async (by: string, direction: string) =>
makeRequest({ sort: by, sortDirection: direction }),
};
};
return await makeRequest();
};