Skip to content

Commit

Permalink
[Infra UI] Use new snapshot endpoint (#34938) (#35806)
Browse files Browse the repository at this point in the history
* Use new snapshot endpoint

* Remove old nodes endpoint

* Reintroduce NAME_FIELDS for displayable names.

* Use camelCase consistently.

* Distinguish node name and node id correctly.

* Adjust functional tests.

* Make prettier.

* Use exact same date histogram as before.

* Enable test for metric values again.

* Add test for new groupBy behaviour.

* Add 'Service Type' to groupBy fields.

* Fix date histogram offset and adjust tests.

* Always query for all metrics.
  • Loading branch information
skh authored Apr 30, 2019
1 parent 614ff20 commit 22333b3
Show file tree
Hide file tree
Showing 66 changed files with 276 additions and 2,465 deletions.
113 changes: 13 additions & 100 deletions x-pack/plugins/infra/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export interface InfraSource {
logSummaryBetween: InfraLogSummaryInterval;

logItem: InfraLogItem;
/** A hierarchy of hosts, pods, containers, services or arbitrary groups */
map?: InfraResponse | null;
/** A snapshot of nodes */
snapshot?: InfraSnapshotResponse | null;

Expand Down Expand Up @@ -199,32 +197,6 @@ export interface InfraLogItemField {
value: string;
}

export interface InfraResponse {
nodes: InfraNode[];
}

export interface InfraNode {
path: InfraNodePath[];

metric: InfraNodeMetric;
}

export interface InfraNodePath {
value: string;

label: string;
}

export interface InfraNodeMetric {
name: InfraMetricType;

value: number;

avg: number;

max: number;
}

export interface InfraSnapshotResponse {
/** Nodes of type host, container or pod grouped by 0, 1 or 2 terms */
nodes: InfraSnapshotNode[];
Expand Down Expand Up @@ -313,29 +285,6 @@ export interface InfraTimerangeInput {
from: number;
}

export interface InfraPathInput {
/** The type of path */
type: InfraPathType;
/** The label to use in the results for the group by for the terms group by */
label?: string | null;
/** The field to group by from a terms aggregation, this is ignored by the filter type */
field?: string | null;
/** The fitlers for the filter group by */
filters?: InfraPathFilterInput[] | null;
}
/** A group by filter */
export interface InfraPathFilterInput {
/** The label for the filter, this will be used as the group name in the final results */
label: string;
/** The query string query */
query: string;
}

export interface InfraMetricInput {
/** The type of metric */
type: InfraMetricType;
}

export interface InfraSnapshotGroupbyInput {
/** The label to use in the results for the group by for the terms group by */
label?: string | null;
Expand Down Expand Up @@ -463,11 +412,6 @@ export interface LogSummaryBetweenInfraSourceArgs {
export interface LogItemInfraSourceArgs {
id: string;
}
export interface MapInfraSourceArgs {
timerange: InfraTimerangeInput;

filterQuery?: string | null;
}
export interface SnapshotInfraSourceArgs {
timerange: InfraTimerangeInput;

Expand All @@ -485,11 +429,6 @@ export interface MetricsInfraSourceArgs {
export interface IndexFieldsInfraSourceStatusArgs {
indexType?: InfraIndexType | null;
}
export interface NodesInfraResponseArgs {
path: InfraPathInput[];

metric: InfraMetricInput;
}
export interface NodesInfraSnapshotResponseArgs {
type: InfraNodeType;

Expand Down Expand Up @@ -530,25 +469,6 @@ export enum InfraNodeType {
host = 'host',
}

export enum InfraPathType {
terms = 'terms',
filters = 'filters',
hosts = 'hosts',
pods = 'pods',
containers = 'containers',
custom = 'custom',
}

export enum InfraMetricType {
count = 'count',
cpu = 'cpu',
load = 'load',
memory = 'memory',
tx = 'tx',
rx = 'rx',
logRate = 'logRate',
}

export enum InfraSnapshotMetricType {
count = 'count',
cpu = 'cpu',
Expand Down Expand Up @@ -589,14 +509,6 @@ export enum InfraMetric {
nginxRequestsPerConnection = 'nginxRequestsPerConnection',
}

export enum InfraOperator {
gt = 'gt',
gte = 'gte',
lt = 'lt',
lte = 'lte',
eq = 'eq',
}

// ====================================================
// Unions
// ====================================================
Expand Down Expand Up @@ -872,8 +784,9 @@ export namespace WaffleNodesQuery {
sourceId: string;
timerange: InfraTimerangeInput;
filterQuery?: string | null;
metric: InfraMetricInput;
path: InfraPathInput[];
metric: InfraSnapshotMetricInput;
groupBy: InfraSnapshotGroupbyInput[];
type: InfraNodeType;
};

export type Query = {
Expand All @@ -887,41 +800,41 @@ export namespace WaffleNodesQuery {

id: string;

map?: Map | null;
snapshot?: Snapshot | null;
};

export type Map = {
__typename?: 'InfraResponse';
export type Snapshot = {
__typename?: 'InfraSnapshotResponse';

nodes: Nodes[];
};

export type Nodes = {
__typename?: 'InfraNode';
__typename?: 'InfraSnapshotNode';

path: Path[];

metric: Metric;
};

export type Path = {
__typename?: 'InfraNodePath';
__typename?: 'InfraSnapshotNodePath';

value: string;

label: string;
};

export type Metric = {
__typename?: 'InfraNodeMetric';
__typename?: 'InfraSnapshotNodeMetric';

name: InfraMetricType;
name: InfraSnapshotMetricType;

value: number;
value?: number | null;

avg: number;
avg?: number | null;

max: number;
max?: number | null;
};
}

Expand Down
22 changes: 11 additions & 11 deletions x-pack/plugins/infra/public/components/nodes_overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import React from 'react';

import euiStyled from '../../../../../common/eui_styled_components';
import {
InfraMetricType,
InfraNode,
InfraSnapshotMetricType,
InfraSnapshotNode,
InfraNodeType,
InfraTimerangeInput,
} from '../../graphql/types';
Expand All @@ -28,7 +28,7 @@ import { TableView } from './table';
interface Props {
options: InfraWaffleMapOptions;
nodeType: InfraNodeType;
nodes: InfraNode[];
nodes: InfraSnapshotNode[];
loading: boolean;
reload: () => void;
onDrilldown: (filter: KueryFilterQuery) => void;
Expand All @@ -51,24 +51,24 @@ interface MetricFormatters {
}

const METRIC_FORMATTERS: MetricFormatters = {
[InfraMetricType.count]: { formatter: InfraFormatterType.number, template: '{{value}}' },
[InfraMetricType.cpu]: {
[InfraSnapshotMetricType.count]: { formatter: InfraFormatterType.number, template: '{{value}}' },
[InfraSnapshotMetricType.cpu]: {
formatter: InfraFormatterType.percent,
template: '{{value}}',
},
[InfraMetricType.memory]: {
[InfraSnapshotMetricType.memory]: {
formatter: InfraFormatterType.percent,
template: '{{value}}',
},
[InfraMetricType.rx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraMetricType.tx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraMetricType.logRate]: {
[InfraSnapshotMetricType.rx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraSnapshotMetricType.tx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraSnapshotMetricType.logRate]: {
formatter: InfraFormatterType.abbreviatedNumber,
template: '{{value}}/s',
},
};

const calculateBoundsFromNodes = (nodes: InfraNode[]): InfraWaffleMapBounds => {
const calculateBoundsFromNodes = (nodes: InfraSnapshotNode[]): 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
Expand Down Expand Up @@ -187,7 +187,7 @@ export const NodesOverview = injectI18n(
const metricFormatter = get(
METRIC_FORMATTERS,
metric.type,
METRIC_FORMATTERS[InfraMetricType.count]
METRIC_FORMATTERS[InfraSnapshotMetricType.count]
);
if (val == null) {
return '';
Expand Down
12 changes: 8 additions & 4 deletions x-pack/plugins/infra/public/components/nodes_overview/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import { EuiButtonEmpty, EuiInMemoryTable, EuiToolTip } from '@elastic/eui';
import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { last } from 'lodash';
import React from 'react';
import { InfraNodeType } from '../../../server/lib/adapters/nodes';
import { createWaffleMapNode } from '../../containers/waffle/nodes_to_wafflemap';
import { InfraNode, InfraNodePath, InfraTimerangeInput } from '../../graphql/types';
import {
InfraSnapshotNode,
InfraSnapshotNodePath,
InfraTimerangeInput,
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';

interface Props {
nodes: InfraNode[];
nodes: InfraSnapshotNode[];
nodeType: InfraNodeType;
options: InfraWaffleMapOptions;
formatter: (subject: string | number) => string;
Expand All @@ -31,7 +35,7 @@ const initialState = {

type State = Readonly<typeof initialState>;

const getGroupPaths = (path: InfraNodePath[]) => {
const getGroupPaths = (path: InfraSnapshotNodePath[]) => {
switch (path.length) {
case 3:
return path.slice(0, 2);
Expand Down
11 changes: 1 addition & 10 deletions x-pack/plugins/infra/public/components/waffle/group_name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { EuiLink, EuiToolTip } from '@elastic/eui';
import React from 'react';

import euiStyled from '../../../../../common/eui_styled_components';
import { InfraPathType } from '../../graphql/types';
import { InfraWaffleMapGroup, InfraWaffleMapOptions } from '../../lib/lib';

interface Props {
Expand Down Expand Up @@ -47,15 +46,7 @@ export class GroupName extends React.PureComponent<Props, {}> {
return;
}
const currentPath = this.props.isChild && groupBy.length > 1 ? groupBy[1] : groupBy[0];
if (currentPath.type === InfraPathType.terms && currentPath.field) {
this.props.onDrilldown(`${currentPath.field}: "${this.props.group.name}"`);
}
if (currentPath.type === InfraPathType.filters && currentPath.filters) {
const currentFilter = currentPath.filters.find(f => f.label === this.props.group.name);
if (currentFilter) {
this.props.onDrilldown(currentFilter.query);
}
}
this.props.onDrilldown(`${currentPath.field}: "${this.props.group.name}"`);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const fieldToName = (field: string, intl: InjectedIntl) => {
id: 'xpack.infra.groupByDisplayNames.provider',
defaultMessage: 'Cloud Provider',
}),
'service.type': intl.formatMessage({
id: 'xpack.infra.groupByDisplayNames.serviceType',
defaultMessage: 'Service Type',
}),
};
return LOOKUP[field] || field;
};
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/components/waffle/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isWaffleMapGroupWithGroups,
isWaffleMapGroupWithNodes,
} from '../../containers/waffle/type_guards';
import { InfraNode, InfraNodeType, InfraTimerangeInput } from '../../graphql/types';
import { InfraSnapshotNode, InfraNodeType, InfraTimerangeInput } from '../../graphql/types';
import { InfraWaffleMapBounds, InfraWaffleMapOptions } from '../../lib/lib';
import { AutoSizer } from '../auto_sizer';
import { GroupOfGroups } from './group_of_groups';
Expand All @@ -20,7 +20,7 @@ import { Legend } from './legend';
import { applyWaffleMapLayout } from './lib/apply_wafflemap_layout';

interface Props {
nodes: InfraNode[];
nodes: InfraSnapshotNode[];
nodeType: InfraNodeType;
options: InfraWaffleMapOptions;
formatter: (subject: string | number) => string;
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/infra/public/components/waffle/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import React from 'react';

import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import euiStyled from '../../../../../common/eui_styled_components';
import { InfraNodeType } from '../../../server/lib/adapters/nodes';
import { InfraTimerangeInput } from '../../graphql/types';
import { InfraTimerangeInput, InfraNodeType } from '../../graphql/types';
import { InfraWaffleMapBounds, InfraWaffleMapNode, InfraWaffleMapOptions } from '../../lib/lib';
import { colorFromValue } from './lib/color_from_value';
import { NodeContextMenu } from './node_context_menu';
Expand Down
Loading

0 comments on commit 22333b3

Please sign in to comment.