Remove graphql types (#54176)

* Fix server types

* Remove graphql types from the frontend

* More type cleanup

* Replace more types. Delete unused files

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Phillip Burch 2020-01-09 17:09:57 -06:00 committed by GitHub
parent 6826368842
commit 32e61592ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 336 additions and 476 deletions

View file

@ -50,6 +50,6 @@ export const NodeDetailsRequestRT = rt.intersection([
]);
// export type NodeDetailsRequest = InfraWrappableRequest<NodesArgs & SourceArgs>;
export type NodeDetailsMetricData = rt.TypeOf<typeof NodeDetailsMetricDataRT>;
export type NodeDetailsRequest = rt.TypeOf<typeof NodeDetailsRequestRT>;
export type NodeDetailsMetricDataResponse = rt.TypeOf<typeof NodeDetailsMetricDataResponseRT>;

View file

@ -19,7 +19,7 @@ export const SnapshotNodePathRT = rt.intersection([
const SnapshotNodeMetricOptionalRT = rt.partial({
value: rt.union([rt.number, rt.null]),
average: rt.union([rt.number, rt.null]),
avg: rt.union([rt.number, rt.null]),
max: rt.union([rt.number, rt.null]),
});
@ -27,8 +27,12 @@ const SnapshotNodeMetricRequiredRT = rt.type({
name: SnapshotMetricTypeRT,
});
export const SnapshotNodeMetricRT = rt.intersection([
SnapshotNodeMetricRequiredRT,
SnapshotNodeMetricOptionalRT,
]);
export const SnapshotNodeRT = rt.type({
metric: rt.intersection([SnapshotNodeMetricRequiredRT, SnapshotNodeMetricOptionalRT]),
metric: SnapshotNodeMetricRT,
path: rt.array(SnapshotNodePathRT),
});
@ -43,18 +47,24 @@ export const InfraTimerangeInputRT = rt.type({
from: rt.number,
});
export const SnapshotGroupByRT = rt.array(
rt.partial({
label: rt.union([rt.string, rt.null]),
field: rt.union([rt.string, rt.null]),
})
);
export const SnapshotMetricInputRT = rt.type({
type: SnapshotMetricTypeRT,
});
export const SnapshotRequestRT = rt.intersection([
rt.type({
timerange: InfraTimerangeInputRT,
metric: rt.type({
type: SnapshotMetricTypeRT,
}),
groupBy: rt.array(
rt.partial({
label: rt.union([rt.string, rt.null]),
field: rt.union([rt.string, rt.null]),
})
),
groupBy: SnapshotGroupByRT,
nodeType: ItemTypeRT,
sourceId: rt.string,
}),
@ -65,6 +75,11 @@ export const SnapshotRequestRT = rt.intersection([
}),
]);
export type SnapshotNodePath = rt.TypeOf<typeof SnapshotNodePathRT>;
export type SnapshotMetricInput = rt.TypeOf<typeof SnapshotMetricInputRT>;
export type InfraTimerangeInput = rt.TypeOf<typeof InfraTimerangeInputRT>;
export type SnapshotNodeMetric = rt.TypeOf<typeof SnapshotNodeMetricRT>;
export type SnapshotGroupBy = rt.TypeOf<typeof SnapshotGroupByRT>;
export type SnapshotRequest = rt.TypeOf<typeof SnapshotRequestRT>;
export type SnapshotNode = rt.TypeOf<typeof SnapshotNodeRT>;
export type SnapshotNodeResponse = rt.TypeOf<typeof SnapshotNodeResponseRT>;

View file

@ -7,16 +7,16 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { InfraSnapshotMetricType } from '../../graphql/types';
import { CloudToolbarItems } from '../shared/compontents/cloud_toolbar_items';
import { SnapshotMetricType } from '../types';
export const AwsEC2ToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.cpu,
InfraSnapshotMetricType.rx,
InfraSnapshotMetricType.tx,
InfraSnapshotMetricType.diskIOReadBytes,
InfraSnapshotMetricType.diskIOWriteBytes,
const metricTypes: SnapshotMetricType[] = [
'cpu',
'rx',
'tx',
'diskIOReadBytes',
'diskIOWriteBytes',
];
const groupByFields = [
'cloud.availability_zone',

View file

@ -6,17 +6,18 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { InfraSnapshotMetricType } from '../../../public/graphql/types';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { CloudToolbarItems } from '../shared/compontents/cloud_toolbar_items';
import { SnapshotMetricType } from '../types';
export const AwsRDSToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.cpu,
InfraSnapshotMetricType.rdsConnections,
InfraSnapshotMetricType.rdsQueriesExecuted,
InfraSnapshotMetricType.rdsActiveTransactions,
InfraSnapshotMetricType.rdsLatency,
const metricTypes: SnapshotMetricType[] = [
'cpu',
'rdsConnections',
'rdsQueriesExecuted',
'rdsActiveTransactions',
'rdsLatency',
];
const groupByFields = [
'cloud.availability_zone',

View file

@ -6,17 +6,17 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { InfraSnapshotMetricType } from '../../../public/graphql/types';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { CloudToolbarItems } from '../shared/compontents/cloud_toolbar_items';
import { SnapshotMetricType } from '../types';
export const AwsS3ToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.s3BucketSize,
InfraSnapshotMetricType.s3NumberOfObjects,
InfraSnapshotMetricType.s3TotalRequests,
InfraSnapshotMetricType.s3DownloadBytes,
InfraSnapshotMetricType.s3UploadBytes,
const metricTypes: SnapshotMetricType[] = [
's3BucketSize',
's3NumberOfObjects',
's3TotalRequests',
's3DownloadBytes',
's3UploadBytes',
];
const groupByFields = ['cloud.region'];
return (

View file

@ -7,16 +7,16 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { InfraSnapshotMetricType } from '../../graphql/types';
import { CloudToolbarItems } from '../shared/compontents/cloud_toolbar_items';
import { SnapshotMetricType } from '../types';
export const AwsSQSToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.sqsMessagesVisible,
InfraSnapshotMetricType.sqsMessagesDelayed,
InfraSnapshotMetricType.sqsMessagesSent,
InfraSnapshotMetricType.sqsMessagesEmpty,
InfraSnapshotMetricType.sqsOldestMessage,
const metricTypes: SnapshotMetricType[] = [
'sqsMessagesVisible',
'sqsMessagesDelayed',
'sqsMessagesSent',
'sqsMessagesEmpty',
'sqsOldestMessage',
];
const groupByFields = ['cloud.region'];
return (

View file

@ -7,15 +7,10 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { InfraSnapshotMetricType } from '../../graphql/types';
import { SnapshotMetricType } from '../types';
export const ContainerToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.cpu,
InfraSnapshotMetricType.memory,
InfraSnapshotMetricType.rx,
InfraSnapshotMetricType.tx,
];
const metricTypes: SnapshotMetricType[] = ['cpu', 'memory', 'rx', 'tx'];
const groupByFields = [
'host.name',
'cloud.availability_zone',

View file

@ -7,17 +7,10 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { InfraSnapshotMetricType } from '../../graphql/types';
import { SnapshotMetricType } from '../types';
export const HostToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.cpu,
InfraSnapshotMetricType.memory,
InfraSnapshotMetricType.load,
InfraSnapshotMetricType.rx,
InfraSnapshotMetricType.tx,
InfraSnapshotMetricType.logRate,
];
const metricTypes: SnapshotMetricType[] = ['cpu', 'memory', 'load', 'rx', 'tx', 'logRate'];
const groupByFields = [
'cloud.availability_zone',
'cloud.machine.type',

View file

@ -7,15 +7,10 @@
import React from 'react';
import { ToolbarProps } from '../../../public/components/inventory/toolbars/toolbar';
import { MetricsAndGroupByToolbarItems } from '../shared/compontents/metrics_and_groupby_toolbar_items';
import { InfraSnapshotMetricType } from '../../graphql/types';
import { SnapshotMetricType } from '../types';
export const PodToolbarItems = (props: ToolbarProps) => {
const metricTypes = [
InfraSnapshotMetricType.cpu,
InfraSnapshotMetricType.memory,
InfraSnapshotMetricType.rx,
InfraSnapshotMetricType.tx,
];
const metricTypes: SnapshotMetricType[] = ['cpu', 'memory', 'rx', 'tx'];
const groupByFields = ['kubernetes.namespace', 'kubernetes.node.name', 'service.type'];
return (
<MetricsAndGroupByToolbarItems

View file

@ -9,14 +9,14 @@ import { EuiFlexItem } from '@elastic/eui';
import { ToolbarProps } from '../../../../public/components/inventory/toolbars/toolbar';
import { WaffleMetricControls } from '../../../../public/components/waffle/waffle_metric_controls';
import { WaffleGroupByControls } from '../../../../public/components/waffle/waffle_group_by_controls';
import { InfraSnapshotMetricType } from '../../../../public/graphql/types';
import {
toGroupByOpt,
toMetricOpt,
} from '../../../../public/components/inventory/toolbars/toolbar_wrapper';
import { SnapshotMetricType } from '../../types';
interface Props extends ToolbarProps {
metricTypes: InfraSnapshotMetricType[];
metricTypes: SnapshotMetricType[];
groupByFields: string[];
}

View file

@ -6,11 +6,6 @@
import React from 'react';
import { InfraWaffleMapOptions, InfraWaffleMapBounds } from '../../lib/lib';
import {
InfraNodeType,
InfraSnapshotMetricInput,
InfraSnapshotGroupbyInput,
} from '../../graphql/types';
import { KueryFilterQuery } from '../../store/local/waffle_filter';
import { NodesOverview } from '../nodes_overview';
@ -18,10 +13,12 @@ import { Toolbar } from './toolbars/toolbar';
import { PageContent } from '../page';
import { useSnapshot } from '../../containers/waffle/use_snaphot';
import { useInventoryMeta } from '../../containers/inventory_metadata/use_inventory_meta';
import { SnapshotMetricInput, SnapshotGroupBy } from '../../../common/http_api/snapshot_api';
import { InventoryItemType } from '../../../common/inventory_models/types';
export interface LayoutProps {
options: InfraWaffleMapOptions;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
onDrilldown: (filter: KueryFilterQuery) => void;
currentTime: number;
onViewChange: (view: string) => void;
@ -30,8 +27,8 @@ export interface LayoutProps {
autoBounds: boolean;
filterQuery: string | null | undefined;
metric: InfraSnapshotMetricInput;
groupBy: InfraSnapshotGroupbyInput[];
metric: SnapshotMetricInput;
groupBy: SnapshotGroupBy;
sourceId: string;
accountId: string;
region: string;

View file

@ -7,13 +7,9 @@
import React, { FunctionComponent } from 'react';
import { Action } from 'typescript-fsa';
import { EuiFlexItem } from '@elastic/eui';
import { SnapshotMetricInput, SnapshotGroupBy } from '../../../../common/http_api/snapshot_api';
import { InventoryCloudAccount } from '../../../../common/http_api/inventory_meta_api';
import { findToolbar } from '../../../../common/inventory_models/toolbars';
import {
InfraNodeType,
InfraSnapshotMetricInput,
InfraSnapshotGroupbyInput,
} from '../../../graphql/types';
import { ToolbarWrapper } from './toolbar_wrapper';
import { waffleOptionsSelectors } from '../../../store';
@ -22,11 +18,12 @@ import { WithWaffleViewState } from '../../../containers/waffle/with_waffle_view
import { SavedViewsToolbarControls } from '../../saved_views/toolbar_control';
import { inventoryViewSavedObjectType } from '../../../../common/saved_objects/inventory_view';
import { IIndexPattern } from '../../../../../../../../src/plugins/data/public';
import { InventoryItemType } from '../../../../common/inventory_models/types';
export interface ToolbarProps {
createDerivedIndexPattern: (type: 'logs' | 'metrics' | 'both') => IIndexPattern;
changeMetric: (payload: InfraSnapshotMetricInput) => Action<InfraSnapshotMetricInput>;
changeGroupBy: (payload: InfraSnapshotGroupbyInput[]) => Action<InfraSnapshotGroupbyInput[]>;
changeMetric: (payload: SnapshotMetricInput) => Action<SnapshotMetricInput>;
changeGroupBy: (payload: SnapshotGroupBy) => Action<SnapshotGroupBy>;
changeCustomOptions: (payload: InfraGroupByOptions[]) => Action<InfraGroupByOptions[]>;
changeAccount: (id: string) => Action<string>;
changeRegion: (name: string) => Action<string>;
@ -70,7 +67,7 @@ const wrapToolbarItems = (
};
interface Props {
nodeType: InfraNodeType;
nodeType: InventoryItemType;
regions: string[];
accounts: InventoryCloudAccount[];
}

View file

@ -7,12 +7,12 @@
import React from 'react';
import { EuiFlexGroup } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { SnapshotMetricType } from '../../../../common/inventory_models/types';
import { WithSource } from '../../../containers/with_source';
import { WithWaffleOptions } from '../../../containers/waffle/with_waffle_options';
import { Toolbar } from '../../eui/toolbar';
import { ToolbarProps } from './toolbar';
import { fieldToName } from '../../waffle/lib/field_to_display_name';
import { InfraSnapshotMetricType } from '../../../graphql/types';
interface Props {
children: (props: Omit<ToolbarProps, 'accounts' | 'regions'>) => React.ReactElement;
@ -144,123 +144,125 @@ export const toGroupByOpt = (field: string) => ({
field,
});
export const toMetricOpt = (metric: InfraSnapshotMetricType) => {
export const toMetricOpt = (
metric: SnapshotMetricType
): { text: string; value: SnapshotMetricType } => {
switch (metric) {
case InfraSnapshotMetricType.cpu:
case 'cpu':
return {
text: ToolbarTranslations.CPUUsage,
value: InfraSnapshotMetricType.cpu,
value: 'cpu',
};
case InfraSnapshotMetricType.memory:
case 'memory':
return {
text: ToolbarTranslations.MemoryUsage,
value: InfraSnapshotMetricType.memory,
value: 'memory',
};
case InfraSnapshotMetricType.rx:
case 'rx':
return {
text: ToolbarTranslations.InboundTraffic,
value: InfraSnapshotMetricType.rx,
value: 'rx',
};
case InfraSnapshotMetricType.tx:
case 'tx':
return {
text: ToolbarTranslations.OutboundTraffic,
value: InfraSnapshotMetricType.tx,
value: 'tx',
};
case InfraSnapshotMetricType.logRate:
case 'logRate':
return {
text: ToolbarTranslations.LogRate,
value: InfraSnapshotMetricType.logRate,
value: 'logRate',
};
case InfraSnapshotMetricType.load:
case 'load':
return {
text: ToolbarTranslations.Load,
value: InfraSnapshotMetricType.load,
value: 'load',
};
case InfraSnapshotMetricType.count:
case 'count':
return {
text: ToolbarTranslations.Count,
value: InfraSnapshotMetricType.count,
value: 'count',
};
case InfraSnapshotMetricType.diskIOReadBytes:
case 'diskIOReadBytes':
return {
text: ToolbarTranslations.DiskIOReadBytes,
value: InfraSnapshotMetricType.diskIOReadBytes,
value: 'diskIOReadBytes',
};
case InfraSnapshotMetricType.diskIOWriteBytes:
case 'diskIOWriteBytes':
return {
text: ToolbarTranslations.DiskIOWriteBytes,
value: InfraSnapshotMetricType.diskIOWriteBytes,
value: 'diskIOWriteBytes',
};
case InfraSnapshotMetricType.s3BucketSize:
case 's3BucketSize':
return {
text: ToolbarTranslations.s3BucketSize,
value: InfraSnapshotMetricType.s3BucketSize,
value: 's3BucketSize',
};
case InfraSnapshotMetricType.s3TotalRequests:
case 's3TotalRequests':
return {
text: ToolbarTranslations.s3TotalRequests,
value: InfraSnapshotMetricType.s3TotalRequests,
value: 's3TotalRequests',
};
case InfraSnapshotMetricType.s3NumberOfObjects:
case 's3NumberOfObjects':
return {
text: ToolbarTranslations.s3NumberOfObjects,
value: InfraSnapshotMetricType.s3NumberOfObjects,
value: 's3NumberOfObjects',
};
case InfraSnapshotMetricType.s3DownloadBytes:
case 's3DownloadBytes':
return {
text: ToolbarTranslations.s3DownloadBytes,
value: InfraSnapshotMetricType.s3DownloadBytes,
value: 's3DownloadBytes',
};
case InfraSnapshotMetricType.s3UploadBytes:
case 's3UploadBytes':
return {
text: ToolbarTranslations.s3UploadBytes,
value: InfraSnapshotMetricType.s3UploadBytes,
value: 's3UploadBytes',
};
case InfraSnapshotMetricType.rdsConnections:
case 'rdsConnections':
return {
text: ToolbarTranslations.rdsConnections,
value: InfraSnapshotMetricType.rdsConnections,
value: 'rdsConnections',
};
case InfraSnapshotMetricType.rdsQueriesExecuted:
case 'rdsQueriesExecuted':
return {
text: ToolbarTranslations.rdsQueriesExecuted,
value: InfraSnapshotMetricType.rdsQueriesExecuted,
value: 'rdsQueriesExecuted',
};
case InfraSnapshotMetricType.rdsActiveTransactions:
case 'rdsActiveTransactions':
return {
text: ToolbarTranslations.rdsActiveTransactions,
value: InfraSnapshotMetricType.rdsActiveTransactions,
value: 'rdsActiveTransactions',
};
case InfraSnapshotMetricType.rdsLatency:
case 'rdsLatency':
return {
text: ToolbarTranslations.rdsLatency,
value: InfraSnapshotMetricType.rdsLatency,
value: 'rdsLatency',
};
case InfraSnapshotMetricType.sqsMessagesVisible:
case 'sqsMessagesVisible':
return {
text: ToolbarTranslations.sqsMessagesVisible,
value: InfraSnapshotMetricType.sqsMessagesVisible,
value: 'sqsMessagesVisible',
};
case InfraSnapshotMetricType.sqsMessagesDelayed:
case 'sqsMessagesDelayed':
return {
text: ToolbarTranslations.sqsMessagesDelayed,
value: InfraSnapshotMetricType.sqsMessagesDelayed,
value: 'sqsMessagesDelayed',
};
case InfraSnapshotMetricType.sqsMessagesSent:
case 'sqsMessagesSent':
return {
text: ToolbarTranslations.sqsMessagesSent,
value: InfraSnapshotMetricType.sqsMessagesSent,
value: 'sqsMessagesSent',
};
case InfraSnapshotMetricType.sqsMessagesEmpty:
case 'sqsMessagesEmpty':
return {
text: ToolbarTranslations.sqsMessagesEmpty,
value: InfraSnapshotMetricType.sqsMessagesEmpty,
value: 'sqsMessagesEmpty',
};
case InfraSnapshotMetricType.sqsOldestMessage:
case 'sqsOldestMessage':
return {
text: ToolbarTranslations.sqsOldestMessage,
value: InfraSnapshotMetricType.sqsOldestMessage,
value: 'sqsOldestMessage',
};
}
};

View file

@ -8,7 +8,6 @@ import React from 'react';
import { MetricsExplorerChartContextMenu, createNodeDetailLink } from './chart_context_menu';
import { mount } from 'enzyme';
import { options, source, timeRange, chartOptions } from '../../utils/fixtures/metrics_explorer';
import { InfraNodeType } from '../../graphql/types';
import DateMath from '@elastic/datemath';
import { ReactWrapper } from 'enzyme';
import { Capabilities } from 'src/core/public';
@ -163,12 +162,7 @@ describe('MetricsExplorerChartContextMenu', () => {
const toDateStrig = '2019-01-01T12:00:00Z';
const to = DateMath.parse(toDateStrig, { roundUp: true })!;
const from = DateMath.parse(fromDateStrig)!;
const link = createNodeDetailLink(
InfraNodeType.host,
'example-01',
fromDateStrig,
toDateStrig
);
const link = createNodeDetailLink('host', 'example-01', fromDateStrig, toDateStrig);
expect(link).toBe(
`#/link-to/host-detail/example-01?to=${to.valueOf()}&from=${from.valueOf()}`
);

View file

@ -21,9 +21,9 @@ import {
MetricsExplorerChartOptions,
} from '../../containers/metrics_explorer/use_metrics_explorer_options';
import { createTSVBLink } from './helpers/create_tsvb_link';
import { InfraNodeType } from '../../graphql/types';
import { getNodeDetailUrl } from '../../pages/link_to/redirect_to_node_detail';
import { SourceConfiguration } from '../../utils/source_configuration';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
options: MetricsExplorerOptions;
@ -35,15 +35,18 @@ interface Props {
chartOptions: MetricsExplorerChartOptions;
}
const fieldToNodeType = (source: SourceConfiguration, field: string): InfraNodeType | undefined => {
const fieldToNodeType = (
source: SourceConfiguration,
field: string
): InventoryItemType | undefined => {
if (source.fields.host === field) {
return InfraNodeType.host;
return 'host';
}
if (source.fields.pod === field) {
return InfraNodeType.pod;
return 'pod';
}
if (source.fields.container === field) {
return InfraNodeType.container;
return 'container';
}
};
@ -54,7 +57,7 @@ const dateMathExpressionToEpoch = (dateMathExpression: string, roundUp = false):
};
export const createNodeDetailLink = (
nodeType: InfraNodeType,
nodeType: InventoryItemType,
nodeId: string,
from: string,
to: string

View file

@ -11,7 +11,6 @@ import { get, max, min } from 'lodash';
import React from 'react';
import euiStyled from '../../../../../common/eui_styled_components';
import { InfraSnapshotMetricType, InfraSnapshotNode, InfraNodeType } from '../../graphql/types';
import { InfraFormatterType, InfraWaffleMapBounds, InfraWaffleMapOptions } from '../../lib/lib';
import { KueryFilterQuery } from '../../store/local/waffle_filter';
import { createFormatter } from '../../utils/formatters';
@ -22,10 +21,11 @@ import { ViewSwitcher } from '../waffle/view_switcher';
import { TableView } from './table';
import { SnapshotNode } from '../../../common/http_api/snapshot_api';
import { convertIntervalToString } from '../../utils/convert_interval_to_string';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
options: InfraWaffleMapOptions;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
nodes: SnapshotNode[];
loading: boolean;
reload: () => void;
@ -49,56 +49,56 @@ interface MetricFormatters {
}
const METRIC_FORMATTERS: MetricFormatters = {
[InfraSnapshotMetricType.count]: { formatter: InfraFormatterType.number, template: '{{value}}' },
[InfraSnapshotMetricType.cpu]: {
['count']: { formatter: InfraFormatterType.number, template: '{{value}}' },
['cpu']: {
formatter: InfraFormatterType.percent,
template: '{{value}}',
},
[InfraSnapshotMetricType.memory]: {
['memory']: {
formatter: InfraFormatterType.percent,
template: '{{value}}',
},
[InfraSnapshotMetricType.rx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraSnapshotMetricType.tx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraSnapshotMetricType.logRate]: {
['rx']: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
['tx']: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
['logRate']: {
formatter: InfraFormatterType.abbreviatedNumber,
template: '{{value}}/s',
},
[InfraSnapshotMetricType.diskIOReadBytes]: {
['diskIOReadBytes']: {
formatter: InfraFormatterType.bytes,
template: '{{value}}/s',
},
[InfraSnapshotMetricType.diskIOWriteBytes]: {
['diskIOWriteBytes']: {
formatter: InfraFormatterType.bytes,
template: '{{value}}/s',
},
[InfraSnapshotMetricType.s3BucketSize]: {
['s3BucketSize']: {
formatter: InfraFormatterType.bytes,
template: '{{value}}',
},
[InfraSnapshotMetricType.s3TotalRequests]: {
['s3TotalRequests']: {
formatter: InfraFormatterType.abbreviatedNumber,
template: '{{value}}',
},
[InfraSnapshotMetricType.s3NumberOfObjects]: {
['s3NumberOfObjects']: {
formatter: InfraFormatterType.abbreviatedNumber,
template: '{{value}}',
},
[InfraSnapshotMetricType.s3UploadBytes]: {
['s3UploadBytes']: {
formatter: InfraFormatterType.bytes,
template: '{{value}}',
},
[InfraSnapshotMetricType.s3DownloadBytes]: {
['s3DownloadBytes']: {
formatter: InfraFormatterType.bytes,
template: '{{value}}',
},
[InfraSnapshotMetricType.sqsOldestMessage]: {
['sqsOldestMessage']: {
formatter: InfraFormatterType.number,
template: '{{value}} seconds',
},
};
const calculateBoundsFromNodes = (nodes: InfraSnapshotNode[]): InfraWaffleMapBounds => {
const calculateBoundsFromNodes = (nodes: SnapshotNode[]): InfraWaffleMapBounds => {
const maxValues = nodes.map(node => node.metric.max);
const minValues = nodes.map(node => node.metric.value);
// if there is only one value then we need to set the bottom range to zero for min
@ -211,11 +211,7 @@ export const NodesOverview = class extends React.Component<Props, {}> {
// TODO: Change this to a real implimentation using the tickFormatter from the prototype as an example.
private formatter = (val: string | number) => {
const { metric } = this.props.options;
const metricFormatter = get(
METRIC_FORMATTERS,
metric.type,
METRIC_FORMATTERS[InfraSnapshotMetricType.count]
);
const metricFormatter = get(METRIC_FORMATTERS, metric.type, METRIC_FORMATTERS.count);
if (val == null) {
return '';
}

View file

@ -10,14 +10,15 @@ import { i18n } from '@kbn/i18n';
import { last } from 'lodash';
import React from 'react';
import { createWaffleMapNode } from '../../containers/waffle/nodes_to_wafflemap';
import { InfraSnapshotNode, InfraSnapshotNodePath, InfraNodeType } from '../../graphql/types';
import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../lib/lib';
import { fieldToName } from '../waffle/lib/field_to_display_name';
import { NodeContextMenu } from '../waffle/node_context_menu';
import { InventoryItemType } from '../../../common/inventory_models/types';
import { SnapshotNode, SnapshotNodePath } from '../../../common/http_api/snapshot_api';
interface Props {
nodes: InfraSnapshotNode[];
nodeType: InfraNodeType;
nodes: SnapshotNode[];
nodeType: InventoryItemType;
options: InfraWaffleMapOptions;
formatter: (subject: string | number) => string;
currentTime: number;
@ -30,7 +31,7 @@ const initialState = {
type State = Readonly<typeof initialState>;
const getGroupPaths = (path: InfraSnapshotNodePath[]) => {
const getGroupPaths = (path: SnapshotNodePath[]) => {
switch (path.length) {
case 3:
return path.slice(0, 2);

View file

@ -7,7 +7,6 @@
import React from 'react';
import euiStyled from '../../../../../common/eui_styled_components';
import { InfraNodeType } from '../../graphql/types';
import {
InfraWaffleMapBounds,
InfraWaffleMapGroupOfGroups,
@ -15,6 +14,7 @@ import {
} from '../../lib/lib';
import { GroupName } from './group_name';
import { GroupOfNodes } from './group_of_nodes';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
onDrilldown: (filter: string) => void;
@ -22,7 +22,7 @@ interface Props {
group: InfraWaffleMapGroupOfGroups;
formatter: (val: number) => string;
bounds: InfraWaffleMapBounds;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
currentTime: number;
}

View file

@ -7,7 +7,6 @@
import React from 'react';
import euiStyled from '../../../../../common/eui_styled_components';
import { InfraNodeType } from '../../graphql/types';
import {
InfraWaffleMapBounds,
InfraWaffleMapGroupOfNodes,
@ -15,6 +14,7 @@ import {
} from '../../lib/lib';
import { GroupName } from './group_name';
import { Node } from './node';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
onDrilldown: (filter: string) => void;
@ -23,7 +23,7 @@ interface Props {
formatter: (val: number) => string;
isChild: boolean;
bounds: InfraWaffleMapBounds;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
currentTime: number;
}

View file

@ -10,8 +10,7 @@ import {
InfraWaffleMapLegendMode,
InfraFormatterType,
} from '../../../lib/lib';
import { InfraNodeType } from '../../../../common/graphql/types';
import { InfraSnapshotMetricType } from '../../../graphql/types';
import { SnapshotMetricType } from '../../../../common/inventory_models/types';
const options: InfraWaffleMapOptions = {
fields: {
@ -24,7 +23,7 @@ const options: InfraWaffleMapOptions = {
},
formatter: InfraFormatterType.percent,
formatTemplate: '{{value}}',
metric: { type: InfraSnapshotMetricType.cpu },
metric: { type: 'cpu' },
groupBy: [],
legend: {
type: InfraWaffleMapLegendMode.gradient,
@ -41,13 +40,13 @@ describe('createUptimeLink()', () => {
ip: '10.0.1.2',
path: [],
metric: {
name: InfraSnapshotMetricType.cpu,
name: 'cpu' as SnapshotMetricType,
value: 0.5,
max: 0.8,
avg: 0.6,
},
};
expect(createUptimeLink(options, InfraNodeType.host, node)).toBe(
expect(createUptimeLink(options, 'host', node)).toBe(
'../app/uptime#/?search=host.ip:"10.0.1.2"'
);
});
@ -59,13 +58,13 @@ describe('createUptimeLink()', () => {
name: 'host-01',
path: [],
metric: {
name: InfraSnapshotMetricType.cpu,
name: 'cpu' as SnapshotMetricType,
value: 0.5,
max: 0.8,
avg: 0.6,
},
};
expect(createUptimeLink(options, InfraNodeType.host, node)).toBe(
expect(createUptimeLink(options, 'host', node)).toBe(
'../app/uptime#/?search=host.name:"host-01"'
);
});
@ -77,13 +76,13 @@ describe('createUptimeLink()', () => {
name: 'pod-01',
path: [],
metric: {
name: InfraSnapshotMetricType.cpu,
name: 'cpu' as SnapshotMetricType,
value: 0.5,
max: 0.8,
avg: 0.6,
},
};
expect(createUptimeLink(options, InfraNodeType.pod, node)).toBe(
expect(createUptimeLink(options, 'pod', node)).toBe(
'../app/uptime#/?search=kubernetes.pod.uid:"29193-pod-02939"'
);
});
@ -95,13 +94,13 @@ describe('createUptimeLink()', () => {
name: 'docker-01',
path: [],
metric: {
name: InfraSnapshotMetricType.cpu,
name: 'cpu' as SnapshotMetricType,
value: 0.5,
max: 0.8,
avg: 0.6,
},
};
expect(createUptimeLink(options, InfraNodeType.container, node)).toBe(
expect(createUptimeLink(options, 'container', node)).toBe(
'../app/uptime#/?search=container.id:"docker-1234"'
);
});

View file

@ -5,17 +5,17 @@
*/
import { get } from 'lodash';
import { InfraNodeType } from '../../../graphql/types';
import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../../lib/lib';
import { InventoryItemType } from '../../../../common/inventory_models/types';
const BASE_URL = '../app/uptime#/?search=';
export const createUptimeLink = (
options: InfraWaffleMapOptions,
nodeType: InfraNodeType,
nodeType: InventoryItemType,
node: InfraWaffleMapNode
) => {
if (nodeType === InfraNodeType.host && node.ip) {
if (nodeType === 'host' && node.ip) {
return `${BASE_URL}host.ip:"${node.ip}"`;
}
const field = get(options, ['fields', nodeType], '');

View file

@ -11,17 +11,18 @@ import {
isWaffleMapGroupWithGroups,
isWaffleMapGroupWithNodes,
} from '../../containers/waffle/type_guards';
import { InfraSnapshotNode, InfraNodeType } from '../../graphql/types';
import { InfraWaffleMapBounds, InfraWaffleMapOptions } from '../../lib/lib';
import { AutoSizer } from '../auto_sizer';
import { GroupOfGroups } from './group_of_groups';
import { GroupOfNodes } from './group_of_nodes';
import { Legend } from './legend';
import { applyWaffleMapLayout } from './lib/apply_wafflemap_layout';
import { SnapshotNode } from '../../../common/http_api/snapshot_api';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
nodes: InfraSnapshotNode[];
nodeType: InfraNodeType;
nodes: SnapshotNode[];
nodeType: InventoryItemType;
options: InfraWaffleMapOptions;
formatter: (subject: string | number) => string;
currentTime: number;

View file

@ -11,10 +11,10 @@ import { i18n } from '@kbn/i18n';
import { ConditionalToolTip } from './conditional_tooltip';
import euiStyled from '../../../../../common/eui_styled_components';
import { InfraNodeType } from '../../graphql/types';
import { InfraWaffleMapBounds, InfraWaffleMapNode, InfraWaffleMapOptions } from '../../lib/lib';
import { colorFromValue } from './lib/color_from_value';
import { NodeContextMenu } from './node_context_menu';
import { InventoryItemType } from '../../../common/inventory_models/types';
const initialState = {
isPopoverOpen: false,
@ -28,7 +28,7 @@ interface Props {
node: InfraWaffleMapNode;
formatter: (val: number) => string;
bounds: InfraWaffleMapBounds;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
currentTime: number;
}

View file

@ -13,19 +13,19 @@ import {
import { i18n } from '@kbn/i18n';
import React from 'react';
import { InfraNodeType } from '../../graphql/types';
import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../lib/lib';
import { getNodeDetailUrl, getNodeLogsUrl } from '../../pages/link_to';
import { createUptimeLink } from './lib/create_uptime_link';
import { findInventoryModel } from '../../../common/inventory_models';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { InventoryItemType } from '../../../common/inventory_models/types';
interface Props {
options: InfraWaffleMapOptions;
currentTime: number;
children: any;
node: InfraWaffleMapNode;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
isPopoverOpen: boolean;
closePopover: () => void;
popoverPosition: EuiPopoverProps['anchorPosition'];
@ -47,7 +47,7 @@ export const NodeContextMenu = ({
// We need to have some exceptions until 7.0 & ECS is finalized. Reference
// #26620 for the details for these fields.
// TODO: This is tech debt, remove it after 7.0 & ECS migration.
const apmField = nodeType === InfraNodeType.host ? 'host.hostname' : inventoryModel.fields.id;
const apmField = nodeType === 'host' ? 'host.hostname' : inventoryModel.fields.id;
const nodeLogsMenuItem = {
name: i18n.translate('xpack.infra.nodeContextMenu.viewLogsName', {
@ -95,8 +95,7 @@ export const NodeContextMenu = ({
const showAPMTraceLink =
inventoryModel.crosslinkSupport.apm && uiCapabilities?.apm && uiCapabilities?.apm.show;
const showUptimeLink =
inventoryModel.crosslinkSupport.uptime &&
([InfraNodeType.pod, InfraNodeType.container].includes(nodeType) || node.ip);
inventoryModel.crosslinkSupport.uptime && (['pod', 'container'].includes(nodeType) || node.ip);
const items = [
...(showLogsLink ? [nodeLogsMenuItem] : []),

View file

@ -17,16 +17,17 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { IFieldType } from 'src/plugins/data/public';
import { InfraNodeType, InfraSnapshotGroupbyInput } from '../../graphql/types';
import { InfraGroupByOptions } from '../../lib/lib';
import { CustomFieldPanel } from './custom_field_panel';
import euiStyled from '../../../../../common/eui_styled_components';
import { InventoryItemType } from '../../../common/inventory_models/types';
import { SnapshotGroupBy } from '../../../common/http_api/snapshot_api';
interface Props {
options: Array<{ text: string; field: string; toolTipContent?: string }>;
nodeType: InfraNodeType;
groupBy: InfraSnapshotGroupbyInput[];
onChange: (groupBy: InfraSnapshotGroupbyInput[]) => void;
nodeType: InventoryItemType;
groupBy: SnapshotGroupBy;
onChange: (groupBy: SnapshotGroupBy) => void;
onChangeCustomOptions: (options: InfraGroupByOptions[]) => void;
fields: IFieldType[];
customOptions: InfraGroupByOptions[];

View file

@ -14,20 +14,15 @@ import {
import React, { useCallback, useState, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
InfraSnapshotMetricInput,
InfraSnapshotMetricType,
InfraNodeType,
InfraSnapshotGroupbyInput,
} from '../../graphql/types';
import { findInventoryModel } from '../../../common/inventory_models';
import { InventoryItemType } from '../../../common/inventory_models/types';
import { SnapshotMetricInput, SnapshotGroupBy } from '../../../common/http_api/snapshot_api';
interface WaffleInventorySwitcherProps {
nodeType: InfraNodeType;
changeNodeType: (nodeType: InfraNodeType) => void;
changeGroupBy: (groupBy: InfraSnapshotGroupbyInput[]) => void;
changeMetric: (metric: InfraSnapshotMetricInput) => void;
nodeType: InventoryItemType;
changeNodeType: (nodeType: InventoryItemType) => void;
changeGroupBy: (groupBy: SnapshotGroupBy) => void;
changeMetric: (metric: SnapshotMetricInput) => void;
changeAccount: (id: string) => void;
changeRegion: (name: string) => void;
}
@ -49,7 +44,7 @@ export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = (
const closePopover = useCallback(() => setIsOpen(false), []);
const openPopover = useCallback(() => setIsOpen(true), []);
const goToNodeType = useCallback(
(targetNodeType: InfraNodeType) => {
(targetNodeType: InventoryItemType) => {
closePopover();
changeNodeType(targetNodeType);
changeGroupBy([]);
@ -57,18 +52,18 @@ export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = (
changeRegion('');
const inventoryModel = findInventoryModel(targetNodeType);
changeMetric({
type: inventoryModel.metrics.defaultSnapshot as InfraSnapshotMetricType,
type: inventoryModel.metrics.defaultSnapshot,
});
},
[closePopover, changeNodeType, changeGroupBy, changeMetric, changeAccount, changeRegion]
);
const goToHost = useCallback(() => goToNodeType('host' as InfraNodeType), [goToNodeType]);
const goToK8 = useCallback(() => goToNodeType('pod' as InfraNodeType), [goToNodeType]);
const goToDocker = useCallback(() => goToNodeType('container' as InfraNodeType), [goToNodeType]);
const goToAwsEC2 = useCallback(() => goToNodeType('awsEC2' as InfraNodeType), [goToNodeType]);
const goToAwsS3 = useCallback(() => goToNodeType('awsS3' as InfraNodeType), [goToNodeType]);
const goToAwsRDS = useCallback(() => goToNodeType('awsRDS' as InfraNodeType), [goToNodeType]);
const goToAwsSQS = useCallback(() => goToNodeType('awsSQS' as InfraNodeType), [goToNodeType]);
const goToHost = useCallback(() => goToNodeType('host'), [goToNodeType]);
const goToK8 = useCallback(() => goToNodeType('pod'), [goToNodeType]);
const goToDocker = useCallback(() => goToNodeType('container'), [goToNodeType]);
const goToAwsEC2 = useCallback(() => goToNodeType('awsEC2'), [goToNodeType]);
const goToAwsS3 = useCallback(() => goToNodeType('awsS3'), [goToNodeType]);
const goToAwsRDS = useCallback(() => goToNodeType('awsRDS'), [goToNodeType]);
const goToAwsSQS = useCallback(() => goToNodeType('awsSQS'), [goToNodeType]);
const panels = useMemo(
() =>
[

View file

@ -14,13 +14,13 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { InfraSnapshotMetricInput, InfraSnapshotMetricType } from '../../graphql/types';
import { SnapshotMetricInput } from '../../../common/http_api/snapshot_api';
import { SnapshotMetricType } from '../../../common/inventory_models/types';
interface Props {
options: Array<{ text: string; value: InfraSnapshotMetricType }>;
metric: InfraSnapshotMetricInput;
onChange: (metric: InfraSnapshotMetricInput) => void;
options: Array<{ text: string; value: SnapshotMetricType }>;
metric: SnapshotMetricInput;
onChange: (metric: SnapshotMetricInput) => void;
}
const initialState = {
@ -90,7 +90,7 @@ export const WaffleMetricControls = class extends React.PureComponent<Props, Sta
this.setState(state => ({ isPopoverOpen: !state.isPopoverOpen }));
};
private handleClick = (value: InfraSnapshotMetricType) => () => {
private handleClick = (value: SnapshotMetricType) => () => {
this.props.onChange({ type: value });
this.handleClose();
};

View file

@ -13,9 +13,9 @@ import {
InventoryMetaResponseRT,
InventoryMetaResponse,
} from '../../../common/http_api/inventory_meta_api';
import { InfraNodeType } from '../../graphql/types';
import { InventoryItemType } from '../../../common/inventory_models/types';
export function useInventoryMeta(sourceId: string, nodeType: InfraNodeType) {
export function useInventoryMeta(sourceId: string, nodeType: InventoryItemType) {
const decodeResponse = (response: any) => {
return pipe(
InventoryMetaResponseRT.decode(response),

View file

@ -8,16 +8,15 @@ import { useEffect } from 'react';
import { fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import { InfraNodeType } from '../../graphql/types';
import { InfraMetadata, InfraMetadataRT } from '../../../common/http_api/metadata_api';
import { useHTTPRequest } from '../../hooks/use_http_request';
import { throwErrors, createPlainError } from '../../../common/runtime_types';
import { InventoryMetric } from '../../../common/inventory_models/types';
import { InventoryMetric, InventoryItemType } from '../../../common/inventory_models/types';
import { getFilteredMetrics } from './lib/get_filtered_metrics';
export function useMetadata(
nodeId: string,
nodeType: InfraNodeType,
nodeType: InventoryItemType,
requiredMetrics: InventoryMetric[],
sourceId: string
) {

View file

@ -6,19 +6,19 @@
import { fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import { InfraNodeType, InfraTimerangeInput } from '../../graphql/types';
import { throwErrors, createPlainError } from '../../../common/runtime_types';
import { useHTTPRequest } from '../../hooks/use_http_request';
import {
NodeDetailsMetricDataResponseRT,
NodeDetailsMetricDataResponse,
} from '../../../common/http_api/node_details_api';
import { InventoryMetric } from '../../../common/inventory_models/types';
import { InventoryMetric, InventoryItemType } from '../../../common/inventory_models/types';
import { InfraTimerangeInput } from '../../../common/http_api/snapshot_api';
export function useNodeDetails(
metrics: InventoryMetric[],
nodeId: string,
nodeType: InfraNodeType,
nodeType: InventoryItemType,
sourceId: string,
timerange: InfraTimerangeInput,
cloudId: string

View file

@ -6,8 +6,6 @@
import { i18n } from '@kbn/i18n';
import { first, last } from 'lodash';
import { InfraSnapshotNode, InfraSnapshotNodePath } from '../../graphql/types';
import {
InfraWaffleMapGroup,
InfraWaffleMapGroupOfGroups,
@ -15,14 +13,15 @@ import {
InfraWaffleMapNode,
} from '../../lib/lib';
import { isWaffleMapGroupWithGroups, isWaffleMapGroupWithNodes } from './type_guards';
import { SnapshotNodePath, SnapshotNode } from '../../../common/http_api/snapshot_api';
export function createId(path: InfraSnapshotNodePath[]) {
export function createId(path: SnapshotNodePath[]) {
return path.map(p => p.value).join('/');
}
function findOrCreateGroupWithNodes(
groups: InfraWaffleMapGroup[],
path: InfraSnapshotNodePath[]
path: SnapshotNodePath[]
): InfraWaffleMapGroupOfNodes {
const id = path.length === 0 ? '__all__' : createId(path);
/**
@ -62,7 +61,7 @@ function findOrCreateGroupWithNodes(
function findOrCreateGroupWithGroups(
groups: InfraWaffleMapGroup[],
path: InfraSnapshotNodePath[]
path: SnapshotNodePath[]
): InfraWaffleMapGroupOfGroups {
const id = path.length === 0 ? '__all__' : createId(path);
const lastPath = last(path);
@ -85,7 +84,7 @@ function findOrCreateGroupWithGroups(
};
}
export function createWaffleMapNode(node: InfraSnapshotNode): InfraWaffleMapNode {
export function createWaffleMapNode(node: SnapshotNode): InfraWaffleMapNode {
const nodePathItem = last(node.path);
if (!nodePathItem) {
throw new Error('There must be at least one node path item');
@ -106,8 +105,8 @@ function withoutGroup(group: InfraWaffleMapGroup) {
};
}
export function nodesToWaffleMap(nodes: InfraSnapshotNode[]): InfraWaffleMapGroup[] {
return nodes.reduce((groups: InfraWaffleMapGroup[], node: InfraSnapshotNode) => {
export function nodesToWaffleMap(nodes: SnapshotNode[]): InfraWaffleMapGroup[] {
return nodes.reduce((groups: InfraWaffleMapGroup[], node: SnapshotNode) => {
const waffleNode = createWaffleMapNode(node);
if (node.path.length === 2) {
const parentGroup = findOrCreateGroupWithNodes(

View file

@ -8,23 +8,20 @@ import { useEffect } from 'react';
import { fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import {
InfraNodeType,
InfraSnapshotMetricInput,
InfraSnapshotGroupbyInput,
} from '../../graphql/types';
import { throwErrors, createPlainError } from '../../../common/runtime_types';
import { useHTTPRequest } from '../../hooks/use_http_request';
import {
SnapshotNodeResponseRT,
SnapshotNodeResponse,
SnapshotGroupBy,
} from '../../../common/http_api/snapshot_api';
import { InventoryItemType, SnapshotMetricType } from '../../../common/inventory_models/types';
export function useSnapshot(
filterQuery: string | null | undefined,
metric: InfraSnapshotMetricInput,
groupBy: InfraSnapshotGroupbyInput[],
nodeType: InfraNodeType,
metric: { type: SnapshotMetricType },
groupBy: SnapshotGroupBy,
nodeType: InventoryItemType,
sourceId: string,
currentTime: number,
accountId: string,

View file

@ -9,17 +9,17 @@ import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { isBoolean, isNumber } from 'lodash';
import {
InfraSnapshotMetricInput,
InfraSnapshotMetricType,
InfraNodeType,
InfraSnapshotGroupbyInput,
} from '../../graphql/types';
import { InfraGroupByOptions } from '../../lib/lib';
import { State, waffleOptionsActions, waffleOptionsSelectors } from '../../store';
import { asChildFunctionRenderer } from '../../utils/typed_react';
import { bindPlainActionCreators } from '../../utils/typed_redux';
import { UrlStateContainer } from '../../utils/url_state';
import { SnapshotMetricInput, SnapshotGroupBy } from '../../../common/http_api/snapshot_api';
import {
SnapshotMetricTypeRT,
InventoryItemType,
ItemTypeRT,
} from '../../../common/inventory_models/types';
const selectOptionsUrlState = createSelector(
waffleOptionsSelectors.selectMetric,
@ -194,13 +194,13 @@ const mapToUrlState = (value: any): WaffleOptionsUrlState | undefined =>
}
: undefined;
const isInfraNodeType = (value: any): value is InfraNodeType => value in InfraNodeType;
const isInfraNodeType = (value: any): value is InventoryItemType => value in ItemTypeRT;
const isInfraSnapshotMetricInput = (subject: any): subject is InfraSnapshotMetricInput => {
return subject != null && subject.type in InfraSnapshotMetricType;
const isInfraSnapshotMetricInput = (subject: any): subject is SnapshotMetricInput => {
return subject != null && subject.type in SnapshotMetricTypeRT;
};
const isInfraSnapshotGroupbyInput = (subject: any): subject is InfraSnapshotGroupbyInput => {
const isInfraSnapshotGroupbyInput = (subject: any): subject is SnapshotGroupBy => {
return subject != null && subject.type != null;
};

View file

@ -7,7 +7,6 @@
import moment from 'moment';
import React from 'react';
import { InfraSnapshotMetricType } from '../graphql/types';
import { InfraFormatterType, InfraOptions, InfraWaffleMapLegendMode } from '../lib/lib';
import { RendererFunction } from '../utils/typed_react';
@ -24,7 +23,7 @@ const initialState = {
wafflemap: {
formatter: InfraFormatterType.percent,
formatTemplate: '{{value}}',
metric: { type: InfraSnapshotMetricType.cpu },
metric: { type: 'cpu' },
groupBy: [],
legend: {
type: InfraWaffleMapLegendMode.gradient,

View file

@ -10,14 +10,14 @@ import ApolloClient from 'apollo-client';
import { AxiosRequestConfig } from 'axios';
import React from 'react';
import { Observable } from 'rxjs';
import { SourceQuery } from '../graphql/types';
import {
InfraSnapshotMetricInput,
InfraSnapshotNodeMetric,
InfraSnapshotNodePath,
InfraSnapshotGroupbyInput,
SnapshotMetricInput,
SnapshotGroupBy,
InfraTimerangeInput,
SourceQuery,
} from '../graphql/types';
SnapshotNodeMetric,
SnapshotNodePath,
} from '../../common/http_api/snapshot_api';
export interface InfraFrontendLibs {
apolloClient: InfraApolloClient;
@ -102,8 +102,8 @@ export interface InfraWaffleMapNode {
id: string;
name: string;
ip?: string | null;
path: InfraSnapshotNodePath[];
metric: InfraSnapshotNodeMetric;
path: SnapshotNodePath[];
metric: SnapshotNodeMetric;
}
export type InfraWaffleMapGroup = InfraWaffleMapGroupOfNodes | InfraWaffleMapGroupOfGroups;
@ -165,8 +165,8 @@ export interface InfraWaffleMapOptions {
fields?: SourceQuery.Query['source']['configuration']['fields'] | null;
formatter: InfraFormatterType;
formatTemplate: string;
metric: InfraSnapshotMetricInput;
groupBy: InfraSnapshotGroupbyInput[];
metric: SnapshotMetricInput;
groupBy: SnapshotGroupBy;
legend: InfraWaffleMapLegend;
}

View file

@ -8,12 +8,12 @@ import React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';
import { replaceMetricTimeInQueryString } from '../metrics/containers/with_metrics_time';
import { InfraNodeType } from '../../graphql/types';
import { getFromFromLocation, getToFromLocation } from './query_params';
import { InventoryItemType } from '../../../common/inventory_models/types';
type RedirectToNodeDetailProps = RouteComponentProps<{
nodeId: string;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
}>;
export const RedirectToNodeDetail = ({
@ -36,7 +36,7 @@ export const getNodeDetailUrl = ({
to,
from,
}: {
nodeType: InfraNodeType;
nodeType: InventoryItemType;
nodeId: string;
to?: number;
from?: number;

View file

@ -14,18 +14,22 @@ import { LoadingPage } from '../../components/loading_page';
import { replaceLogFilterInQueryString } from '../../containers/logs/log_filter';
import { replaceLogPositionInQueryString } from '../../containers/logs/log_position';
import { replaceSourceIdInQueryString } from '../../containers/source_id';
import { InfraNodeType, SourceConfigurationFields } from '../../graphql/types';
import { SourceConfigurationFields } from '../../graphql/types';
import { getFilterFromLocation, getTimeFromLocation } from './query_params';
import { useSource } from '../../containers/source/source';
import { findInventoryFields } from '../../../common/inventory_models';
import { InventoryItemType } from '../../../common/inventory_models/types';
type RedirectToNodeLogsType = RouteComponentProps<{
nodeId: string;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
sourceId?: string;
}>;
const getFieldByNodeType = (nodeType: InfraNodeType, fields: SourceConfigurationFields.Fields) => {
const getFieldByNodeType = (
nodeType: InventoryItemType,
fields: SourceConfigurationFields.Fields
) => {
const inventoryFields = findInventoryFields(nodeType, fields);
return inventoryFields.id;
};
@ -75,6 +79,6 @@ export const getNodeLogsUrl = ({
time,
}: {
nodeId: string;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
time?: number;
}) => [`#/link-to/${nodeType}-logs/`, nodeId, ...(time ? [`?time=${time}`] : [])].join('');

View file

@ -8,13 +8,14 @@ import { ReactText } from 'react';
import Color from 'color';
import { get, first, last, min, max } from 'lodash';
import { createFormatter } from '../../../utils/formatters';
import { InfraDataSeries, InfraMetricData } from '../../../graphql/types';
import { InfraDataSeries } from '../../../graphql/types';
import {
InventoryVisTypeRT,
InventoryFormatterType,
InventoryVisType,
} from '../../../../common/inventory_models/types';
import { SeriesOverrides } from '../types';
import { NodeDetailsMetricData } from '../../../../common/http_api/node_details_api';
/**
* Returns a formatter
@ -34,7 +35,7 @@ export const seriesHasLessThen2DataPoints = (series: InfraDataSeries): boolean =
/**
* Returns the minimum and maximum timestamp for a metric
*/
export const getMaxMinTimestamp = (metric: InfraMetricData): [number, number] => {
export const getMaxMinTimestamp = (metric: NodeDetailsMetricData): [number, number] => {
if (metric.series.some(seriesHasLessThen2DataPoints)) {
return [0, 0];
}

View file

@ -13,9 +13,9 @@ import {
EuiHideFor,
EuiTitle,
} from '@elastic/eui';
import { InventoryMetric } from '../../../../common/inventory_models/types';
import { InfraTimerangeInput } from '../../../../common/http_api/snapshot_api';
import { InventoryMetric, InventoryItemType } from '../../../../common/inventory_models/types';
import { useNodeDetails } from '../../../containers/node_details/use_node_details';
import { InfraNodeType, InfraTimerangeInput } from '../../../graphql/types';
import { MetricsSideNav } from './side_nav';
import { AutoSizer } from '../../../components/auto_sizer';
import { MetricsTimeControls } from './time_controls';
@ -32,7 +32,7 @@ interface Props {
requiredMetrics: InventoryMetric[];
nodeId: string;
cloudId: string;
nodeType: InfraNodeType;
nodeType: InventoryItemType;
sourceId: string;
timeRange: MetricsTimeInput;
parsedTimeRange: InfraTimerangeInput;

View file

@ -8,16 +8,17 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { findLayout } from '../../../../common/inventory_models/layouts';
import { InventoryItemType } from '../../../../common/inventory_models/types';
import { InfraMetricData } from '../../../graphql/types';
import { MetricsTimeInput } from '../containers/with_metrics_time';
import { InfraLoadingPanel } from '../../../components/loading';
import { NoData } from '../../../components/empty_states';
import { NodeDetailsMetricData } from '../../../../common/http_api/node_details_api';
interface Props {
loading: boolean;
refetch: () => void;
type: InventoryItemType;
metrics: InfraMetricData[];
metrics: NodeDetailsMetricData[];
onChangeRangeTime?: (time: MetricsTimeInput) => void;
isLiveStreaming?: boolean;
stopLiveStreaming?: () => void;

View file

@ -1,91 +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;
* you may not use this file except in compliance with the Elastic License.
*/
import { ApolloError } from 'apollo-client';
import React from 'react';
import { Query } from 'react-apollo';
import { i18n } from '@kbn/i18n';
import {
InfraMetric,
InfraMetricData,
InfraNodeType,
MetricsQuery,
InfraTimerangeInput,
} from '../../../graphql/types';
import { metricsQuery } from './metrics.gql_query';
import { InventoryMetric, InventoryMetricRT } from '../../../../common/inventory_models/types';
interface WithMetricsArgs {
metrics: InfraMetricData[];
error?: ApolloError | undefined;
loading: boolean;
refetch: () => void;
}
interface WithMetricsProps {
children: (args: WithMetricsArgs) => React.ReactNode;
requiredMetrics: InventoryMetric[];
nodeType: InfraNodeType;
nodeId: string;
cloudId: string;
sourceId: string;
timerange: InfraTimerangeInput;
}
const isInfraMetrics = (subject: any[]): subject is InfraMetric[] => {
return subject.every(s => InventoryMetricRT.is(s));
};
export const WithMetrics = ({
children,
requiredMetrics,
sourceId,
timerange,
nodeType,
nodeId,
cloudId,
}: WithMetricsProps) => {
if (!isInfraMetrics(requiredMetrics)) {
throw new Error(
i18n.translate('xpack.infra.invalidInventoryMetricsError', {
defaultMessage: 'One of the InfraMetric is invalid',
})
);
}
return (
<Query<MetricsQuery.Query, MetricsQuery.Variables>
query={metricsQuery}
fetchPolicy="no-cache"
notifyOnNetworkStatusChange
variables={{
sourceId,
metrics: requiredMetrics,
nodeType,
nodeId,
cloudId,
timerange,
}}
>
{({ data, error, loading, refetch }) => {
return children({
metrics: filterOnlyInfraMetricData(data && data.source && data.source.metrics),
error,
loading,
refetch,
});
}}
</Query>
);
};
const filterOnlyInfraMetricData = (
metrics: Array<MetricsQuery.Metrics | null> | undefined
): InfraMetricData[] => {
if (!metrics) {
return [];
}
return metrics.filter(m => m !== null).map(m => m as InfraMetricData);
};

View file

@ -10,7 +10,6 @@ import { DocumentTitle } from '../../components/document_title';
import { Header } from '../../components/header';
import { ColumnarPage, PageContent } from '../../components/page';
import { WithMetricsTime, WithMetricsTimeUrlState } from './containers/with_metrics_time';
import { InfraNodeType } from '../../graphql/types';
import { withMetricPageProviders } from './page_providers';
import { useMetadata } from '../../containers/metadata/use_metadata';
import { Source } from '../../containers/source';
@ -19,6 +18,7 @@ import { findInventoryModel } from '../../../common/inventory_models';
import { NavItem } from './lib/side_nav_context';
import { NodeDetailsPage } from './components/node_details_page';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { InventoryItemType } from '../../../common/inventory_models/types';
const DetailPageContent = euiStyled(PageContent)`
overflow: auto;
@ -39,7 +39,7 @@ export const MetricDetail = withMetricPageProviders(
withTheme(({ match, theme }: Props) => {
const uiCapabilities = useKibana().services.application?.capabilities;
const nodeId = match.params.node;
const nodeType = match.params.type as InfraNodeType;
const nodeType = match.params.type as InventoryItemType;
const inventoryModel = findInventoryModel(nodeType);
const { sourceId } = useContext(Source.Context);
const {

View file

@ -6,12 +6,12 @@
import rt from 'io-ts';
import { EuiTheme } from '../../../../../common/eui_styled_components';
import { InfraMetricData } from '../../graphql/types';
import { InventoryFormatterTypeRT } from '../../../common/inventory_models/types';
import { MetricsTimeInput } from './containers/with_metrics_time';
import { NodeDetailsMetricData } from '../../../common/http_api/node_details_api';
export interface LayoutProps {
metrics?: InfraMetricData[];
metrics?: NodeDetailsMetricData[];
onChangeRangeTime?: (time: MetricsTimeInput) => void;
isLiveStreaming?: boolean;
stopLiveStreaming?: () => void;
@ -55,7 +55,7 @@ export const VisSectionPropsRT = rt.partial({
export type VisSectionProps = rt.TypeOf<typeof VisSectionPropsRT> & {
id?: string;
metric?: InfraMetricData;
metric?: NodeDetailsMetricData;
onChangeRangeTime?: (time: MetricsTimeInput) => void;
isLiveStreaming?: boolean;
stopLiveStreaming?: () => void;

View file

@ -5,19 +5,16 @@
*/
import actionCreatorFactory from 'typescript-fsa';
import {
InfraSnapshotMetricInput,
InfraNodeType,
InfraSnapshotGroupbyInput,
} from '../../../graphql/types';
import { SnapshotGroupBy, SnapshotMetricInput } from '../../../../common/http_api/snapshot_api';
import { InventoryItemType } from '../../../../common/inventory_models/types';
import { InfraGroupByOptions, InfraWaffleMapBounds } from '../../../lib/lib';
const actionCreator = actionCreatorFactory('x-pack/infra/local/waffle_options');
export const changeMetric = actionCreator<InfraSnapshotMetricInput>('CHANGE_METRIC');
export const changeGroupBy = actionCreator<InfraSnapshotGroupbyInput[]>('CHANGE_GROUP_BY');
export const changeMetric = actionCreator<SnapshotMetricInput>('CHANGE_METRIC');
export const changeGroupBy = actionCreator<SnapshotGroupBy>('CHANGE_GROUP_BY');
export const changeCustomOptions = actionCreator<InfraGroupByOptions[]>('CHANGE_CUSTOM_OPTIONS');
export const changeNodeType = actionCreator<InfraNodeType>('CHANGE_NODE_TYPE');
export const changeNodeType = actionCreator<InventoryItemType>('CHANGE_NODE_TYPE');
export const changeView = actionCreator<string>('CHANGE_VIEW');
export const changeBoundsOverride = actionCreator<InfraWaffleMapBounds>('CHANGE_BOUNDS_OVERRIDE');
export const changeAutoBounds = actionCreator<boolean>('CHANGE_AUTO_BOUNDS');

View file

@ -6,13 +6,7 @@
import { combineReducers } from 'redux';
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import {
InfraSnapshotMetricInput,
InfraSnapshotMetricType,
InfraNodeType,
InfraSnapshotGroupbyInput,
} from '../../../graphql/types';
import { SnapshotMetricInput, SnapshotGroupBy } from '../../../../common/http_api/snapshot_api';
import { InfraGroupByOptions, InfraWaffleMapBounds } from '../../../lib/lib';
import {
changeAutoBounds,
@ -25,11 +19,12 @@ import {
changeAccount,
changeRegion,
} from './actions';
import { InventoryItemType } from '../../../../common/inventory_models/types';
export interface WaffleOptionsState {
metric: InfraSnapshotMetricInput;
groupBy: InfraSnapshotGroupbyInput[];
nodeType: InfraNodeType;
metric: SnapshotMetricInput;
groupBy: SnapshotGroupBy;
nodeType: InventoryItemType;
view: string;
customOptions: InfraGroupByOptions[];
boundsOverride: InfraWaffleMapBounds;
@ -39,9 +34,9 @@ export interface WaffleOptionsState {
}
export const initialWaffleOptionsState: WaffleOptionsState = {
metric: { type: InfraSnapshotMetricType.cpu },
metric: { type: 'cpu' },
groupBy: [],
nodeType: InfraNodeType.host,
nodeType: 'host',
view: 'map',
customOptions: [],
boundsOverride: { max: 1, min: 0 },

View file

@ -6,22 +6,19 @@
import { RequestHandlerContext, KibanaRequest } from 'src/core/server';
import {
InfraMetric,
InfraMetricData,
InfraNodeType,
InfraTimerangeInput,
} from '../../../graphql/types';
NodeDetailsRequest,
NodeDetailsMetricData,
} from '../../../../common/http_api/node_details_api';
import { InventoryMetric } from '../../../../common/inventory_models/types';
import { InfraSourceConfiguration } from '../../sources';
export interface InfraMetricsRequestOptions {
export interface InfraMetricsRequestOptions
extends Omit<NodeDetailsRequest, 'sourceId' | 'nodeId' | 'cloudId'> {
nodeIds: {
nodeId: string;
cloudId?: string | null;
};
nodeType: InfraNodeType;
sourceConfiguration: InfraSourceConfiguration;
timerange: InfraTimerangeInput;
metrics: InfraMetric[];
}
export interface InfraMetricsAdapter {
@ -29,7 +26,7 @@ export interface InfraMetricsAdapter {
requestContext: RequestHandlerContext,
options: InfraMetricsRequestOptions,
request: KibanaRequest
): Promise<InfraMetricData[]>;
): Promise<NodeDetailsMetricData[]>;
}
export enum InfraMetricModelQueryType {
@ -52,7 +49,7 @@ export enum InfraMetricModelMetricType {
}
export interface InfraMetricModel {
id: InfraMetric;
id: InventoryMetric;
requires: string[];
index_pattern: string | string[];
interval: string;

View file

@ -7,12 +7,16 @@
import { i18n } from '@kbn/i18n';
import { flatten, get } from 'lodash';
import { KibanaRequest, RequestHandlerContext } from 'src/core/server';
import { InfraMetric, InfraMetricData } from '../../../graphql/types';
import { NodeDetailsMetricData } from '../../../../common/http_api/node_details_api';
import { KibanaFramework } from '../framework/kibana_framework_adapter';
import { InfraMetricsAdapter, InfraMetricsRequestOptions } from './adapter_types';
import { checkValidNode } from './lib/check_valid_node';
import { metrics, findInventoryFields } from '../../../../common/inventory_models';
import { TSVBMetricModelCreator } from '../../../../common/inventory_models/types';
import {
TSVBMetricModelCreator,
InventoryMetric,
InventoryMetricRT,
} from '../../../../common/inventory_models/types';
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
export class KibanaMetricsAdapter implements InfraMetricsAdapter {
@ -26,7 +30,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter {
requestContext: RequestHandlerContext,
options: InfraMetricsRequestOptions,
rawRequest: KibanaRequest
): Promise<InfraMetricData[]> {
): Promise<NodeDetailsMetricData[]> {
const indexPattern = `${options.sourceConfiguration.metricAlias},${options.sourceConfiguration.logAlias}`;
const fields = findInventoryFields(options.nodeType, options.sourceConfiguration.fields);
const nodeField = fields.id;
@ -58,8 +62,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter {
);
return metricIds.map((id: string) => {
const infraMetricId: InfraMetric = (InfraMetric as any)[id];
if (!infraMetricId) {
if (!InventoryMetricRT.is(id)) {
throw new Error(
i18n.translate('xpack.infra.kibanaMetrics.invalidInfraMetricErrorMessage', {
defaultMessage: '{id} is not a valid InfraMetric',
@ -69,9 +72,9 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter {
})
);
}
const panel = result[infraMetricId];
const panel = result[id];
return {
id: infraMetricId,
id,
series: panel.series.map(series => {
return {
id: series.id,
@ -87,7 +90,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter {
}
async makeTSVBRequest(
metricId: InfraMetric,
metricId: InventoryMetric,
options: InfraMetricsRequestOptions,
nodeField: string,
requestContext: RequestHandlerContext

View file

@ -5,8 +5,8 @@
*/
import { KibanaRequest, RequestHandlerContext } from 'src/core/server';
import { InfraMetricData } from '../../graphql/types';
import { InfraMetricsAdapter, InfraMetricsRequestOptions } from '../adapters/metrics/adapter_types';
import { NodeDetailsMetricData } from '../../../common/http_api/node_details_api';
export class InfraMetricsDomain {
private adapter: InfraMetricsAdapter;
@ -19,7 +19,7 @@ export class InfraMetricsDomain {
requestContext: RequestHandlerContext,
options: InfraMetricsRequestOptions,
rawRequest: KibanaRequest
): Promise<InfraMetricData[]> {
): Promise<NodeDetailsMetricData[]> {
return await this.adapter.getMetrics(requestContext, options, rawRequest);
}
}

View file

@ -7,12 +7,12 @@
import { uniq } from 'lodash';
import { RequestHandlerContext } from 'kibana/server';
import { InfraSnapshotRequestOptions } from './types';
import { InfraTimerangeInput } from '../../../public/graphql/types';
import { getMetricsAggregations } from './query_helpers';
import { calculateMetricInterval } from '../../utils/calculate_metric_interval';
import { SnapshotModel, SnapshotModelMetricAggRT } from '../../../common/inventory_models/types';
import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
import { getDatasetForField } from '../../routes/metrics_explorer/lib/get_dataset_for_field';
import { InfraTimerangeInput } from '../../../common/http_api/snapshot_api';
export const createTimeRangeWithInterval = async (
framework: KibanaFramework,

View file

@ -5,7 +5,6 @@
*/
import { isIPv4, getIPFromBucket, InfraSnapshotNodeGroupByBucket } from './response_helpers';
import { InfraNodeType } from '../../graphql/types';
describe('InfraOps ResponseHelpers', () => {
describe('isIPv4', () => {
@ -44,7 +43,7 @@ describe('InfraOps ResponseHelpers', () => {
},
},
};
expect(getIPFromBucket(InfraNodeType.host, bucket)).toBe('192.168.1.4');
expect(getIPFromBucket('host', bucket)).toBe('192.168.1.4');
});
it('should NOT return ipv6 address', () => {
const bucket: InfraSnapshotNodeGroupByBucket = {
@ -72,7 +71,7 @@ describe('InfraOps ResponseHelpers', () => {
},
},
};
expect(getIPFromBucket(InfraNodeType.host, bucket)).toBe(null);
expect(getIPFromBucket('host', bucket)).toBe(null);
});
});
});

View file

@ -7,15 +7,11 @@
import { isNumber, last, max, sum, get } from 'lodash';
import moment from 'moment';
import {
InfraSnapshotMetricType,
InfraSnapshotNodePath,
InfraSnapshotNodeMetric,
InfraNodeType,
} from '../../graphql/types';
import { getIntervalInSeconds } from '../../utils/get_interval_in_seconds';
import { InfraSnapshotRequestOptions } from './types';
import { findInventoryModel } from '../../../common/inventory_models';
import { InventoryItemType, SnapshotMetricType } from '../../../common/inventory_models/types';
import { SnapshotNodeMetric, SnapshotNodePath } from '../../../common/http_api/snapshot_api';
export interface InfraSnapshotNodeMetricsBucket {
key: { id: string };
@ -70,7 +66,7 @@ export interface InfraSnapshotNodeGroupByBucket {
export const isIPv4 = (subject: string) => /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(subject);
export const getIPFromBucket = (
nodeType: InfraNodeType,
nodeType: InventoryItemType,
bucket: InfraSnapshotNodeGroupByBucket
): string | null => {
const inventoryModel = findInventoryModel(nodeType);
@ -92,10 +88,10 @@ export const getIPFromBucket = (
export const getNodePath = (
groupBucket: InfraSnapshotNodeGroupByBucket,
options: InfraSnapshotRequestOptions
): InfraSnapshotNodePath[] => {
): SnapshotNodePath[] => {
const node = groupBucket.key;
const path = options.groupBy.map(gb => {
return { value: node[`${gb.field}`], label: node[`${gb.field}`] } as InfraSnapshotNodePath;
return { value: node[`${gb.field}`], label: node[`${gb.field}`] } as SnapshotNodePath;
});
const ip = getIPFromBucket(options.nodeType, groupBucket);
path.push({ value: node.id, label: node.name || node.id, ip });
@ -121,7 +117,7 @@ export const getNodeMetricsForLookup = (
export const getNodeMetrics = (
nodeBuckets: InfraSnapshotMetricsBucket[],
options: InfraSnapshotRequestOptions
): InfraSnapshotNodeMetric => {
): SnapshotNodeMetric => {
if (!nodeBuckets) {
return {
name: options.metric.type,
@ -156,18 +152,15 @@ const findLastFullBucket = (
}, last(buckets));
};
const getMetricValueFromBucket = (
type: InfraSnapshotMetricType,
bucket: InfraSnapshotMetricsBucket
) => {
const getMetricValueFromBucket = (type: SnapshotMetricType, bucket: InfraSnapshotMetricsBucket) => {
const metric = bucket[type];
return (metric && (metric.normalized_value || metric.value)) || 0;
};
function calculateMax(buckets: InfraSnapshotMetricsBucket[], type: InfraSnapshotMetricType) {
function calculateMax(buckets: InfraSnapshotMetricsBucket[], type: SnapshotMetricType) {
return max(buckets.map(bucket => getMetricValueFromBucket(type, bucket))) || 0;
}
function calculateAvg(buckets: InfraSnapshotMetricsBucket[], type: InfraSnapshotMetricType) {
function calculateAvg(buckets: InfraSnapshotMetricsBucket[], type: SnapshotMetricType) {
return sum(buckets.map(bucket => getMetricValueFromBucket(type, bucket))) / buckets.length || 0;
}

View file

@ -5,7 +5,6 @@
*/
import { RequestHandlerContext } from 'src/core/server';
import { InfraSnapshotNode } from '../../graphql/types';
import { InfraDatabaseSearchResponse } from '../adapters/framework';
import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
import { InfraSources } from '../sources';
@ -30,6 +29,7 @@ import { createAfterKeyHandler } from '../../utils/create_afterkey_handler';
import { findInventoryModel } from '../../../common/inventory_models';
import { InfraSnapshotRequestOptions } from './types';
import { createTimeRangeWithInterval } from './create_timerange_with_interval';
import { SnapshotNode } from '../../../common/http_api/snapshot_api';
export class InfraSnapshot {
constructor(private readonly libs: { sources: InfraSources; framework: KibanaFramework }) {}
@ -37,7 +37,7 @@ export class InfraSnapshot {
public async getNodes(
requestContext: RequestHandlerContext,
options: InfraSnapshotRequestOptions
): Promise<{ nodes: InfraSnapshotNode[]; interval: string }> {
): Promise<{ nodes: SnapshotNode[]; interval: string }> {
// Both requestGroupedNodes and requestNodeMetrics may send several requests to elasticsearch
// in order to page through the results of their respective composite aggregations.
// Both chains of requests are supposed to run in parallel, and their results be merged
@ -186,7 +186,7 @@ const mergeNodeBuckets = (
nodeGroupByBuckets: InfraSnapshotNodeGroupByBucket[],
nodeMetricsBuckets: InfraSnapshotNodeMetricsBucket[],
options: InfraSnapshotRequestOptions
): InfraSnapshotNode[] => {
): SnapshotNode[] => {
const nodeMetricsForLookup = getNodeMetricsForLookup(nodeMetricsBuckets);
return nodeGroupByBuckets.map(node => {

View file

@ -5,21 +5,11 @@
*/
import { JsonObject } from '../../../common/typed_json';
import {
InfraNodeType,
InfraSourceConfiguration,
InfraTimerangeInput,
InfraSnapshotGroupbyInput,
InfraSnapshotMetricInput,
} from '../../../public/graphql/types';
import { InfraSourceConfiguration } from '../../../public/graphql/types';
import { SnapshotRequest } from '../../../common/http_api/snapshot_api';
export interface InfraSnapshotRequestOptions {
nodeType: InfraNodeType;
export interface InfraSnapshotRequestOptions
extends Omit<SnapshotRequest, 'sourceId' | 'filterQuery'> {
sourceConfiguration: InfraSourceConfiguration;
timerange: InfraTimerangeInput;
groupBy: InfraSnapshotGroupbyInput[];
metric: InfraSnapshotMetricInput;
filterQuery: JsonObject | undefined;
accountId?: string;
region?: string;
}

View file

@ -8,7 +8,6 @@ import { first, set, startsWith } from 'lodash';
import { RequestHandlerContext } from 'src/core/server';
import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framework_adapter';
import { InfraSourceConfiguration } from '../../../lib/sources';
import { InfraNodeType } from '../../../graphql/types';
import { InfraMetadataInfo } from '../../../../common/http_api/metadata_api';
import { getPodNodeName } from './get_pod_node_name';
import { CLOUD_METRICS_MODULES } from '../../../lib/constants';
@ -27,7 +26,7 @@ export const getNodeInfo = async (
// can report pod details and we can't rely on the host/cloud information associated
// with the kubernetes.pod.uid. We need to first lookup the `kubernetes.node.name`
// then use that to lookup the host's node information.
if (nodeType === InfraNodeType.pod) {
if (nodeType === 'pod') {
const kubernetesNodeName = await getPodNodeName(
framework,
requestContext,
@ -41,7 +40,7 @@ export const getNodeInfo = async (
requestContext,
sourceConfiguration,
kubernetesNodeName,
InfraNodeType.host
'host'
);
}
return {};

View file

@ -6,11 +6,10 @@
import { InfraMetricModelMetricType } from '../../../lib/adapters/metrics';
import { MetricsExplorerRequestBody } from '../types';
import { InfraMetric } from '../../../graphql/types';
import { TSVBMetricModel } from '../../../../common/inventory_models/types';
export const createMetricModel = (options: MetricsExplorerRequestBody): TSVBMetricModel => {
return {
id: InfraMetric.custom,
id: 'custom',
requires: [],
index_pattern: options.indexPattern,
interval: options.timerange.interval,

View file

@ -11,7 +11,7 @@ import { identity } from 'fp-ts/lib/function';
import { InfraBackendLibs } from '../../lib/infra_types';
import { UsageCollector } from '../../usage/usage_collector';
import { InfraMetricsRequestOptions } from '../../lib/adapters/metrics';
import { InfraNodeType, InfraMetric } from '../../graphql/types';
import {
NodeDetailsRequestRT,
NodeDetailsMetricDataResponseRT,
@ -46,9 +46,9 @@ export const initNodeDetailsRoute = (libs: InfraBackendLibs) => {
nodeId,
cloudId,
},
nodeType: nodeType as InfraNodeType,
nodeType,
sourceConfiguration: source.configuration,
metrics: metrics as InfraMetric[],
metrics,
timerange,
};
return response.ok({

View file

@ -11,10 +11,8 @@ import { identity } from 'fp-ts/lib/function';
import { InfraBackendLibs } from '../../lib/infra_types';
import { UsageCollector } from '../../usage/usage_collector';
import { parseFilterQuery } from '../../utils/serialized_query';
import { InfraNodeType, InfraSnapshotMetricInput } from '../../../public/graphql/types';
import { SnapshotRequestRT, SnapshotNodeResponseRT } from '../../../common/http_api/snapshot_api';
import { throwErrors } from '../../../common/runtime_types';
import { InfraSnapshotRequestOptions } from '../../lib/snapshot/types';
const escapeHatch = schema.object({}, { allowUnknowns: true });
@ -46,16 +44,14 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
);
const source = await libs.sources.getSourceConfiguration(requestContext, sourceId);
UsageCollector.countNode(nodeType);
const options: InfraSnapshotRequestOptions = {
const options = {
filterQuery: parseFilterQuery(filterQuery),
accountId,
region,
// TODO: Use common infra metric and replace graphql type
nodeType: nodeType as InfraNodeType,
nodeType,
groupBy,
sourceConfiguration: source.configuration,
// TODO: Use common infra metric and replace graphql type
metric: metric as InfraSnapshotMetricInput,
metric,
timerange,
};
const nodesWithInterval = await libs.snapshot.getNodes(requestContext, options);

View file

@ -5,7 +5,6 @@
*/
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { InfraNodeType } from '../graphql/types';
import { InventoryItemType } from '../../common/inventory_models/types';
const KIBANA_REPORTING_TYPE = 'infraops';
@ -38,10 +37,10 @@ export class UsageCollector {
this.maybeInitializeBucket(bucket);
switch (nodeType) {
case InfraNodeType.pod:
case 'pod':
this.counters[bucket].infraopsKubernetes += 1;
break;
case InfraNodeType.container:
case 'container':
this.counters[bucket].infraopsDocker += 1;
break;
default:

View file

@ -5,9 +5,9 @@
*/
import { RequestHandlerContext } from 'src/core/server';
import { InfraNodeType } from '../graphql/types';
import { findInventoryModel } from '../../common/inventory_models';
import { KibanaFramework } from '../lib/adapters/framework/kibana_framework_adapter';
import { InventoryItemType } from '../../common/inventory_models/types';
interface Options {
indexPattern: string;
@ -27,7 +27,7 @@ export const calculateMetricInterval = async (
requestContext: RequestHandlerContext,
options: Options,
modules?: string[],
nodeType?: InfraNodeType // TODO: check that this type still makes sense
nodeType?: InventoryItemType // TODO: check that this type still makes sense
) => {
let from = options.timerange.from;
if (nodeType) {