Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infra UI] Add log rate to metrics on Waffle Map #23834

Merged
merged 9 commits into from
Oct 17, 2018
134 changes: 59 additions & 75 deletions x-pack/plugins/infra/common/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1315,15 +1315,29 @@
"name": "path",
"description": "",
"type": {
"kind": "LIST",
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "NON_NULL",
"kind": "LIST",
"name": null,
"ofType": { "kind": "INPUT_OBJECT", "name": "InfraPathInput", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "INPUT_OBJECT", "name": "InfraPathInput", "ofType": null }
}
}
},
"defaultValue": null
},
{
"name": "metric",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "INPUT_OBJECT", "name": "InfraMetricInput", "ofType": null }
},
"defaultValue": null
}
],
"type": {
Expand Down Expand Up @@ -1455,6 +1469,45 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "InfraMetricInput",
"description": "",
"fields": null,
"inputFields": [
{
"name": "type",
"description": "The type of metric",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "ENUM", "name": "InfraMetricType", "ofType": null }
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "InfraMetricType",
"description": "",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{ "name": "count", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "cpu", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "load", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "memory", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "tx", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "rx", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "logRate", "description": "", "isDeprecated": false, "deprecationReason": null }
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "InfraNode",
Expand All @@ -1481,44 +1534,13 @@
"deprecationReason": null
},
{
"name": "metrics",
"name": "metric",
"description": "",
"args": [
{
"name": "metrics",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "InfraMetricInput",
"ofType": null
}
}
}
},
"defaultValue": null
}
],
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "InfraNodeMetric", "ofType": null }
}
}
"ofType": { "kind": "OBJECT", "name": "InfraNodeMetric", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand Down Expand Up @@ -1552,44 +1574,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "InfraMetricInput",
"description": "",
"fields": null,
"inputFields": [
{
"name": "type",
"description": "The type of metric",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "ENUM", "name": "InfraMetricType", "ofType": null }
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "InfraMetricType",
"description": "",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{ "name": "count", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "cpu", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "load", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "memory", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "tx", "description": "", "isDeprecated": false, "deprecationReason": null },
{ "name": "rx", "description": "", "isDeprecated": false, "deprecationReason": null }
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "InfraNodeMetric",
Expand Down
25 changes: 11 additions & 14 deletions x-pack/plugins/infra/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface InfraResponse {

export interface InfraNode {
path: InfraNodePath[];
metrics: InfraNodeMetric[];
metric: InfraNodeMetric;
}

export interface InfraNodePath {
Expand Down Expand Up @@ -397,21 +397,19 @@ export namespace InfraResponseResolvers {

export type NodesResolver = Resolver<InfraNode[], NodesArgs>;
export interface NodesArgs {
path?: InfraPathInput[] | null;
path: InfraPathInput[];
metric: InfraMetricInput;
}
}

export namespace InfraNodeResolvers {
export interface Resolvers {
path?: PathResolver;
metrics?: MetricsResolver;
metric?: MetricResolver;
}

export type PathResolver = Resolver<InfraNodePath[]>;
export type MetricsResolver = Resolver<InfraNodeMetric[], MetricsArgs>;
export interface MetricsArgs {
metrics: InfraMetricInput[];
}
export type MetricResolver = Resolver<InfraNodeMetric>;
}

export namespace InfraNodePathResolvers {
Expand Down Expand Up @@ -532,10 +530,8 @@ export interface IndexFieldsInfraSourceStatusArgs {
indexType?: InfraIndexType | null;
}
export interface NodesInfraResponseArgs {
path?: InfraPathInput[] | null;
}
export interface MetricsInfraNodeArgs {
metrics: InfraMetricInput[];
path: InfraPathInput[];
metric: InfraMetricInput;
}

export enum InfraIndexType {
Expand Down Expand Up @@ -565,6 +561,7 @@ export enum InfraMetricType {
memory = 'memory',
tx = 'tx',
rx = 'rx',
logRate = 'logRate',
}

export enum InfraNodeType {
Expand Down Expand Up @@ -656,7 +653,7 @@ export namespace WaffleNodesQuery {
sourceId: string;
timerange: InfraTimerangeInput;
filterQuery?: string | null;
metrics: InfraMetricInput[];
metric: InfraMetricInput;
path: InfraPathInput[];
};

Expand All @@ -679,15 +676,15 @@ export namespace WaffleNodesQuery {
export type Nodes = {
__typename?: 'InfraNode';
path: Path[];
metrics: Metrics[];
metric: Metric;
};

export type Path = {
__typename?: 'InfraNodePath';
value: string;
};

export type Metrics = {
export type Metric = {
__typename?: 'InfraNodeMetric';
name: InfraMetricType;
value: number;
Expand Down
13 changes: 8 additions & 5 deletions x-pack/plugins/infra/public/components/waffle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { EuiButton, EuiEmptyPrompt } from '@elastic/eui';
import { get, last, max, min } from 'lodash';
import { get, max, min } from 'lodash';
import React from 'react';
import styled from 'styled-components';
import { InfraMetricType, InfraNodeType } from '../../../common/graphql/types';
Expand Down Expand Up @@ -59,6 +59,10 @@ const METRIC_FORMATTERS: MetricFormatters = {
},
[InfraMetricType.rx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraMetricType.tx]: { formatter: InfraFormatterType.bits, template: '{{value}}/s' },
[InfraMetricType.logRate]: {
formatter: InfraFormatterType.abbreviatedNumber,
template: '{{value}}/s',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the value really have the unit s? It depends on the histogram bucket size (AFAIK 1m on the waffle map right now). So we either use value with the same unit as the histogram bucket size or we use the normalized_value which should respect the 1s unit specified in the derivative agg, right?

I wonder if this also applies to the other rates like rx, which were already added previously?

Copy link
Member Author

@simianhacker simianhacker Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I totally over looked the normalized value when I was setting this up originally. I just added a commit to fix this.

},
};

const extractValuesFromMap = (groups: InfraWaffleMapGroup[], values: number[] = []): number[] => {
Expand All @@ -69,8 +73,7 @@ const extractValuesFromMap = (groups: InfraWaffleMapGroup[], values: number[] =
if (isWaffleMapGroupWithNodes(group)) {
return acc.concat(
group.nodes.map(node => {
const lastMetric = last(node.metrics);
return (lastMetric && lastMetric.value) || 0;
return node.metric.value || 0;
})
);
}
Expand Down Expand Up @@ -109,7 +112,7 @@ export class Waffle extends React.Component<Props, {}> {
/>
);
}
const metric = last(this.props.options.metrics);
const { metric } = this.props.options;
const metricFormatter = get(
METRIC_FORMATTERS,
metric.type,
Expand Down Expand Up @@ -139,7 +142,7 @@ export class Waffle 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 = last(this.props.options.metrics);
const { metric } = this.props.options;
const metricFormatter = get(
METRIC_FORMATTERS,
metric.type,
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 @@ -5,7 +5,6 @@
*/

import { EuiToolTip } from '@elastic/eui';
import { last } from 'lodash';
import { darken, readableColor } from 'polished';
import React from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -35,7 +34,7 @@ export class Node extends React.PureComponent<Props, State> {
public render() {
const { nodeType, node, options, squareSize, bounds, formatter } = this.props;
const { isPopoverOpen } = this.state;
const metric = last(node.metrics);
const { metric } = node;
const valueMode = squareSize > 110;
const rawValue = (metric && metric.value) || 0;
const color = colorFromValue(options.legend, rawValue, bounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import {
EuiFilterGroup,
EuiPopover,
} from '@elastic/eui';
import { last } from 'lodash';
import React from 'react';
import { InfraMetricInput, InfraMetricType, InfraNodeType } from '../../../common/graphql/types';
interface Props {
nodeType: InfraNodeType;
metrics: InfraMetricInput[];
onChange: (metrics: InfraMetricInput[]) => void;
metric: InfraMetricInput;
onChange: (metric: InfraMetricInput) => void;
}

const OPTIONS = {
Expand All @@ -39,6 +38,7 @@ const OPTIONS = {
{ text: 'Load', value: InfraMetricType.load },
{ text: 'Inbound Traffic', value: InfraMetricType.rx },
{ text: 'Outbound Traffic', value: InfraMetricType.tx },
{ text: 'Log Rate', value: InfraMetricType.logRate },
],
};

Expand All @@ -50,13 +50,13 @@ type State = Readonly<typeof initialState>;
export class WaffleMetricControls extends React.PureComponent<Props, State> {
public readonly state: State = initialState;
public render() {
const currentMetric = last(this.props.metrics);
const { metric } = this.props;
const options = OPTIONS[this.props.nodeType];
const value = currentMetric.type;
const value = metric.type;
if (!options.length || !value) {
throw Error('Unable to select options or value for metric.');
}
const currentLabel = options.find(o => o.value === currentMetric.type);
const currentLabel = options.find(o => o.value === metric.type);
if (!currentLabel) {
return 'null';
}
Expand All @@ -65,7 +65,7 @@ export class WaffleMetricControls extends React.PureComponent<Props, State> {
id: 0,
title: '',
items: options.map(o => {
const icon = o.value === currentMetric.type ? 'check' : 'empty';
const icon = o.value === metric.type ? 'check' : 'empty';
const panel = { name: o.text, onClick: this.handleClick(o.value), icon };
return panel;
}),
Expand Down Expand Up @@ -100,7 +100,7 @@ export class WaffleMetricControls extends React.PureComponent<Props, State> {
};

private handleClick = (value: InfraMetricType) => () => {
this.props.onChange([{ type: value }]);
this.props.onChange({ type: value });
this.handleClose();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Props {
nodeType: InfraNodeType;
changeNodeType: (nodeType: InfraNodeType) => void;
changeGroupBy: (groupBy: InfraPathInput[]) => void;
changeMetrics: (metric: InfraMetricInput[]) => void;
changeMetric: (metric: InfraMetricInput) => void;
}

export class WaffleNodeTypeSwitcher extends React.PureComponent<Props> {
Expand All @@ -40,6 +40,6 @@ export class WaffleNodeTypeSwitcher extends React.PureComponent<Props> {
private handleClick = (nodeType: InfraNodeType) => () => {
this.props.changeNodeType(nodeType);
this.props.changeGroupBy([]);
this.props.changeMetrics([{ type: InfraMetricType.cpu }]);
this.props.changeMetric({ type: InfraMetricType.cpu });
};
}
Loading