mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Infra] Replace MetricsUIAggregation
in favor of estypes.AggregationsAggregate
(#190495)
Closes [#190311](https://github.com/elastic/kibana/issues/190311) ## Summary This PR replaces `MetricsUIAggregation` in favor of `estypes.AggregationsAggregate`. Now the `MetricsUIAggregation` uses estypes.AggregationsAggregate and the `MetricsUIAggregationRT `is removed which also allows us to remove the `ESAggregationRT`. Instead of maintaining the runtime types we now rely on the types provided by elasticsearch. A follow-up issue will be linked here to address the other aggregation types related changes: [#190497](https://github.com/elastic/kibana/issues/190497) ## Testing - Check the types - Host page should load with no errors - To test if the API works use the request provided in the [x-pack/plugins/observability_solution/infra/server/routes/infra/README.md](https://github.com/elastic/kibana/compare/main...jennypavlova:kibana:190311-infra-replace-metricsuiaggregation-in-favor-of-estypesaggregationsaggregate?expand=1#diff-e853fdd3f4073eff8ff8a4df6a657f8cb5fefaa231be0116fe3692ae929f26a8) - if the body is not valid 400 is returned --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
fdae1348df
commit
22031dfb05
29 changed files with 95 additions and 306 deletions
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import * as rt from 'io-ts';
|
||||
import { MetricsAPISeriesRT, MetricsAPIRow } from '../metrics_api';
|
||||
import { MetricsAPISeriesRT, type MetricsAPIRow } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
const AggValueRT = rt.type({
|
||||
value: rt.number,
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
export * from './metadata_api';
|
||||
export * from './metrics_explorer';
|
||||
export * from './metrics_api';
|
||||
export * from './snapshot_api';
|
||||
export * from './host_details';
|
||||
export * from './infra';
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* 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 { createLiteralValueFromUndefinedRT } from '@kbn/io-ts-utils';
|
||||
import * as rt from 'io-ts';
|
||||
import { MetricsUIAggregationRT } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { afterKeyObjectRT, timeRangeRT } from './metrics_explorer';
|
||||
|
||||
const groupByRT = rt.union([rt.string, rt.null, rt.undefined]);
|
||||
|
||||
export const MetricsAPIMetricRT = rt.type({
|
||||
id: rt.string,
|
||||
aggregations: MetricsUIAggregationRT,
|
||||
});
|
||||
|
||||
export const MetricsAPIRequestRT = rt.intersection([
|
||||
rt.type({
|
||||
timerange: timeRangeRT,
|
||||
indexPattern: rt.string,
|
||||
metrics: rt.array(MetricsAPIMetricRT),
|
||||
includeTimeseries: rt.union([rt.boolean, createLiteralValueFromUndefinedRT(true)]),
|
||||
}),
|
||||
rt.partial({
|
||||
groupBy: rt.array(groupByRT),
|
||||
modules: rt.array(rt.string),
|
||||
afterKey: rt.union([rt.null, afterKeyObjectRT]),
|
||||
limit: rt.union([rt.number, rt.null]),
|
||||
filters: rt.array(rt.UnknownRecord),
|
||||
dropPartialBuckets: rt.boolean,
|
||||
alignDataToEnd: rt.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const MetricsAPIPageInfoRT = rt.intersection([
|
||||
rt.type({
|
||||
afterKey: rt.union([rt.null, afterKeyObjectRT, rt.undefined]),
|
||||
}),
|
||||
rt.partial({ interval: rt.number }),
|
||||
]);
|
||||
|
||||
export const MetricsAPIColumnTypeRT = rt.keyof({
|
||||
date: null,
|
||||
number: null,
|
||||
string: null,
|
||||
});
|
||||
|
||||
export const MetricsAPIColumnRT = rt.type({
|
||||
name: rt.string,
|
||||
type: MetricsAPIColumnTypeRT,
|
||||
});
|
||||
|
||||
export const MetricsAPIRowRT = rt.intersection([
|
||||
rt.type({
|
||||
timestamp: rt.number,
|
||||
}),
|
||||
rt.record(
|
||||
rt.string,
|
||||
rt.union([rt.string, rt.number, rt.null, rt.undefined, rt.array(rt.object)])
|
||||
),
|
||||
]);
|
||||
|
||||
export const MetricsAPISeriesRT = rt.intersection([
|
||||
rt.type({
|
||||
id: rt.string,
|
||||
columns: rt.array(MetricsAPIColumnRT),
|
||||
rows: rt.array(MetricsAPIRowRT),
|
||||
}),
|
||||
rt.partial({
|
||||
keys: rt.array(rt.string),
|
||||
}),
|
||||
]);
|
||||
|
||||
export const MetricsAPIResponseSeriesRT = rt.intersection([
|
||||
MetricsAPISeriesRT,
|
||||
rt.partial({ metricsets: rt.array(rt.string) }),
|
||||
]);
|
||||
|
||||
export const MetricsAPIResponseRT = rt.type({
|
||||
series: rt.array(MetricsAPIResponseSeriesRT),
|
||||
info: MetricsAPIPageInfoRT,
|
||||
});
|
||||
|
||||
export type MetricsAPITimerange = rt.TypeOf<typeof timeRangeRT>;
|
||||
|
||||
export type MetricsAPIColumnType = rt.TypeOf<typeof MetricsAPIColumnTypeRT>;
|
||||
|
||||
export type MetricsAPIMetric = rt.TypeOf<typeof MetricsAPIMetricRT>;
|
||||
|
||||
export type MetricsAPIPageInfo = rt.TypeOf<typeof MetricsAPIPageInfoRT>;
|
||||
|
||||
export type MetricsAPIColumn = rt.TypeOf<typeof MetricsAPIColumnRT>;
|
||||
|
||||
export type MetricsAPIRow = rt.TypeOf<typeof MetricsAPIRowRT>;
|
||||
|
||||
export type MetricsAPISeries = rt.TypeOf<typeof MetricsAPISeriesRT>;
|
||||
|
||||
export type MetricsAPIRequest = rt.TypeOf<typeof MetricsAPIRequestRT>;
|
||||
|
||||
export type MetricsAPIResponse = rt.TypeOf<typeof MetricsAPIResponseRT>;
|
|
@ -8,7 +8,7 @@
|
|||
import { createLiteralValueFromUndefinedRT } from '@kbn/io-ts-utils';
|
||||
import * as rt from 'io-ts';
|
||||
import { SnapshotMetricTypeRT, ItemTypeRT } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { MetricsAPISeriesRT } from './metrics_api';
|
||||
import { MetricsAPISeriesRT } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
export const SnapshotNodePathRT = rt.intersection([
|
||||
rt.type({
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
initGetLogAnalysisIdFormatsRoute,
|
||||
} from './routes/log_analysis';
|
||||
import { initMetadataRoute } from './routes/metadata';
|
||||
import { initMetricsAPIRoute } from './routes/metrics_api';
|
||||
import { initMetricsSourceConfigurationRoutes } from './routes/metrics_sources';
|
||||
import { initNodeDetailsRoute } from './routes/node_details';
|
||||
import { initOverviewRoute } from './routes/overview';
|
||||
|
@ -54,7 +53,6 @@ export const registerRoutes = (libs: InfraBackendLibs) => {
|
|||
initValidateLogAnalysisIndicesRoute(libs);
|
||||
initGetLogEntryExamplesRoute(libs);
|
||||
initMetricsExplorerViewRoutes(libs);
|
||||
initMetricsAPIRoute(libs);
|
||||
initMetadataRoute(libs);
|
||||
initInventoryMetaRoute(libs);
|
||||
initInventoryViewRoutes(libs);
|
||||
|
|
|
@ -8,16 +8,15 @@
|
|||
import { has } from 'lodash';
|
||||
import {
|
||||
MetricsUIAggregation,
|
||||
MetricsUIAggregationRT,
|
||||
ESSumBucketAggRT,
|
||||
ESTermsWithAggregationRT,
|
||||
ESDerivativeAggRT,
|
||||
ESBasicMetricAggRT,
|
||||
ESTermsWithAggregationRT,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import { SnapshotCustomMetricInput } from '../../../../../common/http_api';
|
||||
|
||||
export const isMetricRate = (metric: MetricsUIAggregation | undefined): boolean => {
|
||||
if (!MetricsUIAggregationRT.is(metric)) {
|
||||
if (!metric) {
|
||||
return false;
|
||||
}
|
||||
const values = Object.values(metric);
|
||||
|
@ -32,7 +31,7 @@ export const isCustomMetricRate = (customMetric: SnapshotCustomMetricInput) => {
|
|||
};
|
||||
|
||||
export const isInterfaceRateAgg = (metric: MetricsUIAggregation | undefined) => {
|
||||
if (!MetricsUIAggregationRT.is(metric)) {
|
||||
if (!metric) {
|
||||
return false;
|
||||
}
|
||||
const values = Object.values(metric);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
|
||||
import { decodeOrThrow } from '@kbn/io-ts-utils';
|
||||
import type { MetricsAPIResponse, MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { TIMESTAMP_FIELD } from '../../../common/constants';
|
||||
import { MetricsAPIRequest, MetricsAPIResponse } from '../../../common/http_api';
|
||||
import {
|
||||
ESSearchClient,
|
||||
CompositeResponseRT,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { MetricsAPITimerange } from '../../../../../common/http_api';
|
||||
import type { MetricsAPITimerange } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { calculateAuto } from './calculate_auto';
|
||||
import {
|
||||
getUnitValue,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MetricsAPITimerange } from '../../../../common/http_api';
|
||||
import type { MetricsAPITimerange } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { calculateBucketSize } from './calculate_bucket_size';
|
||||
|
||||
export const calculateDateHistogramOffset = (timerange: MetricsAPITimerange): string => {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
import { isArray, isNumber } from 'lodash';
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api';
|
||||
import { ESSearchClient } from '../types';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
|
||||
import type { ESSearchClient } from '../types';
|
||||
|
||||
export const calculatedInterval = async (search: ESSearchClient, options: MetricsAPIRequest) => {
|
||||
const useModuleInterval =
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api';
|
||||
import moment from 'moment';
|
||||
import { convertBucketsToMetricsApiSeries } from './convert_buckets_to_metrics_series';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
const keys = ['example-0'];
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
import { get, values, first } from 'lodash';
|
||||
import * as rt from 'io-ts';
|
||||
import {
|
||||
import type {
|
||||
MetricsAPIRequest,
|
||||
MetricsAPISeries,
|
||||
MetricsAPIColumn,
|
||||
MetricsAPIRow,
|
||||
} from '../../../../common/http_api/metrics_api';
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
Bucket,
|
||||
BasicMetricValueRT,
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { createAggregations, createCompositeAggregations } from './create_aggregations';
|
||||
import moment from 'moment';
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api';
|
||||
|
||||
const options: MetricsAPIRequest = {
|
||||
timerange: {
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
import { AggregationOptionsByType } from '@kbn/es-types';
|
||||
|
||||
import Boom from '@hapi/boom';
|
||||
import { type MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { afterKeyObjectRT } from '../../../../common/http_api';
|
||||
import { TIMESTAMP_FIELD } from '../../../../common/constants';
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api/metrics_api';
|
||||
import { calculateDateHistogramOffset } from './calculate_date_histogram_offset';
|
||||
import { createMetricsAggregations } from './create_metrics_aggregations';
|
||||
import { calculateBucketSize } from './calculate_bucket_size';
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api';
|
||||
import moment from 'moment';
|
||||
import { createMetricsAggregations } from './create_metrics_aggregations';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
const options: MetricsAPIRequest = {
|
||||
timerange: {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MetricsUIAggregation } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { MetricsAPIRequest } from '../../../../common/http_api/metrics_api';
|
||||
import type { MetricsUIAggregation } from '@kbn/metrics-data-access-plugin/common';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
export const createMetricsAggregations = (options: MetricsAPIRequest): MetricsUIAggregation => {
|
||||
const { metrics } = options;
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* 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 Boom from '@hapi/boom';
|
||||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import { fold } from 'fp-ts/lib/Either';
|
||||
import { identity } from 'fp-ts/lib/function';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { throwErrors } from '@kbn/io-ts-utils';
|
||||
import { InfraBackendLibs } from '../../lib/infra_types';
|
||||
import { createSearchClient } from '../../lib/create_search_client';
|
||||
import { query } from '../../lib/metrics';
|
||||
import { MetricsAPIRequestRT, MetricsAPIResponseRT } from '../../../common/http_api';
|
||||
|
||||
const escapeHatch = schema.object({}, { unknowns: 'allow' });
|
||||
|
||||
export const initMetricsAPIRoute = (libs: InfraBackendLibs) => {
|
||||
const { framework } = libs;
|
||||
framework.registerRoute(
|
||||
{
|
||||
method: 'post',
|
||||
path: '/api/infra/metrics_api',
|
||||
validate: {
|
||||
body: escapeHatch,
|
||||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
const options = pipe(
|
||||
MetricsAPIRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
);
|
||||
|
||||
const client = createSearchClient(requestContext, framework);
|
||||
const metricsApiResponse = await query(client, options);
|
||||
|
||||
return response.ok({
|
||||
body: MetricsAPIResponseRT.encode(metricsApiResponse),
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
|
@ -6,14 +6,12 @@
|
|||
*/
|
||||
|
||||
import { get, last, first, isArray } from 'lodash';
|
||||
import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
SnapshotRequest,
|
||||
SnapshotNodePath,
|
||||
SnapshotNode,
|
||||
MetricsAPISeries,
|
||||
MetricsAPIRow,
|
||||
} from '../../../../common/http_api';
|
||||
type MetricsAPIRow,
|
||||
type MetricsAPISeries,
|
||||
findInventoryFields,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import { SnapshotRequest, SnapshotNodePath, SnapshotNode } from '../../../../common/http_api';
|
||||
import { META_KEY } from './constants';
|
||||
|
||||
export const isIPv4 = (subject: string) => /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(subject);
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
*/
|
||||
|
||||
import { uniq } from 'lodash';
|
||||
import { MetricsUIAggregation, ESBasicMetricAggRT } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { MetricsAPITimerange } from '../../../../common/http_api';
|
||||
import {
|
||||
type MetricsUIAggregation,
|
||||
ESBasicMetricAggRT,
|
||||
type MetricsAPITimerange,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import { ESSearchClient } from '../../../lib/metrics/types';
|
||||
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
|
||||
import { getMetricsAggregations, InfraSnapshotRequestOptions } from './get_metrics_aggregations';
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import {
|
||||
import type {
|
||||
InventoryItemType,
|
||||
MetricsUIAggregation,
|
||||
MetricsUIAggregationRT,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import { findInventoryModel } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { networkTraffic } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
@ -54,7 +53,7 @@ export const getMetricsAggregations = (
|
|||
const { metrics } = options;
|
||||
return metrics.reduce((aggs, metric, index) => {
|
||||
const aggregation = metricToAggregation(options.nodeType, metric, index);
|
||||
if (!MetricsUIAggregationRT.is(aggregation)) {
|
||||
if (!aggregation) {
|
||||
throw new Error(
|
||||
i18n.translate('xpack.infra.snapshot.missingSnapshotMetricError', {
|
||||
defaultMessage: 'The aggregation for {metric} for {nodeType} is not available.',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MetricsAPIRequest, MetricsAPIResponse } from '../../../../common/http_api';
|
||||
import type { MetricsAPIResponse, MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
import { ESSearchClient } from '../../../lib/metrics/types';
|
||||
import { query } from '../../../lib/metrics';
|
||||
|
||||
|
|
|
@ -5,13 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
InfraTimerangeInput,
|
||||
MetricsAPIRequest,
|
||||
SnapshotRequest,
|
||||
} from '../../../../common/http_api';
|
||||
import type { InfraTimerangeInput, SnapshotRequest } from '../../../../common/http_api';
|
||||
import moment from 'moment';
|
||||
import { transformMetricsApiResponseToSnapshotResponse } from './transform_metrics_ui_response';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
jest.mock('./apply_metadata_to_last_path', () => ({
|
||||
applyMetadataToLastPath: (series: any) => [{ label: series.id }],
|
||||
|
|
|
@ -6,15 +6,17 @@
|
|||
*/
|
||||
|
||||
import { get, max, sum, last, isNumber } from 'lodash';
|
||||
import { SnapshotMetricType } from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
MetricsAPIResponse,
|
||||
SnapshotNodeResponse,
|
||||
import type {
|
||||
MetricsAPIRequest,
|
||||
MetricsAPIResponse,
|
||||
MetricsAPIRow,
|
||||
MetricsAPISeries,
|
||||
SnapshotMetricType,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
SnapshotNodeResponse,
|
||||
SnapshotRequest,
|
||||
SnapshotNode,
|
||||
MetricsAPISeries,
|
||||
SnapshotNodeMetric,
|
||||
} from '../../../../common/http_api';
|
||||
import { META_KEY } from './constants';
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
import { transformRequestToMetricsAPIRequest } from './transform_request_to_metrics_api_request';
|
||||
import { ESSearchClient } from '../../../lib/metrics/types';
|
||||
import { InfraSource } from '../../../lib/sources';
|
||||
import { MetricsAPIRequest, SnapshotRequest } from '../../../../common/http_api';
|
||||
import type { SnapshotRequest } from '../../../../common/http_api';
|
||||
import type { MetricsAPIRequest } from '@kbn/metrics-data-access-plugin/common';
|
||||
|
||||
jest.mock('./create_timerange_with_interval', () => {
|
||||
return {
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { findInventoryFields, findInventoryModel } from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
type MetricsAPIMetric,
|
||||
type MetricsAPIRequest,
|
||||
findInventoryFields,
|
||||
findInventoryModel,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import { TIMESTAMP_FIELD } from '../../../../common/constants';
|
||||
import { MetricsAPIMetric, MetricsAPIRequest, SnapshotRequest } from '../../../../common/http_api';
|
||||
import { SnapshotRequest } from '../../../../common/http_api';
|
||||
import { ESSearchClient } from '../../../lib/metrics/types';
|
||||
import { InfraSource } from '../../../lib/sources';
|
||||
import { createTimeRangeWithInterval } from './create_timerange_with_interval';
|
||||
|
|
|
@ -6,16 +6,9 @@
|
|||
*/
|
||||
|
||||
import { identity } from 'lodash';
|
||||
import {
|
||||
MetricsUIAggregationRT,
|
||||
networkTraffic,
|
||||
findInventoryModel,
|
||||
} from '@kbn/metrics-data-access-plugin/common';
|
||||
import {
|
||||
MetricsAPIMetric,
|
||||
SnapshotRequest,
|
||||
SnapshotCustomMetricInputRT,
|
||||
} from '../../../../common/http_api';
|
||||
import { networkTraffic, findInventoryModel } from '@kbn/metrics-data-access-plugin/common';
|
||||
import type { MetricsAPIMetric } from '@kbn/metrics-data-access-plugin/common/http_api/metrics_api';
|
||||
import { type SnapshotRequest, SnapshotCustomMetricInputRT } from '../../../../common/http_api';
|
||||
|
||||
export const transformSnapshotMetricsToMetricsAPIMetrics = (
|
||||
snapshotRequest: SnapshotRequest
|
||||
|
@ -24,9 +17,6 @@ export const transformSnapshotMetricsToMetricsAPIMetrics = (
|
|||
.map((metric, index) => {
|
||||
const inventoryModel = findInventoryModel(snapshotRequest.nodeType);
|
||||
const aggregations = inventoryModel.metrics.snapshot?.[metric.type];
|
||||
if (MetricsUIAggregationRT.is(aggregations)) {
|
||||
return { id: metric.type, aggregations };
|
||||
}
|
||||
if (SnapshotCustomMetricInputRT.is(metric)) {
|
||||
const isUniqueId = snapshotRequest.metrics.findIndex((m) =>
|
||||
SnapshotCustomMetricInputRT.is(m) ? m.id === metric.id : false
|
||||
|
@ -46,7 +36,7 @@ export const transformSnapshotMetricsToMetricsAPIMetrics = (
|
|||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
return { id: metric.type, aggregations };
|
||||
})
|
||||
.filter(identity) as MetricsAPIMetric[];
|
||||
};
|
||||
|
|
|
@ -5,16 +5,21 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { createLiteralValueFromUndefinedRT } from '@kbn/io-ts-utils';
|
||||
import * as rt from 'io-ts';
|
||||
import { MetricsUIAggregationRT } from '../inventory_models/types';
|
||||
import { createLiteralValueFromUndefinedRT } from '@kbn/io-ts-utils';
|
||||
import { afterKeyObjectRT, timeRangeRT } from './metrics_explorer';
|
||||
import { MetricsUIAggregation } from '../inventory_models/types';
|
||||
|
||||
export interface MetricsAPIMetric {
|
||||
id: string;
|
||||
aggregations: MetricsUIAggregation;
|
||||
}
|
||||
|
||||
const groupByRT = rt.union([rt.string, rt.null, rt.undefined]);
|
||||
|
||||
export const MetricsAPIMetricRT = rt.type({
|
||||
id: rt.string,
|
||||
aggregations: MetricsUIAggregationRT,
|
||||
aggregations: rt.UnknownRecord,
|
||||
});
|
||||
|
||||
export const MetricsAPIRequestRT = rt.intersection([
|
||||
|
@ -85,12 +90,14 @@ export const MetricsAPIResponseRT = rt.type({
|
|||
info: MetricsAPIPageInfoRT,
|
||||
});
|
||||
|
||||
export type MetricsAPIRequest = Omit<rt.OutputOf<typeof MetricsAPIRequestRT>, 'metrics'> & {
|
||||
metrics: MetricsAPIMetric[];
|
||||
};
|
||||
|
||||
export type MetricsAPITimerange = rt.TypeOf<typeof timeRangeRT>;
|
||||
|
||||
export type MetricsAPIColumnType = rt.TypeOf<typeof MetricsAPIColumnTypeRT>;
|
||||
|
||||
export type MetricsAPIMetric = rt.TypeOf<typeof MetricsAPIMetricRT>;
|
||||
|
||||
export type MetricsAPIPageInfo = rt.TypeOf<typeof MetricsAPIPageInfoRT>;
|
||||
|
||||
export type MetricsAPIColumn = rt.TypeOf<typeof MetricsAPIColumnRT>;
|
||||
|
@ -99,6 +106,4 @@ export type MetricsAPIRow = rt.TypeOf<typeof MetricsAPIRowRT>;
|
|||
|
||||
export type MetricsAPISeries = rt.TypeOf<typeof MetricsAPISeriesRT>;
|
||||
|
||||
export type MetricsAPIRequest = rt.TypeOf<typeof MetricsAPIRequestRT>;
|
||||
|
||||
export type MetricsAPIResponse = rt.TypeOf<typeof MetricsAPIResponseRT>;
|
||||
|
|
|
@ -29,11 +29,10 @@ export {
|
|||
ItemTypeRT,
|
||||
SnapshotMetricTypeRT,
|
||||
ESSumBucketAggRT,
|
||||
ESTermsWithAggregationRT,
|
||||
ESDerivativeAggRT,
|
||||
MetricsUIAggregationRT,
|
||||
ESBasicMetricAggRT,
|
||||
SnapshotMetricTypeKeys,
|
||||
ESTermsWithAggregationRT,
|
||||
} from './inventory_models/types';
|
||||
|
||||
export type {
|
||||
|
@ -49,3 +48,26 @@ export type {
|
|||
|
||||
export { networkTraffic } from './inventory_models/shared/metrics/snapshot/network_traffic';
|
||||
export { METRICS_EXPLORER_API_MAX_METRICS } from './constants';
|
||||
|
||||
export {
|
||||
MetricsAPIMetricRT,
|
||||
MetricsAPIRequestRT,
|
||||
MetricsAPIPageInfoRT,
|
||||
MetricsAPIColumnTypeRT,
|
||||
MetricsAPIColumnRT,
|
||||
MetricsAPIRowRT,
|
||||
MetricsAPISeriesRT,
|
||||
MetricsAPIResponseSeriesRT,
|
||||
MetricsAPIResponseRT,
|
||||
} from './http_api';
|
||||
export type {
|
||||
MetricsAPIMetric,
|
||||
MetricsAPIRequest,
|
||||
MetricsAPITimerange,
|
||||
MetricsAPIColumnType,
|
||||
MetricsAPIPageInfo,
|
||||
MetricsAPIColumn,
|
||||
MetricsAPIRow,
|
||||
MetricsAPISeries,
|
||||
MetricsAPIResponse,
|
||||
} from './http_api';
|
||||
|
|
|
@ -11,6 +11,7 @@ import type {
|
|||
LensConfig,
|
||||
} from '@kbn/lens-embeddable-utils/config_builder';
|
||||
import * as rt from 'io-ts';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
|
||||
export const ItemTypeRT = rt.keyof({
|
||||
host: null,
|
||||
|
@ -244,38 +245,6 @@ export const ESBasicMetricAggRT = rt.record(
|
|||
])
|
||||
);
|
||||
|
||||
export const ESPercentileAggRT = rt.type({
|
||||
percentiles: rt.type({
|
||||
field: rt.string,
|
||||
percents: rt.array(rt.number),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ESCaridnalityAggRT = rt.type({
|
||||
cardinality: rt.partial({
|
||||
field: rt.string,
|
||||
}),
|
||||
});
|
||||
|
||||
export const ESBucketScriptAggRT = rt.type({
|
||||
bucket_script: rt.intersection([
|
||||
rt.type({
|
||||
buckets_path: rt.record(rt.string, rt.string),
|
||||
script: rt.type({
|
||||
source: rt.string,
|
||||
lang: rt.keyof({ painless: null, expression: null }),
|
||||
}),
|
||||
}),
|
||||
rt.partial({ gap_policy: rt.keyof({ skip: null, insert_zeros: null }) }),
|
||||
]),
|
||||
});
|
||||
|
||||
export const ESCumulativeSumAggRT = rt.type({
|
||||
cumulative_sum: rt.type({
|
||||
buckets_path: rt.string,
|
||||
}),
|
||||
});
|
||||
|
||||
export const ESDerivativeAggRT = rt.type({
|
||||
derivative: rt.type({
|
||||
buckets_path: rt.string,
|
||||
|
@ -290,63 +259,13 @@ export const ESSumBucketAggRT = rt.type({
|
|||
}),
|
||||
});
|
||||
|
||||
export const ESTopMetricsAggRT = rt.type({
|
||||
top_metrics: rt.intersection([
|
||||
rt.type({
|
||||
metrics: rt.union([rt.array(rt.type({ field: rt.string })), rt.type({ field: rt.string })]),
|
||||
}),
|
||||
rt.partial({
|
||||
size: rt.number,
|
||||
sort: rt.record(rt.string, rt.union([rt.literal('desc'), rt.literal('asc')])),
|
||||
}),
|
||||
]),
|
||||
export type MetricsUIAggregation = Record<string, estypes.AggregationsAggregate>;
|
||||
|
||||
export const ESTermsWithAggregationRT = rt.type({
|
||||
terms: rt.type({ field: rt.string }),
|
||||
aggregations: rt.UnknownRecord,
|
||||
});
|
||||
|
||||
export const ESMaxPeriodFilterExistsAggRT = rt.type({
|
||||
filter: rt.type({
|
||||
exists: rt.type({
|
||||
field: rt.string,
|
||||
}),
|
||||
}),
|
||||
aggs: rt.type({
|
||||
period: rt.type({
|
||||
max: rt.type({
|
||||
field: rt.string,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export interface SnapshotTermsWithAggregation {
|
||||
terms: { field: string };
|
||||
aggregations: MetricsUIAggregation;
|
||||
}
|
||||
|
||||
export const ESTermsWithAggregationRT: rt.Type<SnapshotTermsWithAggregation> = rt.recursion(
|
||||
'SnapshotModelRT',
|
||||
() =>
|
||||
rt.type({
|
||||
terms: rt.type({ field: rt.string }),
|
||||
aggregations: MetricsUIAggregationRT,
|
||||
})
|
||||
);
|
||||
|
||||
export const ESAggregationRT = rt.union([
|
||||
ESBasicMetricAggRT,
|
||||
ESPercentileAggRT,
|
||||
ESBucketScriptAggRT,
|
||||
ESCumulativeSumAggRT,
|
||||
ESDerivativeAggRT,
|
||||
ESSumBucketAggRT,
|
||||
ESTermsWithAggregationRT,
|
||||
ESCaridnalityAggRT,
|
||||
ESTopMetricsAggRT,
|
||||
ESMaxPeriodFilterExistsAggRT,
|
||||
]);
|
||||
|
||||
export const MetricsUIAggregationRT = rt.record(rt.string, ESAggregationRT);
|
||||
export type MetricsUIAggregation = rt.TypeOf<typeof MetricsUIAggregationRT>;
|
||||
|
||||
export const SnapshotMetricTypeKeys = {
|
||||
count: null,
|
||||
cpuV2: null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue