Skip to content

Commit

Permalink
Adding initial code for EC2
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Nov 1, 2019
1 parent 82f3f16 commit c100f30
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export const sharedSchema = gql`
pod
container
host
awsEC2
}
`;
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/infra/common/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ export enum InfraNodeType {
pod = 'pod',
container = 'container',
host = 'host',
awsEC2 = 'awsEC2',
}

export enum InfraSnapshotMetricType {
Expand All @@ -562,6 +563,8 @@ export enum InfraSnapshotMetricType {
tx = 'tx',
rx = 'rx',
logRate = 'logRate',
diskIOReadBytes = 'diskIOReadBytes',
diskIOWriteBytes = 'diskIOWriteBytes',
}

export enum InfraMetric {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { InventoryModel } from '../types';
export const container: InventoryModel = {
id: 'container',
requiredModules: ['docker'],
fields: {
id: 'container.id',
name: 'container.name',
ip: 'continaer.ip_address',
},
metrics,
requiredMetrics: [
'containerOverview',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
export const host: InventoryModel = {
id: 'host',
requiredModules: ['system'],
fields: {
id: 'host.name',
name: 'host.name',
ip: 'host.ip',
},
metrics,
requiredMetrics: [
'hostSystemOverview',
Expand Down
38 changes: 37 additions & 1 deletion x-pack/legacy/plugins/infra/common/inventory_models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import { i18n } from '@kbn/i18n';
import { host } from './host';
import { pod } from './pod';
import { awsEC2 } from './aws_ec2';
import { container } from './container';
import { InventoryItemType } from './types';
export { metrics } from './metrics';

const inventoryModels = [host, pod, container];
const inventoryModels = [host, pod, container, awsEC2];

export const findInventoryModel = (type: InventoryItemType) => {
const model = inventoryModels.find(m => m.id === type);
Expand All @@ -24,3 +25,38 @@ export const findInventoryModel = (type: InventoryItemType) => {
}
return model;
};

interface InventoryFields {
message: string[];
host: string;
pod: string;
container: string;
timestamp: string;
tiebreaker: string;
}

const LEGACY_TYPES = ['host', 'pod', 'container'];

const getFieldByType = (type: InventoryItemType, fields: InventoryFields) => {
switch (type) {
case 'pod':
return fields.pod;
case 'host':
return fields.host;
case 'container':
return fields.container;
}
};

export const findInventoryFields = (type: InventoryItemType, fields: InventoryFields) => {
const inventoryModel = findInventoryModel(type);
if (LEGACY_TYPES.includes(type)) {
const id = getFieldByType(type, fields) || inventoryModel.fields.id;
return {
...inventoryModel.fields,
id,
};
} else {
return inventoryModel.fields;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { nginx as nginxRequiredMetrics } from '../shared/metrics/required_metric
export const pod: InventoryModel = {
id: 'pod',
requiredModules: ['kubernetes'],
fields: {
id: 'kubernetes.pod.uid',
name: 'kubernetes.pod.name',
ip: 'kubernetes.pod.ip',
},
metrics,
requiredMetrics: [
'podOverview',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HostToolbarItems } from './host/toolbar_items';
import { ContainerToolbarItems } from './container/toolbar_items';
import { PodToolbarItems } from './pod/toolbar_items';
import { ToolbarProps } from '../../public/components/inventory/toolbars/toolbar';
import { AwsEC2ToolbarItems } from './aws_ec2/toolbar_items';

interface Toolbars {
[type: string]: ReactNode;
Expand All @@ -21,6 +22,7 @@ const toolbars: Toolbars = {
host: HostToolbarItems,
container: ContainerToolbarItems,
pod: PodToolbarItems,
awsEC2: AwsEC2ToolbarItems,
};

export const findToolbar = (type: InventoryItemType) => {
Expand Down
8 changes: 7 additions & 1 deletion x-pack/legacy/plugins/infra/common/inventory_models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import * as rt from 'io-ts';
import { InfraSnapshotMetricType } from '../graphql/types';

export const ItemTypeRT = rt.keyof({
host: null,
Expand Down Expand Up @@ -268,6 +267,8 @@ export const SnapshotMetricTypeRT = rt.keyof({
tx: null,
rx: null,
logRate: null,
diskIOReadBytes: null,
diskIOWriteBytes: null,
});

export type SnapshotMetricType = rt.TypeOf<typeof SnapshotMetricTypeRT>;
Expand All @@ -281,6 +282,11 @@ export interface InventoryMetrics {
export interface InventoryModel {
id: string;
requiredModules: string[];
fields: {
id: string;
name: string;
ip: string;
};
metrics: InventoryMetrics;
requiredMetrics: InventoryMetric[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const ToolbarTranslations = {
Count: i18n.translate('xpack.infra.waffle.metricOptions.countText', {
defaultMessage: 'Count',
}),
DiskIOReadBytes: i18n.translate('xpack.infra.waffle.metricOptions.diskIOReadBytes', {
defaultMessage: 'Disk Reads',
}),
DiskIOWriteBytes: i18n.translate('xpack.infra.waffle.metricOptions.diskIOWriteBytes', {
defaultMessage: 'Disk Writes',
}),
};

export const toGroupByOpt = (field: string) => ({
Expand Down Expand Up @@ -126,5 +132,15 @@ export const toMetricOpt = (metric: InfraSnapshotMetricType) => {
text: ToolbarTranslations.Count,
value: InfraSnapshotMetricType.count,
};
case InfraSnapshotMetricType.diskIOReadBytes:
return {
text: ToolbarTranslations.DiskIOReadBytes,
value: InfraSnapshotMetricType.diskIOReadBytes,
};
case InfraSnapshotMetricType.diskIOWriteBytes:
return {
text: ToolbarTranslations.DiskIOWriteBytes,
value: InfraSnapshotMetricType.diskIOWriteBytes,
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ interface Lookup {
[id: string]: string;
}

const availabilityZoneName = i18n.translate('xpack.infra.groupByDisplayNames.availabilityZone', {
defaultMessage: 'Availability zone',
});

const machineTypeName = i18n.translate('xpack.infra.groupByDisplayNames.machineType', {
defaultMessage: 'Machine type',
});

export const fieldToName = (field: string) => {
const LOOKUP: Lookup = {
'kubernetes.namespace': i18n.translate('xpack.infra.groupByDisplayNames.kubernetesNamespace', {
Expand All @@ -21,12 +29,8 @@ export const fieldToName = (field: string) => {
'host.name': i18n.translate('xpack.infra.groupByDisplayNames.hostName', {
defaultMessage: 'Host',
}),
'cloud.availability_zone': i18n.translate('xpack.infra.groupByDisplayNames.availabilityZone', {
defaultMessage: 'Availability zone',
}),
'cloud.machine.type': i18n.translate('xpack.infra.groupByDisplayNames.machineType', {
defaultMessage: 'Machine type',
}),
'cloud.availability_zone': availabilityZoneName,
'cloud.machine.type': machineTypeName,
'cloud.project.id': i18n.translate('xpack.infra.groupByDisplayNames.projectID', {
defaultMessage: 'Project ID',
}),
Expand All @@ -36,6 +40,17 @@ export const fieldToName = (field: string) => {
'service.type': i18n.translate('xpack.infra.groupByDisplayNames.serviceType', {
defaultMessage: 'Service type',
}),
'aws.cloud.availability_zone': availabilityZoneName,
'aws.cloud.machine.type': machineTypeName,
'aws.tags': i18n.translate('xpack.infra.groupByDisplayNames.tags', {
defaultMessage: 'Tags',
}),
'aws.ec2.instance.image.id': i18n.translate('xpack.infra.groupByDisplayNames.image', {
defaultMessage: 'Image',
}),
'aws.ec2.instance.state.name': i18n.translate('xpack.infra.groupByDisplayNames.state.name', {
defaultMessage: 'State',
}),
};
return LOOKUP[field] || field;
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const NodeContextMenu = injectUICapabilities(
[InfraNodeType.host]: 'host.hostname',
[InfraNodeType.container]: 'container.id',
[InfraNodeType.pod]: 'kubernetes.pod.uid',
[InfraNodeType.awsEC2]: 'cloud.instance.id',
};

const nodeLogsMenuItem = {
Expand Down
Loading

0 comments on commit c100f30

Please sign in to comment.