diff --git a/x-pack/legacy/plugins/infra/index.ts b/x-pack/legacy/plugins/infra/index.ts index 196950b51be3a..ced94d30bf747 100644 --- a/x-pack/legacy/plugins/infra/index.ts +++ b/x-pack/legacy/plugins/infra/index.ts @@ -7,17 +7,6 @@ import { i18n } from '@kbn/i18n'; import JoiNamespace from 'joi'; import { resolve } from 'path'; -import { PluginInitializerContext } from 'src/core/server'; -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import KbnServer from 'src/legacy/server/kbn_server'; -import { getConfigSchema } from './server/kibana.index'; -import { savedObjectMappings } from './server/saved_objects'; -import { plugin, InfraServerPluginDeps } from './server/new_platform_index'; -import { InfraSetup } from '../../../plugins/infra/server'; -import { PluginSetupContract as FeaturesPluginSetup } from '../../../plugins/features/server'; -import { SpacesPluginSetup } from '../../../plugins/spaces/server'; -import { VisTypeTimeseriesSetup } from '../../../../src/plugins/vis_type_timeseries/server'; -import { APMPluginContract } from '../../../plugins/apm/server'; export const APP_ID = 'infra'; @@ -70,45 +59,24 @@ export function infra(kibana: any) { url: `/app/${APP_ID}#/logs`, }, ], - mappings: savedObjectMappings, + // mappings: savedObjectMappings, }, config(Joi: typeof JoiNamespace) { - return getConfigSchema(Joi); + return Joi.object({ + enabled: Joi.boolean().default(true), + }) + .unknown() + .default(); }, init(legacyServer: any) { - const { newPlatform } = legacyServer as KbnServer; - const { core, plugins } = newPlatform.setup; - - const infraSetup = (plugins.infra as unknown) as InfraSetup; // chef's kiss - - const initContext = ({ - config: infraSetup.__legacy.config, - } as unknown) as PluginInitializerContext; - // NP_TODO: Use real types from the other plugins as they are migrated - const pluginDeps: InfraServerPluginDeps = { - home: legacyServer.newPlatform.setup.plugins.home, - usageCollection: plugins.usageCollection as UsageCollectionSetup, - indexPatterns: { - indexPatternsServiceFactory: legacyServer.indexPatternsServiceFactory, + // NP_TODO: How do we move this to new platform? + legacyServer.addAppLinksToSampleDataset('logs', [ + { + path: `/app/${APP_ID}#/logs`, + label: logsSampleDataLinkLabel, + icon: 'logsApp', }, - metrics: plugins.metrics as VisTypeTimeseriesSetup, - spaces: plugins.spaces as SpacesPluginSetup, - features: plugins.features as FeaturesPluginSetup, - apm: plugins.apm as APMPluginContract, - }; - - const infraPluginInstance = plugin(initContext); - infraPluginInstance.setup(core, pluginDeps); - - // NP_TODO: EVERYTHING BELOW HERE IS LEGACY - - const libs = infraPluginInstance.getLibs(); - - // NP_NOTE: Left here for now for legacy plugins to consume - legacyServer.expose( - 'defineInternalSourceConfiguration', - libs.sources.defineInternalSourceConfiguration.bind(libs.sources) - ); + ]); }, }); } diff --git a/x-pack/legacy/plugins/infra/server/new_platform_index.ts b/x-pack/legacy/plugins/infra/server/new_platform_index.ts deleted file mode 100644 index e59897a6b241d..0000000000000 --- a/x-pack/legacy/plugins/infra/server/new_platform_index.ts +++ /dev/null @@ -1,15 +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 { PluginInitializerContext } from 'src/core/server'; -import { InfraServerPlugin, InfraPluginSetup } from './new_platform_plugin'; -import { config, InfraConfig } from '../../../../plugins/infra/server'; -import { InfraServerPluginDeps } from './lib/adapters/framework'; -export { config, InfraConfig, InfraServerPluginDeps, InfraPluginSetup }; - -export function plugin(context: PluginInitializerContext) { - return new InfraServerPlugin(context); -} diff --git a/x-pack/legacy/plugins/infra/server/saved_objects.ts b/x-pack/legacy/plugins/infra/server/saved_objects.ts deleted file mode 100644 index 2e554300b0ecb..0000000000000 --- a/x-pack/legacy/plugins/infra/server/saved_objects.ts +++ /dev/null @@ -1,15 +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 { infraSourceConfigurationSavedObjectMappings } from './lib/sources'; -import { metricsExplorerViewSavedObjectMappings } from '../common/saved_objects/metrics_explorer_view'; -import { inventoryViewSavedObjectMappings } from '../common/saved_objects/inventory_view'; - -export const savedObjectMappings = { - ...infraSourceConfigurationSavedObjectMappings, - ...metricsExplorerViewSavedObjectMappings, - ...inventoryViewSavedObjectMappings, -}; diff --git a/x-pack/legacy/plugins/monitoring/index.js b/x-pack/legacy/plugins/monitoring/index.js index 3d98b11c2045b..1a7cbac9a167b 100644 --- a/x-pack/legacy/plugins/monitoring/index.js +++ b/x-pack/legacy/plugins/monitoring/index.js @@ -84,6 +84,6 @@ export const monitoring = kibana => uiExports: getUiExports(), postInit(server) { const serverConfig = server.config(); - initInfraSource(serverConfig, server.plugins.infra); + initInfraSource(serverConfig, server.newPlatform.setup.plugins.infra); }, }); diff --git a/x-pack/plugins/infra/common/color_palette.test.ts b/x-pack/plugins/infra/common/color_palette.test.ts new file mode 100644 index 0000000000000..ce0219862480d --- /dev/null +++ b/x-pack/plugins/infra/common/color_palette.test.ts @@ -0,0 +1,38 @@ +/* + * 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 { sampleColor, MetricsExplorerColor, colorTransformer } from './color_palette'; +describe('Color Palette', () => { + describe('sampleColor()', () => { + it('should just work', () => { + const usedColors = [MetricsExplorerColor.color0]; + const color = sampleColor(usedColors); + expect(color).toBe(MetricsExplorerColor.color1); + }); + + it('should return color0 when nothing is available', () => { + const usedColors = [ + MetricsExplorerColor.color0, + MetricsExplorerColor.color1, + MetricsExplorerColor.color2, + MetricsExplorerColor.color3, + MetricsExplorerColor.color4, + MetricsExplorerColor.color5, + MetricsExplorerColor.color6, + MetricsExplorerColor.color7, + MetricsExplorerColor.color8, + MetricsExplorerColor.color9, + ]; + const color = sampleColor(usedColors); + expect(color).toBe(MetricsExplorerColor.color0); + }); + }); + describe('colorTransformer()', () => { + it('should just work', () => { + expect(colorTransformer(MetricsExplorerColor.color0)).toBe('#3185FC'); + }); + }); +}); diff --git a/x-pack/plugins/infra/common/color_palette.ts b/x-pack/plugins/infra/common/color_palette.ts new file mode 100644 index 0000000000000..c43c17b9b0ef3 --- /dev/null +++ b/x-pack/plugins/infra/common/color_palette.ts @@ -0,0 +1,56 @@ +/* + * 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 { difference, first, values } from 'lodash'; + +export enum MetricsExplorerColor { + color0 = 'color0', + color1 = 'color1', + color2 = 'color2', + color3 = 'color3', + color4 = 'color4', + color5 = 'color5', + color6 = 'color6', + color7 = 'color7', + color8 = 'color8', + color9 = 'color9', +} + +export interface MetricsExplorerPalette { + [MetricsExplorerColor.color0]: string; + [MetricsExplorerColor.color1]: string; + [MetricsExplorerColor.color2]: string; + [MetricsExplorerColor.color3]: string; + [MetricsExplorerColor.color4]: string; + [MetricsExplorerColor.color5]: string; + [MetricsExplorerColor.color6]: string; + [MetricsExplorerColor.color7]: string; + [MetricsExplorerColor.color8]: string; + [MetricsExplorerColor.color9]: string; +} + +export const defaultPalette: MetricsExplorerPalette = { + [MetricsExplorerColor.color0]: '#3185FC', // euiColorVis1 (blue) + [MetricsExplorerColor.color1]: '#DB1374', // euiColorVis2 (red-ish) + [MetricsExplorerColor.color2]: '#00B3A4', // euiColorVis0 (green-ish) + [MetricsExplorerColor.color3]: '#490092', // euiColorVis3 (purple) + [MetricsExplorerColor.color4]: '#FEB6DB', // euiColorVis4 (pink) + [MetricsExplorerColor.color5]: '#E6C220', // euiColorVis5 (yellow) + [MetricsExplorerColor.color6]: '#BFA180', // euiColorVis6 (tan) + [MetricsExplorerColor.color7]: '#F98510', // euiColorVis7 (orange) + [MetricsExplorerColor.color8]: '#461A0A', // euiColorVis8 (brown) + [MetricsExplorerColor.color9]: '#920000', // euiColorVis9 (maroon) +}; + +export const createPaletteTransformer = (palette: MetricsExplorerPalette) => ( + color: MetricsExplorerColor +) => palette[color]; + +export const colorTransformer = createPaletteTransformer(defaultPalette); + +export const sampleColor = (usedColors: MetricsExplorerColor[] = []): MetricsExplorerColor => { + const available = difference(values(MetricsExplorerColor) as MetricsExplorerColor[], usedColors); + return first(available) || MetricsExplorerColor.color0; +}; diff --git a/x-pack/plugins/infra/common/ecs_allowed_list.test.ts b/x-pack/plugins/infra/common/ecs_allowed_list.test.ts new file mode 100644 index 0000000000000..66ed681255d34 --- /dev/null +++ b/x-pack/plugins/infra/common/ecs_allowed_list.test.ts @@ -0,0 +1,42 @@ +/* + * 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 { + getAllowedListForPrefix, + ECS_ALLOWED_LIST, + K8S_ALLOWED_LIST, + PROMETHEUS_ALLOWED_LIST, + DOCKER_ALLOWED_LIST, +} from './ecs_allowed_list'; +describe('getAllowedListForPrefix()', () => { + test('kubernetes', () => { + expect(getAllowedListForPrefix('kubernetes.pod')).toEqual([ + ...ECS_ALLOWED_LIST, + 'kubernetes.pod', + ...K8S_ALLOWED_LIST, + ]); + }); + test('docker', () => { + expect(getAllowedListForPrefix('docker.container')).toEqual([ + ...ECS_ALLOWED_LIST, + 'docker.container', + ...DOCKER_ALLOWED_LIST, + ]); + }); + test('prometheus', () => { + expect(getAllowedListForPrefix('prometheus.metrics')).toEqual([ + ...ECS_ALLOWED_LIST, + 'prometheus.metrics', + ...PROMETHEUS_ALLOWED_LIST, + ]); + }); + test('anything.else', () => { + expect(getAllowedListForPrefix('anything.else')).toEqual([ + ...ECS_ALLOWED_LIST, + 'anything.else', + ]); + }); +}); diff --git a/x-pack/plugins/infra/common/ecs_allowed_list.ts b/x-pack/plugins/infra/common/ecs_allowed_list.ts new file mode 100644 index 0000000000000..1728cd1fa4b45 --- /dev/null +++ b/x-pack/plugins/infra/common/ecs_allowed_list.ts @@ -0,0 +1,67 @@ +/* + * 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 { first } from 'lodash'; + +export const ECS_ALLOWED_LIST = [ + 'host', + 'cloud', + 'event', + 'agent', + 'fields', + 'service', + 'ecs', + 'metricset', + 'tags', + 'message', + 'labels', + '@timestamp', + 'source', + 'container', +]; + +export const K8S_ALLOWED_LIST = [ + 'kubernetes.pod.name', + 'kubernetes.pod.uid', + 'kubernetes.namespace', + 'kubernetes.node.name', + 'kubernetes.labels', + 'kubernetes.annotations', + 'kubernetes.replicaset.name', + 'kubernetes.deployment.name', + 'kubernetes.statefulset.name', + 'kubernetes.container.name', + 'kubernetes.container.image', +]; + +export const PROMETHEUS_ALLOWED_LIST = ['prometheus.labels', 'prometheus.metrics']; + +export const DOCKER_ALLOWED_LIST = [ + 'docker.container.id', + 'docker.container.image', + 'docker.container.name', + 'docker.container.labels', +]; + +export const AWS_S3_ALLOWED_LIST = ['aws.s3']; + +export const getAllowedListForPrefix = (prefix: string) => { + const firstPart = first(prefix.split(/\./)); + const defaultAllowedList = prefix ? [...ECS_ALLOWED_LIST, prefix] : ECS_ALLOWED_LIST; + switch (firstPart) { + case 'docker': + return [...defaultAllowedList, ...DOCKER_ALLOWED_LIST]; + case 'prometheus': + return [...defaultAllowedList, ...PROMETHEUS_ALLOWED_LIST]; + case 'kubernetes': + return [...defaultAllowedList, ...K8S_ALLOWED_LIST]; + case 'aws': + if (prefix === 'aws.s3_daily_storage') { + return [...defaultAllowedList, ...AWS_S3_ALLOWED_LIST]; + } + default: + return defaultAllowedList; + } +}; diff --git a/x-pack/plugins/infra/common/errors/index.ts b/x-pack/plugins/infra/common/errors/index.ts new file mode 100644 index 0000000000000..88b76eb0ef775 --- /dev/null +++ b/x-pack/plugins/infra/common/errors/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './metrics'; diff --git a/x-pack/plugins/infra/common/errors/metrics.ts b/x-pack/plugins/infra/common/errors/metrics.ts new file mode 100644 index 0000000000000..2acf2b741cec9 --- /dev/null +++ b/x-pack/plugins/infra/common/errors/metrics.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export enum InfraMetricsErrorCodes { + // eslint-disable-next-line @typescript-eslint/camelcase + invalid_node = 'METRICS_INVALID_NODE', +} diff --git a/x-pack/plugins/infra/common/graphql/root/index.ts b/x-pack/plugins/infra/common/graphql/root/index.ts new file mode 100644 index 0000000000000..47417b6376307 --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/root/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export { rootSchema } from './schema.gql'; diff --git a/x-pack/plugins/infra/common/graphql/root/schema.gql.ts b/x-pack/plugins/infra/common/graphql/root/schema.gql.ts new file mode 100644 index 0000000000000..1665334827e8e --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/root/schema.gql.ts @@ -0,0 +1,18 @@ +/* + * 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 gql from 'graphql-tag'; + +export const rootSchema = gql` + schema { + query: Query + mutation: Mutation + } + + type Query + + type Mutation +`; diff --git a/x-pack/plugins/infra/common/graphql/shared/fragments.gql_query.ts b/x-pack/plugins/infra/common/graphql/shared/fragments.gql_query.ts new file mode 100644 index 0000000000000..c324813b65efb --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/shared/fragments.gql_query.ts @@ -0,0 +1,81 @@ +/* + * 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 gql from 'graphql-tag'; + +export const sharedFragments = { + InfraTimeKey: gql` + fragment InfraTimeKeyFields on InfraTimeKey { + time + tiebreaker + } + `, + InfraSourceFields: gql` + fragment InfraSourceFields on InfraSource { + id + version + updatedAt + origin + } + `, + InfraLogEntryFields: gql` + fragment InfraLogEntryFields on InfraLogEntry { + gid + key { + time + tiebreaker + } + columns { + ... on InfraLogEntryTimestampColumn { + columnId + timestamp + } + ... on InfraLogEntryMessageColumn { + columnId + message { + ... on InfraLogMessageFieldSegment { + field + value + } + ... on InfraLogMessageConstantSegment { + constant + } + } + } + ... on InfraLogEntryFieldColumn { + columnId + field + value + } + } + } + `, + InfraLogEntryHighlightFields: gql` + fragment InfraLogEntryHighlightFields on InfraLogEntry { + gid + key { + time + tiebreaker + } + columns { + ... on InfraLogEntryMessageColumn { + columnId + message { + ... on InfraLogMessageFieldSegment { + field + highlights + } + } + } + ... on InfraLogEntryFieldColumn { + columnId + field + highlights + } + } + } + `, +}; diff --git a/x-pack/plugins/infra/common/graphql/shared/index.ts b/x-pack/plugins/infra/common/graphql/shared/index.ts new file mode 100644 index 0000000000000..56c8675e76caf --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/shared/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export { sharedFragments } from './fragments.gql_query'; +export { sharedSchema } from './schema.gql'; diff --git a/x-pack/plugins/infra/common/graphql/shared/schema.gql.ts b/x-pack/plugins/infra/common/graphql/shared/schema.gql.ts new file mode 100644 index 0000000000000..071313817eff3 --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/shared/schema.gql.ts @@ -0,0 +1,38 @@ +/* + * 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 gql from 'graphql-tag'; + +export const sharedSchema = gql` + "A representation of the log entry's position in the event stream" + type InfraTimeKey { + "The timestamp of the event that the log entry corresponds to" + time: Float! + "The tiebreaker that disambiguates events with the same timestamp" + tiebreaker: Float! + } + + input InfraTimeKeyInput { + time: Float! + tiebreaker: Float! + } + + enum InfraIndexType { + ANY + LOGS + METRICS + } + + enum InfraNodeType { + pod + container + host + awsEC2 + awsS3 + awsRDS + awsSQS + } +`; diff --git a/x-pack/plugins/infra/common/graphql/types.ts b/x-pack/plugins/infra/common/graphql/types.ts new file mode 100644 index 0000000000000..bb089bf8bf8ad --- /dev/null +++ b/x-pack/plugins/infra/common/graphql/types.ts @@ -0,0 +1,1109 @@ +/* tslint:disable */ + +// ==================================================== +// START: Typescript template +// ==================================================== + +// ==================================================== +// Types +// ==================================================== + +export interface Query { + /** Get an infrastructure data source by id.The resolution order for the source configuration attributes is as followswith the first defined value winning:1. The attributes of the saved object with the given 'id'.2. The attributes defined in the static Kibana configuration key'xpack.infra.sources.default'.3. The hard-coded default values.As a consequence, querying a source that doesn't exist doesn't error out,but returns the configured or hardcoded defaults. */ + source: InfraSource; + /** Get a list of all infrastructure data sources */ + allSources: InfraSource[]; +} +/** A source of infrastructure data */ +export interface InfraSource { + /** The id of the source */ + id: string; + /** The version number the source configuration was last persisted with */ + version?: string | null; + /** The timestamp the source configuration was last persisted at */ + updatedAt?: number | null; + /** The origin of the source (one of 'fallback', 'internal', 'stored') */ + origin: string; + /** The raw configuration of the source */ + configuration: InfraSourceConfiguration; + /** The status of the source */ + status: InfraSourceStatus; + /** A consecutive span of log entries surrounding a point in time */ + logEntriesAround: InfraLogEntryInterval; + /** A consecutive span of log entries within an interval */ + logEntriesBetween: InfraLogEntryInterval; + /** Sequences of log entries matching sets of highlighting queries within an interval */ + logEntryHighlights: InfraLogEntryInterval[]; + + /** A snapshot of nodes */ + snapshot?: InfraSnapshotResponse | null; + + metrics: InfraMetricData[]; +} +/** A set of configuration options for an infrastructure data source */ +export interface InfraSourceConfiguration { + /** The name of the data source */ + name: string; + /** A description of the data source */ + description: string; + /** The alias to read metric data from */ + metricAlias: string; + /** The alias to read log data from */ + logAlias: string; + /** The field mapping to use for this source */ + fields: InfraSourceFields; + /** The columns to use for log display */ + logColumns: InfraSourceLogColumn[]; +} +/** A mapping of semantic fields to their document counterparts */ +export interface InfraSourceFields { + /** The field to identify a container by */ + container: string; + /** The fields to identify a host by */ + host: string; + /** The fields to use as the log message */ + message: string[]; + /** The field to identify a pod by */ + pod: string; + /** The field to use as a tiebreaker for log events that have identical timestamps */ + tiebreaker: string; + /** The field to use as a timestamp for metrics and logs */ + timestamp: string; +} +/** The built-in timestamp log column */ +export interface InfraSourceTimestampLogColumn { + timestampColumn: InfraSourceTimestampLogColumnAttributes; +} + +export interface InfraSourceTimestampLogColumnAttributes { + /** A unique id for the column */ + id: string; +} +/** The built-in message log column */ +export interface InfraSourceMessageLogColumn { + messageColumn: InfraSourceMessageLogColumnAttributes; +} + +export interface InfraSourceMessageLogColumnAttributes { + /** A unique id for the column */ + id: string; +} +/** A log column containing a field value */ +export interface InfraSourceFieldLogColumn { + fieldColumn: InfraSourceFieldLogColumnAttributes; +} + +export interface InfraSourceFieldLogColumnAttributes { + /** A unique id for the column */ + id: string; + /** The field name this column refers to */ + field: string; +} +/** The status of an infrastructure data source */ +export interface InfraSourceStatus { + /** Whether the configured metric alias exists */ + metricAliasExists: boolean; + /** Whether the configured log alias exists */ + logAliasExists: boolean; + /** Whether the configured alias or wildcard pattern resolve to any metric indices */ + metricIndicesExist: boolean; + /** Whether the configured alias or wildcard pattern resolve to any log indices */ + logIndicesExist: boolean; + /** The list of indices in the metric alias */ + metricIndices: string[]; + /** The list of indices in the log alias */ + logIndices: string[]; + /** The list of fields defined in the index mappings */ + indexFields: InfraIndexField[]; +} +/** A descriptor of a field in an index */ +export interface InfraIndexField { + /** The name of the field */ + name: string; + /** The type of the field's values as recognized by Kibana */ + type: string; + /** Whether the field's values can be efficiently searched for */ + searchable: boolean; + /** Whether the field's values can be aggregated */ + aggregatable: boolean; + /** Whether the field should be displayed based on event.module and a ECS allowed list */ + displayable: boolean; +} +/** A consecutive sequence of log entries */ +export interface InfraLogEntryInterval { + /** The key corresponding to the start of the interval covered by the entries */ + start?: InfraTimeKey | null; + /** The key corresponding to the end of the interval covered by the entries */ + end?: InfraTimeKey | null; + /** Whether there are more log entries available before the start */ + hasMoreBefore: boolean; + /** Whether there are more log entries available after the end */ + hasMoreAfter: boolean; + /** The query the log entries were filtered by */ + filterQuery?: string | null; + /** The query the log entries were highlighted with */ + highlightQuery?: string | null; + /** A list of the log entries */ + entries: InfraLogEntry[]; +} +/** A representation of the log entry's position in the event stream */ +export interface InfraTimeKey { + /** The timestamp of the event that the log entry corresponds to */ + time: number; + /** The tiebreaker that disambiguates events with the same timestamp */ + tiebreaker: number; +} +/** A log entry */ +export interface InfraLogEntry { + /** A unique representation of the log entry's position in the event stream */ + key: InfraTimeKey; + /** The log entry's id */ + gid: string; + /** The source id */ + source: string; + /** The columns used for rendering the log entry */ + columns: InfraLogEntryColumn[]; +} +/** A special built-in column that contains the log entry's timestamp */ +export interface InfraLogEntryTimestampColumn { + /** The id of the corresponding column configuration */ + columnId: string; + /** The timestamp */ + timestamp: number; +} +/** A special built-in column that contains the log entry's constructed message */ +export interface InfraLogEntryMessageColumn { + /** The id of the corresponding column configuration */ + columnId: string; + /** A list of the formatted log entry segments */ + message: InfraLogMessageSegment[]; +} +/** A segment of the log entry message that was derived from a field */ +export interface InfraLogMessageFieldSegment { + /** The field the segment was derived from */ + field: string; + /** The segment's message */ + value: string; + /** A list of highlighted substrings of the value */ + highlights: string[]; +} +/** A segment of the log entry message that was derived from a string literal */ +export interface InfraLogMessageConstantSegment { + /** The segment's message */ + constant: string; +} +/** A column that contains the value of a field of the log entry */ +export interface InfraLogEntryFieldColumn { + /** The id of the corresponding column configuration */ + columnId: string; + /** The field name of the column */ + field: string; + /** The value of the field in the log entry */ + value: string; + /** A list of highlighted substrings of the value */ + highlights: string[]; +} + +export interface InfraSnapshotResponse { + /** Nodes of type host, container or pod grouped by 0, 1 or 2 terms */ + nodes: InfraSnapshotNode[]; +} + +export interface InfraSnapshotNode { + path: InfraSnapshotNodePath[]; + + metric: InfraSnapshotNodeMetric; +} + +export interface InfraSnapshotNodePath { + value: string; + + label: string; + + ip?: string | null; +} + +export interface InfraSnapshotNodeMetric { + name: InfraSnapshotMetricType; + + value?: number | null; + + avg?: number | null; + + max?: number | null; +} + +export interface InfraMetricData { + id?: InfraMetric | null; + + series: InfraDataSeries[]; +} + +export interface InfraDataSeries { + id: string; + + label: string; + + data: InfraDataPoint[]; +} + +export interface InfraDataPoint { + timestamp: number; + + value?: number | null; +} + +export interface Mutation { + /** Create a new source of infrastructure data */ + createSource: UpdateSourceResult; + /** Modify an existing source */ + updateSource: UpdateSourceResult; + /** Delete a source of infrastructure data */ + deleteSource: DeleteSourceResult; +} +/** The result of a successful source update */ +export interface UpdateSourceResult { + /** The source that was updated */ + source: InfraSource; +} +/** The result of a source deletion operations */ +export interface DeleteSourceResult { + /** The id of the source that was deleted */ + id: string; +} + +// ==================================================== +// InputTypes +// ==================================================== + +export interface InfraTimeKeyInput { + time: number; + + tiebreaker: number; +} +/** A highlighting definition */ +export interface InfraLogEntryHighlightInput { + /** The query to highlight by */ + query: string; + /** The number of highlighted documents to include beyond the beginning of the interval */ + countBefore: number; + /** The number of highlighted documents to include beyond the end of the interval */ + countAfter: number; +} + +export interface InfraTimerangeInput { + /** The interval string to use for last bucket. The format is '{value}{unit}'. For example '5m' would return the metrics for the last 5 minutes of the timespan. */ + interval: string; + /** The end of the timerange */ + to: number; + /** The beginning of the timerange */ + from: number; +} + +export interface InfraSnapshotGroupbyInput { + /** 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; +} + +export interface InfraSnapshotMetricInput { + /** The type of metric */ + type: InfraSnapshotMetricType; +} + +export interface InfraNodeIdsInput { + nodeId: string; + + cloudId?: string | null; +} +/** The properties to update the source with */ +export interface UpdateSourceInput { + /** The name of the data source */ + name?: string | null; + /** A description of the data source */ + description?: string | null; + /** The alias to read metric data from */ + metricAlias?: string | null; + /** The alias to read log data from */ + logAlias?: string | null; + /** The field mapping to use for this source */ + fields?: UpdateSourceFieldsInput | null; + /** The log columns to display for this source */ + logColumns?: UpdateSourceLogColumnInput[] | null; +} +/** The mapping of semantic fields of the source to be created */ +export interface UpdateSourceFieldsInput { + /** The field to identify a container by */ + container?: string | null; + /** The fields to identify a host by */ + host?: string | null; + /** The field to identify a pod by */ + pod?: string | null; + /** The field to use as a tiebreaker for log events that have identical timestamps */ + tiebreaker?: string | null; + /** The field to use as a timestamp for metrics and logs */ + timestamp?: string | null; +} +/** One of the log column types to display for this source */ +export interface UpdateSourceLogColumnInput { + /** A custom field log column */ + fieldColumn?: UpdateSourceFieldLogColumnInput | null; + /** A built-in message log column */ + messageColumn?: UpdateSourceMessageLogColumnInput | null; + /** A built-in timestamp log column */ + timestampColumn?: UpdateSourceTimestampLogColumnInput | null; +} + +export interface UpdateSourceFieldLogColumnInput { + id: string; + + field: string; +} + +export interface UpdateSourceMessageLogColumnInput { + id: string; +} + +export interface UpdateSourceTimestampLogColumnInput { + id: string; +} + +// ==================================================== +// Arguments +// ==================================================== + +export interface SourceQueryArgs { + /** The id of the source */ + id: string; +} +export interface LogEntriesAroundInfraSourceArgs { + /** The sort key that corresponds to the point in time */ + key: InfraTimeKeyInput; + /** The maximum number of preceding to return */ + countBefore?: number | null; + /** The maximum number of following to return */ + countAfter?: number | null; + /** The query to filter the log entries by */ + filterQuery?: string | null; +} +export interface LogEntriesBetweenInfraSourceArgs { + /** The sort key that corresponds to the start of the interval */ + startKey: InfraTimeKeyInput; + /** The sort key that corresponds to the end of the interval */ + endKey: InfraTimeKeyInput; + /** The query to filter the log entries by */ + filterQuery?: string | null; +} +export interface LogEntryHighlightsInfraSourceArgs { + /** The sort key that corresponds to the start of the interval */ + startKey: InfraTimeKeyInput; + /** The sort key that corresponds to the end of the interval */ + endKey: InfraTimeKeyInput; + /** The query to filter the log entries by */ + filterQuery?: string | null; + /** The highlighting to apply to the log entries */ + highlights: InfraLogEntryHighlightInput[]; +} +export interface SnapshotInfraSourceArgs { + timerange: InfraTimerangeInput; + + filterQuery?: string | null; +} +export interface MetricsInfraSourceArgs { + nodeIds: InfraNodeIdsInput; + + nodeType: InfraNodeType; + + timerange: InfraTimerangeInput; + + metrics: InfraMetric[]; +} +export interface IndexFieldsInfraSourceStatusArgs { + indexType?: InfraIndexType | null; +} +export interface NodesInfraSnapshotResponseArgs { + type: InfraNodeType; + + groupBy: InfraSnapshotGroupbyInput[]; + + metric: InfraSnapshotMetricInput; +} +export interface CreateSourceMutationArgs { + /** The id of the source */ + id: string; + + sourceProperties: UpdateSourceInput; +} +export interface UpdateSourceMutationArgs { + /** The id of the source */ + id: string; + /** The properties to update the source with */ + sourceProperties: UpdateSourceInput; +} +export interface DeleteSourceMutationArgs { + /** The id of the source */ + id: string; +} + +// ==================================================== +// Enums +// ==================================================== + +export enum InfraIndexType { + ANY = 'ANY', + LOGS = 'LOGS', + METRICS = 'METRICS', +} + +export enum InfraNodeType { + pod = 'pod', + container = 'container', + host = 'host', + awsEC2 = 'awsEC2', + awsS3 = 'awsS3', + awsRDS = 'awsRDS', + awsSQS = 'awsSQS', +} + +export enum InfraSnapshotMetricType { + count = 'count', + cpu = 'cpu', + load = 'load', + memory = 'memory', + tx = 'tx', + rx = 'rx', + logRate = 'logRate', + diskIOReadBytes = 'diskIOReadBytes', + diskIOWriteBytes = 'diskIOWriteBytes', + s3TotalRequests = 's3TotalRequests', + s3NumberOfObjects = 's3NumberOfObjects', + s3BucketSize = 's3BucketSize', + s3DownloadBytes = 's3DownloadBytes', + s3UploadBytes = 's3UploadBytes', + rdsConnections = 'rdsConnections', + rdsQueriesExecuted = 'rdsQueriesExecuted', + rdsActiveTransactions = 'rdsActiveTransactions', + rdsLatency = 'rdsLatency', + sqsMessagesVisible = 'sqsMessagesVisible', + sqsMessagesDelayed = 'sqsMessagesDelayed', + sqsMessagesSent = 'sqsMessagesSent', + sqsMessagesEmpty = 'sqsMessagesEmpty', + sqsOldestMessage = 'sqsOldestMessage', +} + +export enum InfraMetric { + hostSystemOverview = 'hostSystemOverview', + hostCpuUsage = 'hostCpuUsage', + hostFilesystem = 'hostFilesystem', + hostK8sOverview = 'hostK8sOverview', + hostK8sCpuCap = 'hostK8sCpuCap', + hostK8sDiskCap = 'hostK8sDiskCap', + hostK8sMemoryCap = 'hostK8sMemoryCap', + hostK8sPodCap = 'hostK8sPodCap', + hostLoad = 'hostLoad', + hostMemoryUsage = 'hostMemoryUsage', + hostNetworkTraffic = 'hostNetworkTraffic', + hostDockerOverview = 'hostDockerOverview', + hostDockerInfo = 'hostDockerInfo', + hostDockerTop5ByCpu = 'hostDockerTop5ByCpu', + hostDockerTop5ByMemory = 'hostDockerTop5ByMemory', + podOverview = 'podOverview', + podCpuUsage = 'podCpuUsage', + podMemoryUsage = 'podMemoryUsage', + podLogUsage = 'podLogUsage', + podNetworkTraffic = 'podNetworkTraffic', + containerOverview = 'containerOverview', + containerCpuKernel = 'containerCpuKernel', + containerCpuUsage = 'containerCpuUsage', + containerDiskIOOps = 'containerDiskIOOps', + containerDiskIOBytes = 'containerDiskIOBytes', + containerMemory = 'containerMemory', + containerNetworkTraffic = 'containerNetworkTraffic', + nginxHits = 'nginxHits', + nginxRequestRate = 'nginxRequestRate', + nginxActiveConnections = 'nginxActiveConnections', + nginxRequestsPerConnection = 'nginxRequestsPerConnection', + awsOverview = 'awsOverview', + awsCpuUtilization = 'awsCpuUtilization', + awsNetworkBytes = 'awsNetworkBytes', + awsNetworkPackets = 'awsNetworkPackets', + awsDiskioBytes = 'awsDiskioBytes', + awsDiskioOps = 'awsDiskioOps', + awsEC2CpuUtilization = 'awsEC2CpuUtilization', + awsEC2DiskIOBytes = 'awsEC2DiskIOBytes', + awsEC2NetworkTraffic = 'awsEC2NetworkTraffic', + awsS3TotalRequests = 'awsS3TotalRequests', + awsS3NumberOfObjects = 'awsS3NumberOfObjects', + awsS3BucketSize = 'awsS3BucketSize', + awsS3DownloadBytes = 'awsS3DownloadBytes', + awsS3UploadBytes = 'awsS3UploadBytes', + awsRDSCpuTotal = 'awsRDSCpuTotal', + awsRDSConnections = 'awsRDSConnections', + awsRDSQueriesExecuted = 'awsRDSQueriesExecuted', + awsRDSActiveTransactions = 'awsRDSActiveTransactions', + awsRDSLatency = 'awsRDSLatency', + awsSQSMessagesVisible = 'awsSQSMessagesVisible', + awsSQSMessagesDelayed = 'awsSQSMessagesDelayed', + awsSQSMessagesSent = 'awsSQSMessagesSent', + awsSQSMessagesEmpty = 'awsSQSMessagesEmpty', + awsSQSOldestMessage = 'awsSQSOldestMessage', + custom = 'custom', +} + +// ==================================================== +// Unions +// ==================================================== + +/** All known log column types */ +export type InfraSourceLogColumn = + | InfraSourceTimestampLogColumn + | InfraSourceMessageLogColumn + | InfraSourceFieldLogColumn; + +/** A column of a log entry */ +export type InfraLogEntryColumn = + | InfraLogEntryTimestampColumn + | InfraLogEntryMessageColumn + | InfraLogEntryFieldColumn; + +/** A segment of the log entry message */ +export type InfraLogMessageSegment = InfraLogMessageFieldSegment | InfraLogMessageConstantSegment; + +// ==================================================== +// END: Typescript template +// ==================================================== + +// ==================================================== +// Documents +// ==================================================== + +export namespace LogEntryHighlightsQuery { + export type Variables = { + sourceId?: string | null; + startKey: InfraTimeKeyInput; + endKey: InfraTimeKeyInput; + filterQuery?: string | null; + highlights: InfraLogEntryHighlightInput[]; + }; + + export type Query = { + __typename?: 'Query'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + id: string; + + logEntryHighlights: LogEntryHighlights[]; + }; + + export type LogEntryHighlights = { + __typename?: 'InfraLogEntryInterval'; + + start?: Start | null; + + end?: End | null; + + entries: Entries[]; + }; + + export type Start = InfraTimeKeyFields.Fragment; + + export type End = InfraTimeKeyFields.Fragment; + + export type Entries = InfraLogEntryHighlightFields.Fragment; +} + +export namespace MetricsQuery { + export type Variables = { + sourceId: string; + timerange: InfraTimerangeInput; + metrics: InfraMetric[]; + nodeId: string; + cloudId?: string | null; + nodeType: InfraNodeType; + }; + + export type Query = { + __typename?: 'Query'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + id: string; + + metrics: Metrics[]; + }; + + export type Metrics = { + __typename?: 'InfraMetricData'; + + id?: InfraMetric | null; + + series: Series[]; + }; + + export type Series = { + __typename?: 'InfraDataSeries'; + + id: string; + + label: string; + + data: Data[]; + }; + + export type Data = { + __typename?: 'InfraDataPoint'; + + timestamp: number; + + value?: number | null; + }; +} + +export namespace CreateSourceConfigurationMutation { + export type Variables = { + sourceId: string; + sourceProperties: UpdateSourceInput; + }; + + export type Mutation = { + __typename?: 'Mutation'; + + createSource: CreateSource; + }; + + export type CreateSource = { + __typename?: 'UpdateSourceResult'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + configuration: Configuration; + + status: Status; + } & InfraSourceFields.Fragment; + + export type Configuration = SourceConfigurationFields.Fragment; + + export type Status = SourceStatusFields.Fragment; +} + +export namespace SourceQuery { + export type Variables = { + sourceId?: string | null; + }; + + export type Query = { + __typename?: 'Query'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + configuration: Configuration; + + status: Status; + } & InfraSourceFields.Fragment; + + export type Configuration = SourceConfigurationFields.Fragment; + + export type Status = SourceStatusFields.Fragment; +} + +export namespace UpdateSourceMutation { + export type Variables = { + sourceId?: string | null; + sourceProperties: UpdateSourceInput; + }; + + export type Mutation = { + __typename?: 'Mutation'; + + updateSource: UpdateSource; + }; + + export type UpdateSource = { + __typename?: 'UpdateSourceResult'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + configuration: Configuration; + + status: Status; + } & InfraSourceFields.Fragment; + + export type Configuration = SourceConfigurationFields.Fragment; + + export type Status = SourceStatusFields.Fragment; +} + +export namespace WaffleNodesQuery { + export type Variables = { + sourceId: string; + timerange: InfraTimerangeInput; + filterQuery?: string | null; + metric: InfraSnapshotMetricInput; + groupBy: InfraSnapshotGroupbyInput[]; + type: InfraNodeType; + }; + + export type Query = { + __typename?: 'Query'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + id: string; + + snapshot?: Snapshot | null; + }; + + export type Snapshot = { + __typename?: 'InfraSnapshotResponse'; + + nodes: Nodes[]; + }; + + export type Nodes = { + __typename?: 'InfraSnapshotNode'; + + path: Path[]; + + metric: Metric; + }; + + export type Path = { + __typename?: 'InfraSnapshotNodePath'; + + value: string; + + label: string; + + ip?: string | null; + }; + + export type Metric = { + __typename?: 'InfraSnapshotNodeMetric'; + + name: InfraSnapshotMetricType; + + value?: number | null; + + avg?: number | null; + + max?: number | null; + }; +} + +export namespace LogEntries { + export type Variables = { + sourceId?: string | null; + timeKey: InfraTimeKeyInput; + countBefore?: number | null; + countAfter?: number | null; + filterQuery?: string | null; + }; + + export type Query = { + __typename?: 'Query'; + + source: Source; + }; + + export type Source = { + __typename?: 'InfraSource'; + + id: string; + + logEntriesAround: LogEntriesAround; + }; + + export type LogEntriesAround = { + __typename?: 'InfraLogEntryInterval'; + + start?: Start | null; + + end?: End | null; + + hasMoreBefore: boolean; + + hasMoreAfter: boolean; + + entries: Entries[]; + }; + + export type Start = InfraTimeKeyFields.Fragment; + + export type End = InfraTimeKeyFields.Fragment; + + export type Entries = InfraLogEntryFields.Fragment; +} + +export namespace SourceConfigurationFields { + export type Fragment = { + __typename?: 'InfraSourceConfiguration'; + + name: string; + + description: string; + + logAlias: string; + + metricAlias: string; + + fields: Fields; + + logColumns: LogColumns[]; + }; + + export type Fields = { + __typename?: 'InfraSourceFields'; + + container: string; + + host: string; + + message: string[]; + + pod: string; + + tiebreaker: string; + + timestamp: string; + }; + + export type LogColumns = + | InfraSourceTimestampLogColumnInlineFragment + | InfraSourceMessageLogColumnInlineFragment + | InfraSourceFieldLogColumnInlineFragment; + + export type InfraSourceTimestampLogColumnInlineFragment = { + __typename?: 'InfraSourceTimestampLogColumn'; + + timestampColumn: TimestampColumn; + }; + + export type TimestampColumn = { + __typename?: 'InfraSourceTimestampLogColumnAttributes'; + + id: string; + }; + + export type InfraSourceMessageLogColumnInlineFragment = { + __typename?: 'InfraSourceMessageLogColumn'; + + messageColumn: MessageColumn; + }; + + export type MessageColumn = { + __typename?: 'InfraSourceMessageLogColumnAttributes'; + + id: string; + }; + + export type InfraSourceFieldLogColumnInlineFragment = { + __typename?: 'InfraSourceFieldLogColumn'; + + fieldColumn: FieldColumn; + }; + + export type FieldColumn = { + __typename?: 'InfraSourceFieldLogColumnAttributes'; + + id: string; + + field: string; + }; +} + +export namespace SourceStatusFields { + export type Fragment = { + __typename?: 'InfraSourceStatus'; + + indexFields: IndexFields[]; + + logIndicesExist: boolean; + + metricIndicesExist: boolean; + }; + + export type IndexFields = { + __typename?: 'InfraIndexField'; + + name: string; + + type: string; + + searchable: boolean; + + aggregatable: boolean; + + displayable: boolean; + }; +} + +export namespace InfraTimeKeyFields { + export type Fragment = { + __typename?: 'InfraTimeKey'; + + time: number; + + tiebreaker: number; + }; +} + +export namespace InfraSourceFields { + export type Fragment = { + __typename?: 'InfraSource'; + + id: string; + + version?: string | null; + + updatedAt?: number | null; + + origin: string; + }; +} + +export namespace InfraLogEntryFields { + export type Fragment = { + __typename?: 'InfraLogEntry'; + + gid: string; + + key: Key; + + columns: Columns[]; + }; + + export type Key = { + __typename?: 'InfraTimeKey'; + + time: number; + + tiebreaker: number; + }; + + export type Columns = + | InfraLogEntryTimestampColumnInlineFragment + | InfraLogEntryMessageColumnInlineFragment + | InfraLogEntryFieldColumnInlineFragment; + + export type InfraLogEntryTimestampColumnInlineFragment = { + __typename?: 'InfraLogEntryTimestampColumn'; + + columnId: string; + + timestamp: number; + }; + + export type InfraLogEntryMessageColumnInlineFragment = { + __typename?: 'InfraLogEntryMessageColumn'; + + columnId: string; + + message: Message[]; + }; + + export type Message = + | InfraLogMessageFieldSegmentInlineFragment + | InfraLogMessageConstantSegmentInlineFragment; + + export type InfraLogMessageFieldSegmentInlineFragment = { + __typename?: 'InfraLogMessageFieldSegment'; + + field: string; + + value: string; + }; + + export type InfraLogMessageConstantSegmentInlineFragment = { + __typename?: 'InfraLogMessageConstantSegment'; + + constant: string; + }; + + export type InfraLogEntryFieldColumnInlineFragment = { + __typename?: 'InfraLogEntryFieldColumn'; + + columnId: string; + + field: string; + + value: string; + }; +} + +export namespace InfraLogEntryHighlightFields { + export type Fragment = { + __typename?: 'InfraLogEntry'; + + gid: string; + + key: Key; + + columns: Columns[]; + }; + + export type Key = { + __typename?: 'InfraTimeKey'; + + time: number; + + tiebreaker: number; + }; + + export type Columns = + | InfraLogEntryMessageColumnInlineFragment + | InfraLogEntryFieldColumnInlineFragment; + + export type InfraLogEntryMessageColumnInlineFragment = { + __typename?: 'InfraLogEntryMessageColumn'; + + columnId: string; + + message: Message[]; + }; + + export type Message = InfraLogMessageFieldSegmentInlineFragment; + + export type InfraLogMessageFieldSegmentInlineFragment = { + __typename?: 'InfraLogMessageFieldSegment'; + + field: string; + + highlights: string[]; + }; + + export type InfraLogEntryFieldColumnInlineFragment = { + __typename?: 'InfraLogEntryFieldColumn'; + + columnId: string; + + field: string; + + highlights: string[]; + }; +} diff --git a/x-pack/plugins/infra/common/http_api/index.ts b/x-pack/plugins/infra/common/http_api/index.ts new file mode 100644 index 0000000000000..326daa93de33a --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/index.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export * from './log_analysis'; +export * from './metadata_api'; +export * from './log_entries'; +export * from './metrics_explorer'; diff --git a/x-pack/plugins/infra/common/http_api/inventory_meta_api.ts b/x-pack/plugins/infra/common/http_api/inventory_meta_api.ts new file mode 100644 index 0000000000000..77de515c9cc46 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/inventory_meta_api.ts @@ -0,0 +1,28 @@ +/* + * 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 * as rt from 'io-ts'; +import { ItemTypeRT } from '../inventory_models/types'; + +const CloudAccountRT = rt.type({ + value: rt.string, + name: rt.string, +}); + +export const InventoryMetaResponseRT = rt.type({ + accounts: rt.array(CloudAccountRT), + projects: rt.array(rt.string), + regions: rt.array(rt.string), +}); + +export const InventoryMetaRequestRT = rt.type({ + sourceId: rt.string, + nodeType: ItemTypeRT, +}); + +export type InventoryMetaRequest = rt.TypeOf; +export type InventoryMetaResponse = rt.TypeOf; +export type InventoryCloudAccount = rt.TypeOf; diff --git a/x-pack/legacy/plugins/infra/server/routes/log_analysis/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_analysis/index.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/log_analysis/queries/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/log_analysis/queries/index.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate.ts new file mode 100644 index 0000000000000..dfc3d2aabd11a --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate.ts @@ -0,0 +1,77 @@ +/* + * 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 * as rt from 'io-ts'; + +import { badRequestErrorRT, conflictErrorRT, forbiddenErrorRT, timeRangeRT } from '../../shared'; + +export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH = + '/api/infra/log_analysis/results/log_entry_rate'; + +/** + * request + */ + +export const getLogEntryRateRequestPayloadRT = rt.type({ + data: rt.type({ + bucketDuration: rt.number, + sourceId: rt.string, + timeRange: timeRangeRT, + }), +}); + +export type GetLogEntryRateRequestPayload = rt.TypeOf; + +/** + * response + */ + +export const logEntryRateAnomalyRT = rt.type({ + actualLogEntryRate: rt.number, + anomalyScore: rt.number, + duration: rt.number, + startTime: rt.number, + typicalLogEntryRate: rt.number, +}); + +export const logEntryRatePartitionRT = rt.type({ + analysisBucketCount: rt.number, + anomalies: rt.array(logEntryRateAnomalyRT), + averageActualLogEntryRate: rt.number, + maximumAnomalyScore: rt.number, + numberOfLogEntries: rt.number, + partitionId: rt.string, +}); + +export type LogEntryRatePartition = rt.TypeOf; + +export const logEntryRateHistogramBucketRT = rt.type({ + partitions: rt.array(logEntryRatePartitionRT), + startTime: rt.number, +}); + +export type LogEntryRateHistogramBucket = rt.TypeOf; + +export const getLogEntryRateSuccessReponsePayloadRT = rt.type({ + data: rt.type({ + bucketDuration: rt.number, + histogramBuckets: rt.array(logEntryRateHistogramBucketRT), + totalNumberOfLogEntries: rt.number, + }), +}); + +export type GetLogEntryRateSuccessResponsePayload = rt.TypeOf< + typeof getLogEntryRateSuccessReponsePayloadRT +>; + +export const getLogEntryRateResponsePayloadRT = rt.union([ + getLogEntryRateSuccessReponsePayloadRT, + badRequestErrorRT, + conflictErrorRT, + forbiddenErrorRT, +]); + +export type GetLogEntryRateReponsePayload = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/index.ts new file mode 100644 index 0000000000000..f23ef7ee7c302 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_analysis/validation/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './log_entry_rate_indices'; diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts new file mode 100644 index 0000000000000..5b2509074f6ed --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts @@ -0,0 +1,61 @@ +/* + * 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 * as rt from 'io-ts'; + +export const LOG_ANALYSIS_VALIDATE_INDICES_PATH = + '/api/infra/log_analysis/validation/log_entry_rate_indices'; + +/** + * Request types + */ +export const validationIndicesFieldSpecificationRT = rt.type({ + name: rt.string, + validTypes: rt.array(rt.string), +}); + +export type ValidationIndicesFieldSpecification = rt.TypeOf< + typeof validationIndicesFieldSpecificationRT +>; + +export const validationIndicesRequestPayloadRT = rt.type({ + data: rt.type({ + fields: rt.array(validationIndicesFieldSpecificationRT), + indices: rt.array(rt.string), + }), +}); + +export type ValidationIndicesRequestPayload = rt.TypeOf; + +/** + * Response types + * */ +export const validationIndicesErrorRT = rt.union([ + rt.type({ + error: rt.literal('INDEX_NOT_FOUND'), + index: rt.string, + }), + rt.type({ + error: rt.literal('FIELD_NOT_FOUND'), + index: rt.string, + field: rt.string, + }), + rt.type({ + error: rt.literal('FIELD_NOT_VALID'), + index: rt.string, + field: rt.string, + }), +]); + +export type ValidationIndicesError = rt.TypeOf; + +export const validationIndicesResponsePayloadRT = rt.type({ + data: rt.type({ + errors: rt.array(validationIndicesErrorRT), + }), +}); + +export type ValidationIndicesResponsePayload = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/common.ts b/x-pack/plugins/infra/common/http_api/log_entries/common.ts new file mode 100644 index 0000000000000..3eb7e278bf99c --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_entries/common.ts @@ -0,0 +1,12 @@ +/* + * 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 * as rt from 'io-ts'; + +export const logEntriesCursorRT = rt.type({ + time: rt.number, + tiebreaker: rt.number, +}); diff --git a/x-pack/legacy/plugins/infra/server/routes/log_entries/index.ts b/x-pack/plugins/infra/common/http_api/log_entries/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_entries/index.ts rename to x-pack/plugins/infra/common/http_api/log_entries/index.ts diff --git a/x-pack/plugins/infra/common/http_api/log_entries/item.ts b/x-pack/plugins/infra/common/http_api/log_entries/item.ts new file mode 100644 index 0000000000000..02335d68402c0 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_entries/item.ts @@ -0,0 +1,32 @@ +/* + * 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 * as rt from 'io-ts'; +import { logEntriesCursorRT } from './common'; + +export const LOG_ENTRIES_ITEM_PATH = '/api/log_entries/item'; + +export const logEntriesItemRequestRT = rt.type({ + sourceId: rt.string, + id: rt.string, +}); + +export type LogEntriesItemRequest = rt.TypeOf; + +const logEntriesItemFieldRT = rt.type({ field: rt.string, value: rt.string }); +const logEntriesItemRT = rt.type({ + id: rt.string, + index: rt.string, + fields: rt.array(logEntriesItemFieldRT), + key: logEntriesCursorRT, +}); +export const logEntriesItemResponseRT = rt.type({ + data: logEntriesItemRT, +}); + +export type LogEntriesItemField = rt.TypeOf; +export type LogEntriesItem = rt.TypeOf; +export type LogEntriesItemResponse = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/summary.ts b/x-pack/plugins/infra/common/http_api/log_entries/summary.ts new file mode 100644 index 0000000000000..4a2c0db0e995e --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_entries/summary.ts @@ -0,0 +1,37 @@ +/* + * 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 * as rt from 'io-ts'; + +export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary'; + +export const logEntriesSummaryRequestRT = rt.type({ + sourceId: rt.string, + startDate: rt.number, + endDate: rt.number, + bucketSize: rt.number, + query: rt.union([rt.string, rt.undefined, rt.null]), +}); + +export type LogEntriesSummaryRequest = rt.TypeOf; + +export const logEntriesSummaryBucketRT = rt.type({ + start: rt.number, + end: rt.number, + entriesCount: rt.number, +}); + +export type LogEntriesSummaryBucket = rt.TypeOf; + +export const logEntriesSummaryResponseRT = rt.type({ + data: rt.type({ + start: rt.number, + end: rt.number, + buckets: rt.array(logEntriesSummaryBucketRT), + }), +}); + +export type LogEntriesSummaryResponse = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts b/x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts new file mode 100644 index 0000000000000..30222cd71bbde --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts @@ -0,0 +1,46 @@ +/* + * 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 * as rt from 'io-ts'; +import { logEntriesSummaryRequestRT, logEntriesSummaryBucketRT } from './summary'; +import { logEntriesCursorRT } from './common'; + +export const LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH = '/api/log_entries/summary_highlights'; + +export const logEntriesSummaryHighlightsRequestRT = rt.intersection([ + logEntriesSummaryRequestRT, + rt.type({ + highlightTerms: rt.array(rt.string), + }), +]); + +export type LogEntriesSummaryHighlightsRequest = rt.TypeOf< + typeof logEntriesSummaryHighlightsRequestRT +>; + +export const logEntriesSummaryHighlightsBucketRT = rt.intersection([ + logEntriesSummaryBucketRT, + rt.type({ + representativeKey: logEntriesCursorRT, + }), +]); + +export type LogEntriesSummaryHighlightsBucket = rt.TypeOf< + typeof logEntriesSummaryHighlightsBucketRT +>; + +export const logEntriesSummaryHighlightsResponseRT = rt.type({ + data: rt.array( + rt.type({ + start: rt.number, + end: rt.number, + buckets: rt.array(logEntriesSummaryHighlightsBucketRT), + }) + ), +}); +export type LogEntriesSummaryHighlightsResponse = rt.TypeOf< + typeof logEntriesSummaryHighlightsResponseRT +>; diff --git a/x-pack/plugins/infra/common/http_api/metadata_api.ts b/x-pack/plugins/infra/common/http_api/metadata_api.ts new file mode 100644 index 0000000000000..7fc3c3e876f08 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/metadata_api.ts @@ -0,0 +1,93 @@ +/* + * 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 * as rt from 'io-ts'; +import { ItemTypeRT } from '../../common/inventory_models/types'; + +export const InfraMetadataRequestRT = rt.type({ + nodeId: rt.string, + nodeType: ItemTypeRT, + sourceId: rt.string, +}); + +export const InfraMetadataFeatureRT = rt.type({ + name: rt.string, + source: rt.string, +}); + +export const InfraMetadataOSRT = rt.partial({ + codename: rt.string, + family: rt.string, + kernel: rt.string, + name: rt.string, + platform: rt.string, + version: rt.string, +}); + +export const InfraMetadataHostRT = rt.partial({ + name: rt.string, + os: InfraMetadataOSRT, + architecture: rt.string, + containerized: rt.boolean, +}); + +export const InfraMetadataInstanceRT = rt.partial({ + id: rt.string, + name: rt.string, +}); + +export const InfraMetadataProjectRT = rt.partial({ + id: rt.string, +}); + +export const InfraMetadataMachineRT = rt.partial({ + interface: rt.string, +}); + +export const InfraMetadataCloudRT = rt.partial({ + instance: InfraMetadataInstanceRT, + provider: rt.string, + availability_zone: rt.string, + project: InfraMetadataProjectRT, + machine: InfraMetadataMachineRT, +}); + +export const InfraMetadataInfoRT = rt.partial({ + cloud: InfraMetadataCloudRT, + host: InfraMetadataHostRT, +}); + +const InfraMetadataRequiredRT = rt.type({ + id: rt.string, + name: rt.string, + features: rt.array(InfraMetadataFeatureRT), +}); + +const InfraMetadataOptionalRT = rt.partial({ + info: InfraMetadataInfoRT, +}); + +export const InfraMetadataRT = rt.intersection([InfraMetadataRequiredRT, InfraMetadataOptionalRT]); + +export type InfraMetadata = rt.TypeOf; + +export type InfraMetadataRequest = rt.TypeOf; + +export type InfraMetadataFeature = rt.TypeOf; + +export type InfraMetadataInfo = rt.TypeOf; + +export type InfraMetadataCloud = rt.TypeOf; + +export type InfraMetadataInstance = rt.TypeOf; + +export type InfraMetadataProject = rt.TypeOf; + +export type InfraMetadataMachine = rt.TypeOf; + +export type InfraMetadataHost = rt.TypeOf; + +export type InfraMetadataOS = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/metrics_explorer/index.ts b/x-pack/plugins/infra/common/http_api/metrics_explorer/index.ts new file mode 100644 index 0000000000000..c10f86c40ad46 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/metrics_explorer/index.ts @@ -0,0 +1,96 @@ +/* + * 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 * as rt from 'io-ts'; + +export const METRIC_EXPLORER_AGGREGATIONS = [ + 'avg', + 'max', + 'min', + 'cardinality', + 'rate', + 'count', +] as const; + +type MetricExplorerAggregations = typeof METRIC_EXPLORER_AGGREGATIONS[number]; + +const metricsExplorerAggregationKeys = METRIC_EXPLORER_AGGREGATIONS.reduce< + Record +>((acc, agg) => ({ ...acc, [agg]: null }), {} as Record); + +export const metricsExplorerAggregationRT = rt.keyof(metricsExplorerAggregationKeys); + +export const metricsExplorerMetricRequiredFieldsRT = rt.type({ + aggregation: metricsExplorerAggregationRT, +}); + +export const metricsExplorerMetricOptionalFieldsRT = rt.partial({ + field: rt.union([rt.string, rt.undefined]), +}); + +export const metricsExplorerMetricRT = rt.intersection([ + metricsExplorerMetricRequiredFieldsRT, + metricsExplorerMetricOptionalFieldsRT, +]); + +export const timeRangeRT = rt.type({ + field: rt.string, + from: rt.number, + to: rt.number, + interval: rt.string, +}); + +export const metricsExplorerRequestBodyRequiredFieldsRT = rt.type({ + timerange: timeRangeRT, + indexPattern: rt.string, + metrics: rt.array(metricsExplorerMetricRT), +}); + +export const metricsExplorerRequestBodyOptionalFieldsRT = rt.partial({ + groupBy: rt.union([rt.string, rt.null, rt.undefined]), + afterKey: rt.union([rt.string, rt.null, rt.undefined]), + limit: rt.union([rt.number, rt.null, rt.undefined]), + filterQuery: rt.union([rt.string, rt.null, rt.undefined]), +}); + +export const metricsExplorerRequestBodyRT = rt.intersection([ + metricsExplorerRequestBodyRequiredFieldsRT, + metricsExplorerRequestBodyOptionalFieldsRT, +]); + +export const metricsExplorerPageInfoRT = rt.type({ + total: rt.number, + afterKey: rt.union([rt.string, rt.null]), +}); + +export const metricsExplorerColumnTypeRT = rt.keyof({ + date: null, + number: null, + string: null, +}); + +export const metricsExplorerColumnRT = rt.type({ + name: rt.string, + type: metricsExplorerColumnTypeRT, +}); + +export const metricsExplorerRowRT = rt.intersection([ + rt.type({ + timestamp: rt.number, + }), + rt.record(rt.string, rt.union([rt.string, rt.number, rt.null, rt.undefined])), +]); + +export const metricsExplorerSeriesRT = rt.type({ + id: rt.string, + columns: rt.array(metricsExplorerColumnRT), + rows: rt.array(metricsExplorerRowRT), +}); + +export const metricsExplorerResponseRT = rt.type({ + series: rt.array(metricsExplorerSeriesRT), + pageInfo: metricsExplorerPageInfoRT, +}); diff --git a/x-pack/plugins/infra/common/http_api/node_details_api.ts b/x-pack/plugins/infra/common/http_api/node_details_api.ts new file mode 100644 index 0000000000000..46aab881bce4c --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/node_details_api.ts @@ -0,0 +1,55 @@ +/* + * 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 * as rt from 'io-ts'; +import { InventoryMetricRT, ItemTypeRT } from '../inventory_models/types'; +import { InfraTimerangeInputRT } from './snapshot_api'; + +const NodeDetailsDataPointRT = rt.intersection([ + rt.type({ + timestamp: rt.number, + }), + rt.partial({ + value: rt.union([rt.number, rt.null]), + }), +]); + +const NodeDetailsDataSeries = rt.type({ + id: rt.string, + label: rt.string, + data: rt.array(NodeDetailsDataPointRT), +}); + +export const NodeDetailsMetricDataRT = rt.intersection([ + rt.partial({ + id: rt.union([InventoryMetricRT, rt.null]), + }), + rt.type({ + series: rt.array(NodeDetailsDataSeries), + }), +]); + +export const NodeDetailsMetricDataResponseRT = rt.type({ + metrics: rt.array(NodeDetailsMetricDataRT), +}); + +export const NodeDetailsRequestRT = rt.intersection([ + rt.type({ + nodeType: ItemTypeRT, + nodeId: rt.string, + metrics: rt.array(InventoryMetricRT), + timerange: InfraTimerangeInputRT, + sourceId: rt.string, + }), + rt.partial({ + cloudId: rt.union([rt.string, rt.null]), + }), +]); + +// export type NodeDetailsRequest = InfraWrappableRequest; + +export type NodeDetailsRequest = rt.TypeOf; +export type NodeDetailsMetricDataResponse = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/shared/errors.ts b/x-pack/plugins/infra/common/http_api/shared/errors.ts new file mode 100644 index 0000000000000..74608cec4d0dc --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/shared/errors.ts @@ -0,0 +1,23 @@ +/* + * 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 * as rt from 'io-ts'; + +const createErrorRuntimeType = ( + statusCode: number, + errorCode: string, + attributes?: Attributes +) => + rt.type({ + statusCode: rt.literal(statusCode), + error: rt.literal(errorCode), + message: rt.string, + ...(!!attributes ? { attributes } : {}), + }); + +export const badRequestErrorRT = createErrorRuntimeType(400, 'Bad Request'); +export const forbiddenErrorRT = createErrorRuntimeType(403, 'Forbidden'); +export const conflictErrorRT = createErrorRuntimeType(409, 'Conflict'); diff --git a/x-pack/plugins/infra/common/http_api/shared/index.ts b/x-pack/plugins/infra/common/http_api/shared/index.ts new file mode 100644 index 0000000000000..1047ca2f2a01a --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/shared/index.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export * from './errors'; +export * from './metric_statistics'; +export * from './time_range'; diff --git a/x-pack/plugins/infra/common/http_api/shared/metric_statistics.ts b/x-pack/plugins/infra/common/http_api/shared/metric_statistics.ts new file mode 100644 index 0000000000000..70bd85402c433 --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/shared/metric_statistics.ts @@ -0,0 +1,15 @@ +/* + * 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 * as rt from 'io-ts'; + +export const metricStatisticsRT = rt.type({ + avg: rt.union([rt.number, rt.null]), + count: rt.number, + max: rt.union([rt.number, rt.null]), + min: rt.union([rt.number, rt.null]), + sum: rt.number, +}); diff --git a/x-pack/plugins/infra/common/http_api/shared/time_range.ts b/x-pack/plugins/infra/common/http_api/shared/time_range.ts new file mode 100644 index 0000000000000..efda07423748b --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/shared/time_range.ts @@ -0,0 +1,14 @@ +/* + * 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 * as rt from 'io-ts'; + +export const timeRangeRT = rt.type({ + startTime: rt.number, + endTime: rt.number, +}); + +export type TimeRange = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/http_api/snapshot_api.ts b/x-pack/plugins/infra/common/http_api/snapshot_api.ts new file mode 100644 index 0000000000000..4ee0c9e23b68f --- /dev/null +++ b/x-pack/plugins/infra/common/http_api/snapshot_api.ts @@ -0,0 +1,70 @@ +/* + * 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 * as rt from 'io-ts'; +import { SnapshotMetricTypeRT, ItemTypeRT } from '../inventory_models/types'; + +export const SnapshotNodePathRT = rt.intersection([ + rt.type({ + value: rt.string, + label: rt.string, + }), + rt.partial({ + ip: rt.union([rt.string, rt.null]), + }), +]); + +const SnapshotNodeMetricOptionalRT = rt.partial({ + value: rt.union([rt.number, rt.null]), + average: rt.union([rt.number, rt.null]), + max: rt.union([rt.number, rt.null]), +}); + +const SnapshotNodeMetricRequiredRT = rt.type({ + name: SnapshotMetricTypeRT, +}); + +export const SnapshotNodeRT = rt.type({ + metric: rt.intersection([SnapshotNodeMetricRequiredRT, SnapshotNodeMetricOptionalRT]), + path: rt.array(SnapshotNodePathRT), +}); + +export const SnapshotNodeResponseRT = rt.type({ + nodes: rt.array(SnapshotNodeRT), + interval: rt.string, +}); + +export const InfraTimerangeInputRT = rt.type({ + interval: rt.string, + to: rt.number, + from: rt.number, +}); + +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]), + }) + ), + nodeType: ItemTypeRT, + sourceId: rt.string, + }), + rt.partial({ + accountId: rt.string, + region: rt.string, + filterQuery: rt.union([rt.string, rt.null]), + }), +]); + +export type SnapshotRequest = rt.TypeOf; +export type SnapshotNode = rt.TypeOf; +export type SnapshotNodeResponse = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/index.ts new file mode 100644 index 0000000000000..ccfd8cd9851eb --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/index.ts @@ -0,0 +1,30 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const awsEC2: InventoryModel = { + id: 'awsEC2', + displayName: i18n.translate('xpack.infra.inventoryModels.awsEC2.displayName', { + defaultMessage: 'EC2 Instances', + }), + requiredModule: 'aws', + crosslinkSupport: { + details: true, + logs: true, + apm: true, + uptime: true, + }, + metrics, + fields: { + id: 'cloud.instance.id', + name: 'cloud.instance.name', + ip: 'aws.ec2.instance.public.ip', + }, + requiredMetrics: ['awsEC2CpuUtilization', 'awsEC2NetworkTraffic', 'awsEC2DiskIOBytes'], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/layout.tsx b/x-pack/plugins/infra/common/inventory_models/aws_ec2/layout.tsx new file mode 100644 index 0000000000000..a3074b78f9f3b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/layout.tsx @@ -0,0 +1,130 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + + +
+ + + + + + + + + +
+
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/index.ts new file mode 100644 index 0000000000000..18b7cca2048a5 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/index.ts @@ -0,0 +1,28 @@ +/* + * 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 { cpu } from './snapshot/cpu'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; +import { diskIOReadBytes } from './snapshot/disk_io_read_bytes'; +import { diskIOWriteBytes } from './snapshot/disk_io_write_bytes'; + +import { awsEC2CpuUtilization } from './tsvb/aws_ec2_cpu_utilization'; +import { awsEC2NetworkTraffic } from './tsvb/aws_ec2_network_traffic'; +import { awsEC2DiskIOBytes } from './tsvb/aws_ec2_diskio_bytes'; + +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + awsEC2CpuUtilization, + awsEC2NetworkTraffic, + awsEC2DiskIOBytes, + }, + snapshot: { cpu, rx, tx, diskIOReadBytes, diskIOWriteBytes }, + defaultSnapshot: 'cpu', + defaultTimeRangeInSeconds: 14400, // 4 hours +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..483d9de784919 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/cpu.ts @@ -0,0 +1,27 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu_avg: { + avg: { + field: 'aws.ec2.cpu.total.pct', + }, + }, + cpu: { + bucket_script: { + buckets_path: { + cpu: 'cpu_avg', + }, + script: { + source: 'params.cpu / 100', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_read_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_read_bytes.ts new file mode 100644 index 0000000000000..48e4a9eb59fad --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_read_bytes.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const diskIOReadBytes: SnapshotModel = { + diskIOReadBytes: { + avg: { + field: 'aws.ec2.diskio.read.bytes_per_sec', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_write_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_write_bytes.ts new file mode 100644 index 0000000000000..deadaa8c4a776 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/disk_io_write_bytes.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const diskIOWriteBytes: SnapshotModel = { + diskIOWriteBytes: { + avg: { + field: 'aws.ec2.diskio.write.bytes_per_sec', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/rx.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..2b857ce9b338a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/rx.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rx: SnapshotModel = { + rx: { + avg: { + field: 'aws.ec2.network.in.bytes_per_sec', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/tx.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..63c9da8ea1888 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/snapshot/tx.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const tx: SnapshotModel = { + tx: { + avg: { + field: 'aws.ec2.network.in.bytes_per_sec', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_cpu_utilization.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_cpu_utilization.ts new file mode 100644 index 0000000000000..a7a06ef1cfc1d --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_cpu_utilization.ts @@ -0,0 +1,37 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsEC2CpuUtilization = createTSVBModel( + 'awsEC2CpuUtilization', + ['aws.ec2'], + [ + { + id: 'total', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.cpu.total.pct', + id: 'avg-cpu', + type: 'avg', + }, + { + id: 'convert-to-percent', + script: 'params.avg / 100', + type: 'calculation', + variables: [ + { + field: 'avg-cpu', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_diskio_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_diskio_bytes.ts new file mode 100644 index 0000000000000..35d165936211a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_diskio_bytes.ts @@ -0,0 +1,41 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; +export const awsEC2DiskIOBytes = createTSVBModel( + 'awsEC2DiskIOBytes', + ['aws.ec2'], + [ + { + id: 'write', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.diskio.write.bytes_per_sec', + id: 'avg-write', + type: 'avg', + }, + ], + }, + { + id: 'read', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.diskio.read.bytes_per_sec', + id: 'avg-read', + type: 'avg', + }, + { + id: 'calculation-rate', + type: 'calculation', + variables: [{ id: 'rate-var', name: 'rate', field: 'avg-read' }], + script: 'params.rate * -1', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_network_traffic.ts b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_network_traffic.ts new file mode 100644 index 0000000000000..ea4b41d0bcd68 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/metrics/tsvb/aws_ec2_network_traffic.ts @@ -0,0 +1,41 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; +export const awsEC2NetworkTraffic = createTSVBModel( + 'awsEC2NetworkTraffic', + ['aws.ec2'], + [ + { + id: 'tx', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.network.out.bytes_per_sec', + id: 'avg-tx', + type: 'avg', + }, + ], + }, + { + id: 'rx', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.network.in.bytes_per_sec', + id: 'avg-rx', + type: 'avg', + }, + { + id: 'calculation-rate', + type: 'calculation', + variables: [{ id: 'rate-var', name: 'rate', field: 'avg-rx' }], + script: 'params.rate * -1', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_ec2/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/aws_ec2/toolbar_items.tsx new file mode 100644 index 0000000000000..490b5c552dcc3 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_ec2/toolbar_items.tsx @@ -0,0 +1,37 @@ +/* + * 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 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'; + +export const AwsEC2ToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.cpu, + InfraSnapshotMetricType.rx, + InfraSnapshotMetricType.tx, + InfraSnapshotMetricType.diskIOReadBytes, + InfraSnapshotMetricType.diskIOWriteBytes, + ]; + const groupByFields = [ + 'cloud.availability_zone', + 'cloud.machine.type', + 'aws.ec2.instance.image.id', + 'aws.ec2.instance.state.name', + ]; + return ( + <> + + + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/index.ts new file mode 100644 index 0000000000000..f1182a942ff06 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/index.ts @@ -0,0 +1,35 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const awsRDS: InventoryModel = { + id: 'awsRDS', + displayName: i18n.translate('xpack.infra.inventoryModels.awsRDS.displayName', { + defaultMessage: 'RDS Databases', + }), + requiredModule: 'aws', + crosslinkSupport: { + details: true, + logs: true, + apm: false, + uptime: false, + }, + metrics, + fields: { + id: 'aws.rds.db_instance.arn', + name: 'aws.rds.db_instance.identifier', + }, + requiredMetrics: [ + 'awsRDSCpuTotal', + 'awsRDSConnections', + 'awsRDSQueriesExecuted', + 'awsRDSActiveTransactions', + 'awsRDSLatency', + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/layout.tsx b/x-pack/plugins/infra/common/inventory_models/aws_rds/layout.tsx new file mode 100644 index 0000000000000..debb569fcd5bb --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/layout.tsx @@ -0,0 +1,183 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + +
+ + + + + + + + + + + + + + + +
+
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/index.ts new file mode 100644 index 0000000000000..eaded5d8df223 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/index.ts @@ -0,0 +1,38 @@ +/* + * 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 { InventoryMetrics } from '../../types'; + +import { cpu } from './snapshot/cpu'; +import { rdsLatency } from './snapshot/rds_latency'; +import { rdsConnections } from './snapshot/rds_connections'; +import { rdsQueriesExecuted } from './snapshot/rds_queries_executed'; +import { rdsActiveTransactions } from './snapshot/rds_active_transactions'; + +import { awsRDSLatency } from './tsvb/aws_rds_latency'; +import { awsRDSConnections } from './tsvb/aws_rds_connections'; +import { awsRDSCpuTotal } from './tsvb/aws_rds_cpu_total'; +import { awsRDSQueriesExecuted } from './tsvb/aws_rds_queries_executed'; +import { awsRDSActiveTransactions } from './tsvb/aws_rds_active_transactions'; + +export const metrics: InventoryMetrics = { + tsvb: { + awsRDSLatency, + awsRDSConnections, + awsRDSCpuTotal, + awsRDSQueriesExecuted, + awsRDSActiveTransactions, + }, + snapshot: { + cpu, + rdsLatency, + rdsConnections, + rdsQueriesExecuted, + rdsActiveTransactions, + }, + defaultSnapshot: 'cpu', + defaultTimeRangeInSeconds: 14400, // 4 hours +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..e277b3b11958b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/cpu.ts @@ -0,0 +1,27 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu_avg: { + avg: { + field: 'aws.rds.cpu.total.pct', + }, + }, + cpu: { + bucket_script: { + buckets_path: { + cpu: 'cpu_avg', + }, + script: { + source: 'params.cpu / 100', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_active_transactions.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_active_transactions.ts new file mode 100644 index 0000000000000..be3dba100ba29 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_active_transactions.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rdsActiveTransactions: SnapshotModel = { + rdsActiveTransactions: { + avg: { + field: 'aws.rds.transactions.active', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_connections.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_connections.ts new file mode 100644 index 0000000000000..c7855d5548eea --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_connections.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rdsConnections: SnapshotModel = { + rdsConnections: { + avg: { + field: 'aws.rds.database_connections', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_latency.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_latency.ts new file mode 100644 index 0000000000000..2997b54d2f92e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_latency.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rdsLatency: SnapshotModel = { + rdsLatency: { + avg: { + field: 'aws.rds.latency.dml', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_queries_executed.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_queries_executed.ts new file mode 100644 index 0000000000000..18e6538fb1e1e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/snapshot/rds_queries_executed.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rdsQueriesExecuted: SnapshotModel = { + rdsQueriesExecuted: { + avg: { + field: 'aws.rds.queries', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_active_transactions.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_active_transactions.ts new file mode 100644 index 0000000000000..026cdeac40c36 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_active_transactions.ts @@ -0,0 +1,36 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsRDSActiveTransactions = createTSVBModel( + 'awsRDSActiveTransactions', + ['aws.rds'], + [ + { + id: 'active', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.transactions.active', + id: 'avg', + type: 'avg', + }, + ], + }, + { + id: 'blocked', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.transactions.blocked', + id: 'avg', + type: 'avg', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_connections.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_connections.ts new file mode 100644 index 0000000000000..145cc758e4a5b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_connections.ts @@ -0,0 +1,25 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsRDSConnections = createTSVBModel( + 'awsRDSConnections', + ['aws.rds'], + [ + { + id: 'connections', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.database_connections', + id: 'avg-conns', + type: 'avg', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_cpu_total.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_cpu_total.ts new file mode 100644 index 0000000000000..9a8eefc859bb0 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_cpu_total.ts @@ -0,0 +1,37 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsRDSCpuTotal = createTSVBModel( + 'awsRDSCpuTotal', + ['aws.rds'], + [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.cpu.total.pct', + id: 'avg-cpu', + type: 'avg', + }, + { + id: 'convert-to-percent', + script: 'params.avg / 100', + type: 'calculation', + variables: [ + { + field: 'avg-cpu', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_latency.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_latency.ts new file mode 100644 index 0000000000000..80dffeeb717c6 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_latency.ts @@ -0,0 +1,68 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsRDSLatency = createTSVBModel( + 'awsRDSLatency', + ['aws.rds'], + [ + { + id: 'read', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.latency.read', + id: 'avg', + type: 'avg', + }, + ], + }, + { + id: 'write', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.latency.write', + id: 'avg', + type: 'avg', + }, + ], + }, + { + id: 'insert', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.latency.insert', + id: 'avg', + type: 'avg', + }, + ], + }, + { + id: 'update', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.latency.update', + id: 'avg', + type: 'avg', + }, + ], + }, + { + id: 'commit', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.latency.commit', + id: 'avg', + type: 'avg', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_queries_executed.ts b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_queries_executed.ts new file mode 100644 index 0000000000000..4dd1a1e89a21a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/metrics/tsvb/aws_rds_queries_executed.ts @@ -0,0 +1,24 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; +export const awsRDSQueriesExecuted = createTSVBModel( + 'awsRDSQueriesExecuted', + ['aws.rds'], + [ + { + id: 'queries', + split_mode: 'everything', + metrics: [ + { + field: 'aws.rds.queries', + id: 'avg-queries', + type: 'avg', + }, + ], + }, + ] +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_rds/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/aws_rds/toolbar_items.tsx new file mode 100644 index 0000000000000..86ed57e8f4c7f --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_rds/toolbar_items.tsx @@ -0,0 +1,36 @@ +/* + * 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 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'; + +export const AwsRDSToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.cpu, + InfraSnapshotMetricType.rdsConnections, + InfraSnapshotMetricType.rdsQueriesExecuted, + InfraSnapshotMetricType.rdsActiveTransactions, + InfraSnapshotMetricType.rdsLatency, + ]; + const groupByFields = [ + 'cloud.availability_zone', + 'aws.rds.db_instance.class', + 'aws.rds.db_instance.status', + ]; + return ( + <> + + + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/index.ts new file mode 100644 index 0000000000000..3bdf319f49c5f --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/index.ts @@ -0,0 +1,35 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const awsS3: InventoryModel = { + id: 'awsS3', + displayName: i18n.translate('xpack.infra.inventoryModels.awsS3.displayName', { + defaultMessage: 'S3 Buckets', + }), + requiredModule: 'aws', + crosslinkSupport: { + details: true, + logs: true, + apm: false, + uptime: false, + }, + metrics, + fields: { + id: 'aws.s3.bucket.name', + name: 'aws.s3.bucket.name', + }, + requiredMetrics: [ + 'awsS3BucketSize', + 'awsS3NumberOfObjects', + 'awsS3TotalRequests', + 'awsS3DownloadBytes', + 'awsS3UploadBytes', + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/layout.tsx b/x-pack/plugins/infra/common/inventory_models/aws_s3/layout.tsx new file mode 100644 index 0000000000000..955960f5baeda --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/layout.tsx @@ -0,0 +1,146 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + +
+ + + + + + + + + + + + + + + +
+
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/index.ts new file mode 100644 index 0000000000000..5aa974c16feec --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/index.ts @@ -0,0 +1,38 @@ +/* + * 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 { InventoryMetrics } from '../../types'; + +import { awsS3BucketSize } from './tsvb/aws_s3_bucket_size'; +import { awsS3TotalRequests } from './tsvb/aws_s3_total_requests'; +import { awsS3NumberOfObjects } from './tsvb/aws_s3_number_of_objects'; +import { awsS3DownloadBytes } from './tsvb/aws_s3_download_bytes'; +import { awsS3UploadBytes } from './tsvb/aws_s3_upload_bytes'; + +import { s3BucketSize } from './snapshot/s3_bucket_size'; +import { s3TotalRequests } from './snapshot/s3_total_requests'; +import { s3NumberOfObjects } from './snapshot/s3_number_of_objects'; +import { s3DownloadBytes } from './snapshot/s3_download_bytes'; +import { s3UploadBytes } from './snapshot/s3_upload_bytes'; + +export const metrics: InventoryMetrics = { + tsvb: { + awsS3BucketSize, + awsS3TotalRequests, + awsS3NumberOfObjects, + awsS3DownloadBytes, + awsS3UploadBytes, + }, + snapshot: { + s3BucketSize, + s3NumberOfObjects, + s3TotalRequests, + s3UploadBytes, + s3DownloadBytes, + }, + defaultSnapshot: 's3BucketSize', + defaultTimeRangeInSeconds: 86400 * 7, // 7 days +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_bucket_size.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_bucket_size.ts new file mode 100644 index 0000000000000..a99753a39c97c --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_bucket_size.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const s3BucketSize: SnapshotModel = { + s3BucketSize: { + max: { + field: 'aws.s3_daily_storage.bucket.size.bytes', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_download_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_download_bytes.ts new file mode 100644 index 0000000000000..a0b23dadee37a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_download_bytes.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const s3DownloadBytes: SnapshotModel = { + s3DownloadBytes: { + max: { + field: 'aws.s3_request.downloaded.bytes', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_number_of_objects.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_number_of_objects.ts new file mode 100644 index 0000000000000..29162a59db47a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_number_of_objects.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const s3NumberOfObjects: SnapshotModel = { + s3NumberOfObjects: { + max: { + field: 'aws.s3_daily_storage.number_of_objects', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_total_requests.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_total_requests.ts new file mode 100644 index 0000000000000..bc57c6eb38234 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_total_requests.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const s3TotalRequests: SnapshotModel = { + s3TotalRequests: { + max: { + field: 'aws.s3_request.requests.total', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_upload_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_upload_bytes.ts new file mode 100644 index 0000000000000..977d73254c3cd --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/snapshot/s3_upload_bytes.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const s3UploadBytes: SnapshotModel = { + s3UploadBytes: { + max: { + field: 'aws.s3_request.uploaded.bytes', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_bucket_size.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_bucket_size.ts new file mode 100644 index 0000000000000..216f98b9e16b4 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_bucket_size.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsS3BucketSize = createTSVBModel( + 'awsS3BucketSize', + ['aws.s3_daily_storage'], + [ + { + id: 'bytes', + split_mode: 'everything', + metrics: [ + { + field: 'aws.s3_daily_storage.bucket.size.bytes', + id: 'max-bytes', + type: 'max', + }, + ], + }, + ], + '>=86400s', + false +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_download_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_download_bytes.ts new file mode 100644 index 0000000000000..15eb3130a5e23 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_download_bytes.ts @@ -0,0 +1,25 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsS3DownloadBytes = createTSVBModel( + 'awsS3DownloadBytes', + ['aws.s3_request'], + [ + { + id: 'bytes', + split_mode: 'everything', + metrics: [ + { + field: 'aws.s3_request.downloaded.bytes', + id: 'max-bytes', + type: 'max', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_number_of_objects.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_number_of_objects.ts new file mode 100644 index 0000000000000..c108735bc0efd --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_number_of_objects.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsS3NumberOfObjects = createTSVBModel( + 'awsS3NumberOfObjects', + ['aws.s3_daily_storage'], + [ + { + id: 'objects', + split_mode: 'everything', + metrics: [ + { + field: 'aws.s3_daily_storage.number_of_objects', + id: 'max-size', + type: 'max', + }, + ], + }, + ], + '>=86400s', + false +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_total_requests.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_total_requests.ts new file mode 100644 index 0000000000000..311067fd96b47 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_total_requests.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsS3TotalRequests = createTSVBModel( + 'awsS3TotalRequests', + ['aws.s3_request'], + [ + { + id: 'total', + split_mode: 'everything', + metrics: [ + { + field: 'aws.s3_request.requests.total', + id: 'max-size', + type: 'max', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_upload_bytes.ts b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_upload_bytes.ts new file mode 100644 index 0000000000000..ab66b47cfa781 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/metrics/tsvb/aws_s3_upload_bytes.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsS3UploadBytes = createTSVBModel( + 'awsS3UploadBytes', + ['aws.s3_request'], + [ + { + id: 'bytes', + split_mode: 'everything', + metrics: [ + { + field: 'aws.s3_request.uploaded.bytes', + id: 'max-bytes', + type: 'max', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_s3/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/aws_s3/toolbar_items.tsx new file mode 100644 index 0000000000000..276b6b83eb43d --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_s3/toolbar_items.tsx @@ -0,0 +1,32 @@ +/* + * 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 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'; + +export const AwsS3ToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.s3BucketSize, + InfraSnapshotMetricType.s3NumberOfObjects, + InfraSnapshotMetricType.s3TotalRequests, + InfraSnapshotMetricType.s3DownloadBytes, + InfraSnapshotMetricType.s3UploadBytes, + ]; + const groupByFields = ['cloud.region']; + return ( + <> + + + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/index.ts new file mode 100644 index 0000000000000..1733e995a824f --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/index.ts @@ -0,0 +1,35 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const awsSQS: InventoryModel = { + id: 'awsSQS', + displayName: i18n.translate('xpack.infra.inventoryModels.awsSQS.displayName', { + defaultMessage: 'SQS Queues', + }), + requiredModule: 'aws', + crosslinkSupport: { + details: true, + logs: true, + apm: false, + uptime: false, + }, + metrics, + fields: { + id: 'aws.sqs.queue.name', + name: 'aws.sqs.queue.name', + }, + requiredMetrics: [ + 'awsSQSMessagesVisible', + 'awsSQSMessagesDelayed', + 'awsSQSMessagesSent', + 'awsSQSMessagesEmpty', + 'awsSQSOldestMessage', + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/layout.tsx b/x-pack/plugins/infra/common/inventory_models/aws_sqs/layout.tsx new file mode 100644 index 0000000000000..5d460c971ec3b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/layout.tsx @@ -0,0 +1,146 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + +
+ + + + + + + + + + + + + + + +
+
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/index.ts new file mode 100644 index 0000000000000..7bc593cc22035 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/index.ts @@ -0,0 +1,38 @@ +/* + * 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 { InventoryMetrics } from '../../types'; + +import { sqsMessagesVisible } from './snapshot/sqs_messages_visible'; +import { sqsMessagesDelayed } from './snapshot/sqs_messages_delayed'; +import { sqsMessagesEmpty } from './snapshot/sqs_messages_empty'; +import { sqsMessagesSent } from './snapshot/sqs_messages_sent'; +import { sqsOldestMessage } from './snapshot/sqs_oldest_message'; + +import { awsSQSMessagesVisible } from './tsvb/aws_sqs_messages_visible'; +import { awsSQSMessagesDelayed } from './tsvb/aws_sqs_messages_delayed'; +import { awsSQSMessagesSent } from './tsvb/aws_sqs_messages_sent'; +import { awsSQSMessagesEmpty } from './tsvb/aws_sqs_messages_empty'; +import { awsSQSOldestMessage } from './tsvb/aws_sqs_oldest_message'; + +export const metrics: InventoryMetrics = { + tsvb: { + awsSQSMessagesVisible, + awsSQSMessagesDelayed, + awsSQSMessagesSent, + awsSQSMessagesEmpty, + awsSQSOldestMessage, + }, + snapshot: { + sqsMessagesVisible, + sqsMessagesDelayed, + sqsMessagesEmpty, + sqsMessagesSent, + sqsOldestMessage, + }, + defaultSnapshot: 'sqsMessagesVisible', + defaultTimeRangeInSeconds: 14400, // 4 hours +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_delayed.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_delayed.ts new file mode 100644 index 0000000000000..679f86671725e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_delayed.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const sqsMessagesDelayed: SnapshotModel = { + sqsMessagesDelayed: { + max: { + field: 'aws.sqs.messages.delayed', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_empty.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_empty.ts new file mode 100644 index 0000000000000..d80a3f3451e1d --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_empty.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const sqsMessagesEmpty: SnapshotModel = { + sqsMessagesEmpty: { + max: { + field: 'aws.sqs.messages.not_visible', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_sent.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_sent.ts new file mode 100644 index 0000000000000..3d6934bf3da85 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_sent.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const sqsMessagesSent: SnapshotModel = { + sqsMessagesSent: { + max: { + field: 'aws.sqs.messages.sent', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_visible.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_visible.ts new file mode 100644 index 0000000000000..1a78c50cd7949 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_messages_visible.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const sqsMessagesVisible: SnapshotModel = { + sqsMessagesVisible: { + avg: { + field: 'aws.sqs.messages.visible', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_oldest_message.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_oldest_message.ts new file mode 100644 index 0000000000000..ae780069c8ca1 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/snapshot/sqs_oldest_message.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const sqsOldestMessage: SnapshotModel = { + sqsOldestMessage: { + max: { + field: 'aws.sqs.oldest_message_age.sec', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_delayed.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_delayed.ts new file mode 100644 index 0000000000000..469b9ddd33953 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_delayed.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsSQSMessagesDelayed = createTSVBModel( + 'awsSQSMessagesDelayed', + ['aws.sqs'], + [ + { + id: 'delayed', + split_mode: 'everything', + metrics: [ + { + field: 'aws.sqs.messages.delayed', + id: 'avg-delayed', + type: 'avg', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_empty.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_empty.ts new file mode 100644 index 0000000000000..54c9e503a8c8c --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_empty.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsSQSMessagesEmpty = createTSVBModel( + 'awsSQSMessagesEmpty', + ['aws.sqs'], + [ + { + id: 'empty', + split_mode: 'everything', + metrics: [ + { + field: 'aws.sqs.messages.not_visible', + id: 'avg-empty', + type: 'avg', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_sent.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_sent.ts new file mode 100644 index 0000000000000..98389ef22fbe8 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_sent.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsSQSMessagesSent = createTSVBModel( + 'awsSQSMessagesSent', + ['aws.sqs'], + [ + { + id: 'sent', + split_mode: 'everything', + metrics: [ + { + field: 'aws.sqs.messages.sent', + id: 'avg-sent', + type: 'avg', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_visible.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_visible.ts new file mode 100644 index 0000000000000..c96ab07e4ae75 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_messages_visible.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsSQSMessagesVisible = createTSVBModel( + 'awsSQSMessagesVisible', + ['aws.sqs'], + [ + { + id: 'visible', + split_mode: 'everything', + metrics: [ + { + field: 'aws.sqs.messages.visible', + id: 'avg-visible', + type: 'avg', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_oldest_message.ts b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_oldest_message.ts new file mode 100644 index 0000000000000..812906386fb67 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/metrics/tsvb/aws_sqs_oldest_message.ts @@ -0,0 +1,26 @@ +/* + * 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 { createTSVBModel } from '../../../create_tsvb_model'; + +export const awsSQSOldestMessage = createTSVBModel( + 'awsSQSOldestMessage', + ['aws.sqs'], + [ + { + id: 'oldest', + split_mode: 'everything', + metrics: [ + { + field: 'aws.sqs.oldest_message_age.sec', + id: 'max-oldest', + type: 'max', + }, + ], + }, + ], + '>=300s' +); diff --git a/x-pack/plugins/infra/common/inventory_models/aws_sqs/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/aws_sqs/toolbar_items.tsx new file mode 100644 index 0000000000000..67baa22a5e6b0 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/aws_sqs/toolbar_items.tsx @@ -0,0 +1,32 @@ +/* + * 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 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'; + +export const AwsSQSToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.sqsMessagesVisible, + InfraSnapshotMetricType.sqsMessagesDelayed, + InfraSnapshotMetricType.sqsMessagesSent, + InfraSnapshotMetricType.sqsMessagesEmpty, + InfraSnapshotMetricType.sqsOldestMessage, + ]; + const groupByFields = ['cloud.region']; + return ( + <> + + + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/container/index.ts b/x-pack/plugins/infra/common/inventory_models/container/index.ts new file mode 100644 index 0000000000000..29b3cfe3af180 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/index.ts @@ -0,0 +1,37 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const container: InventoryModel = { + id: 'container', + displayName: i18n.translate('xpack.infra.inventoryModel.container.displayName', { + defaultMessage: 'Docker Containers', + }), + requiredModule: 'docker', + crosslinkSupport: { + details: true, + logs: true, + apm: true, + uptime: true, + }, + fields: { + id: 'container.id', + name: 'container.name', + ip: 'continaer.ip_address', + }, + metrics, + requiredMetrics: [ + 'containerOverview', + 'containerCpuUsage', + 'containerMemory', + 'containerNetworkTraffic', + 'containerDiskIOBytes', + 'containerDiskIOOps', + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/container/layout.tsx b/x-pack/plugins/infra/common/inventory_models/container/layout.tsx new file mode 100644 index 0000000000000..e207687cf8643 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/layout.tsx @@ -0,0 +1,230 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { GaugesSectionVis } from '../../../public/pages/metrics/components/gauges_section_vis'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; +import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + + +
+ + + + + + + + + + + + + + + + + + +
+
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/index.ts new file mode 100644 index 0000000000000..73a10cbadb66d --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/index.ts @@ -0,0 +1,34 @@ +/* + * 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 { InventoryMetrics } from '../../types'; +import { cpu } from './snapshot/cpu'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { containerOverview } from './tsvb/container_overview'; +import { containerCpuUsage } from './tsvb/container_cpu_usage'; +import { containerCpuKernel } from './tsvb/container_cpu_kernel'; +import { containerDiskIOOps } from './tsvb/container_diskio_ops'; +import { containerDiskIOBytes } from './tsvb/container_disk_io_bytes'; +import { containerMemory } from './tsvb/container_memory'; +import { containerNetworkTraffic } from './tsvb/container_network_traffic'; + +export const metrics: InventoryMetrics = { + tsvb: { + containerOverview, + containerCpuUsage, + containerCpuKernel, + containerDiskIOOps, + containerDiskIOBytes, + containerNetworkTraffic, + containerMemory, + }, + snapshot: { cpu, memory, rx, tx }, + defaultSnapshot: 'cpu', + defaultTimeRangeInSeconds: 3600, // 1 hour +}; diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..a6c25ee260cac --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu: { + avg: { + field: 'docker.cpu.total.pct', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..30df0ebbaa1d4 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts @@ -0,0 +1,9 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { memory: { avg: { field: 'docker.memory.usage.pct' } } }; diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..6843f6149c711 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts @@ -0,0 +1,12 @@ +/* + * 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 { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const rx = networkTrafficWithInterfaces( + 'rx', + 'docker.network.in.bytes', + 'docker.network.interface' +); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..bccb4e60e9d19 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts @@ -0,0 +1,12 @@ +/* + * 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 { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const tx = networkTrafficWithInterfaces( + 'tx', + 'docker.network.out.bytes', + 'docker.network.interface' +); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts new file mode 100644 index 0000000000000..9e4a6dad429bb --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerCpuKernel: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerCpuKernel', + requires: ['docker.cpu'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'kernel', + split_mode: 'everything', + metrics: [ + { + field: 'docker.cpu.kernel.pct', + id: 'avg-cpu-kernel', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts new file mode 100644 index 0000000000000..0eb84f4c3aca5 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerCpuUsage', + requires: ['docker.cpu'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'docker.cpu.total.pct', + id: 'avg-cpu-total', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts new file mode 100644 index 0000000000000..273056f376825 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts @@ -0,0 +1,80 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerDiskIOBytes: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerDiskIOBytes', + requires: ['docker.disk'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'read', + split_mode: 'everything', + metrics: [ + { + field: 'docker.diskio.read.bytes', + id: 'max-diskio-read-bytes', + type: 'max', + }, + { + field: 'max-diskio-read-bytes', + id: 'deriv-max-diskio-read-bytes', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-diskio-read-bytes', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-read-bytes' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + }, + { + id: 'write', + split_mode: 'everything', + metrics: [ + { + field: 'docker.diskio.write.bytes', + id: 'max-diskio-write-bytes', + type: 'max', + }, + { + field: 'max-diskio-write-bytes', + id: 'deriv-max-diskio-write-bytes', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-diskio-write-bytes', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-write-bytes' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + id: 'calc-invert-rate', + script: 'params.rate * -1', + type: 'calculation', + variables: [ + { + field: 'posonly-deriv-max-diskio-write-bytes', + id: 'var-rate', + name: 'rate', + }, + ], + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts new file mode 100644 index 0000000000000..4067a5cf6c6f4 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts @@ -0,0 +1,80 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerDiskIOOps: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerDiskIOOps', + requires: ['docker.disk'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'read', + split_mode: 'everything', + metrics: [ + { + field: 'docker.diskio.read.ops', + id: 'max-diskio-read-ops', + type: 'max', + }, + { + field: 'max-diskio-read-ops', + id: 'deriv-max-diskio-read-ops', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-diskio-read-ops', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-read-ops' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + }, + { + id: 'write', + split_mode: 'everything', + metrics: [ + { + field: 'docker.diskio.write.ops', + id: 'max-diskio-write-ops', + type: 'max', + }, + { + field: 'max-diskio-write-ops', + id: 'deriv-max-diskio-write-ops', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-diskio-write-ops', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-write-ops' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + id: 'calc-invert-rate', + script: 'params.rate * -1', + type: 'calculation', + variables: [ + { + field: 'posonly-deriv-max-diskio-write-ops', + id: 'var-rate', + name: 'rate', + }, + ], + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts new file mode 100644 index 0000000000000..8af7f057e8bad --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerMemory: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerMemory', + requires: ['docker.memory'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'memory', + split_mode: 'everything', + metrics: [ + { + field: 'docker.memory.usage.pct', + id: 'avg-memory', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts new file mode 100644 index 0000000000000..18daac446bdcd --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts @@ -0,0 +1,56 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerNetworkTraffic: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerNetworkTraffic', + requires: ['docker.network'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'tx', + split_mode: 'everything', + metrics: [ + { + field: 'docker.network.out.bytes', + id: 'avg-network-out', + type: 'avg', + }, + ], + }, + { + id: 'rx', + split_mode: 'everything', + metrics: [ + { + field: 'docker.network.in.bytes', + id: 'avg-network-in', + type: 'avg', + }, + { + id: 'invert-posonly-deriv-max-network-in', + script: 'params.rate * -1', + type: 'calculation', + variables: [ + { + field: 'avg-network-in', + id: 'var-rate', + name: 'rate', + }, + ], + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts new file mode 100644 index 0000000000000..7facd082718b1 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts @@ -0,0 +1,66 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const containerOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerOverview', + requires: ['docker'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'docker.cpu.total.pct', + id: 'avg-cpu-total', + type: 'avg', + }, + ], + }, + { + id: 'memory', + split_mode: 'everything', + metrics: [ + { + field: 'docker.memory.usage.pct', + id: 'avg-memory', + type: 'avg', + }, + ], + }, + { + id: 'tx', + split_mode: 'everything', + metrics: [ + { + field: 'docker.network.out.bytes', + id: 'avg-network-out', + type: 'avg', + }, + ], + }, + { + id: 'rx', + split_mode: 'everything', + metrics: [ + { + field: 'docker.network.in.bytes', + id: 'avg-network-in', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/container/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/container/toolbar_items.tsx new file mode 100644 index 0000000000000..9ed2cbe6dea08 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/container/toolbar_items.tsx @@ -0,0 +1,34 @@ +/* + * 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 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'; + +export const ContainerToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.cpu, + InfraSnapshotMetricType.memory, + InfraSnapshotMetricType.rx, + InfraSnapshotMetricType.tx, + ]; + const groupByFields = [ + 'host.name', + 'cloud.availability_zone', + 'cloud.machine.type', + 'cloud.project.id', + 'cloud.provider', + 'service.type', + ]; + return ( + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts b/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts new file mode 100644 index 0000000000000..7036b2236881f --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts @@ -0,0 +1,24 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel, TSVBSeries, InventoryMetric } from './types'; + +export const createTSVBModel = ( + id: InventoryMetric, + requires: string[], + series: TSVBSeries[], + interval = '>=300s', + dropLastBucket = true +): TSVBMetricModelCreator => (timeField, indexPattern): TSVBMetricModel => ({ + id, + requires, + drop_last_bucket: dropLastBucket, + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series, +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/index.ts b/x-pack/plugins/infra/common/inventory_models/host/index.ts new file mode 100644 index 0000000000000..364ef0b4c2c91 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/index.ts @@ -0,0 +1,47 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; +import { + aws as awsRequiredMetrics, + nginx as nginxRequireMetrics, +} from '../shared/metrics/required_metrics'; + +export const host: InventoryModel = { + id: 'host', + displayName: i18n.translate('xpack.infra.inventoryModel.host.displayName', { + defaultMessage: 'Hosts', + }), + requiredModule: 'system', + crosslinkSupport: { + details: true, + logs: true, + apm: true, + uptime: true, + }, + fields: { + id: 'host.name', + name: 'host.name', + ip: 'host.ip', + }, + metrics, + requiredMetrics: [ + 'hostSystemOverview', + 'hostCpuUsage', + 'hostLoad', + 'hostMemoryUsage', + 'hostNetworkTraffic', + 'hostK8sOverview', + 'hostK8sCpuCap', + 'hostK8sMemoryCap', + 'hostK8sDiskCap', + 'hostK8sPodCap', + ...awsRequiredMetrics, + ...nginxRequireMetrics, + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/host/layout.tsx b/x-pack/plugins/infra/common/inventory_models/host/layout.tsx new file mode 100644 index 0000000000000..ca53193e64ca2 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/layout.tsx @@ -0,0 +1,370 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { withTheme } from '../../../../../common/eui_styled_components/eui_styled_components'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { GaugesSectionVis } from '../../../public/pages/metrics/components/gauges_section_vis'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import * as Aws from '../shared/layouts/aws'; +import * as Ngnix from '../shared/layouts/nginx'; +import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + +
+ + +
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts new file mode 100644 index 0000000000000..7f77f23e4fb95 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/index.ts @@ -0,0 +1,56 @@ +/* + * 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 { cpu } from './snapshot/cpu'; +import { count } from '../../shared/metrics/snapshot/count'; +import { load } from './snapshot/load'; +import { logRate } from './snapshot/log_rate'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { hostSystemOverview } from './tsvb/host_system_overview'; +import { hostCpuUsage } from './tsvb/host_cpu_usage'; +import { hostLoad } from './tsvb/host_load'; +import { hostMemoryUsage } from './tsvb/host_memory_usage'; +import { hostNetworkTraffic } from './tsvb/host_network_traffic'; +import { hostFilesystem } from './tsvb/host_filesystem'; + +import { hostK8sOverview } from './tsvb/host_k8s_overview'; +import { hostK8sCpuCap } from './tsvb/host_k8s_cpu_cap'; +import { hostK8sPodCap } from './tsvb/host_k8s_pod_cap'; +import { hostK8sDiskCap } from './tsvb/host_k8s_disk_cap'; +import { hostK8sMemoryCap } from './tsvb/host_k8s_memory_cap'; + +import { hostDockerTop5ByMemory } from './tsvb/host_docker_top_5_by_memory'; +import { hostDockerTop5ByCpu } from './tsvb/host_docker_top_5_by_cpu'; +import { hostDockerOverview } from './tsvb/host_docker_overview'; +import { hostDockerInfo } from './tsvb/host_docker_info'; + +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + hostSystemOverview, + hostCpuUsage, + hostLoad, + hostMemoryUsage, + hostNetworkTraffic, + hostFilesystem, + hostK8sOverview, + hostK8sCpuCap, + hostK8sPodCap, + hostK8sDiskCap, + hostK8sMemoryCap, + hostDockerOverview, + hostDockerInfo, + hostDockerTop5ByMemory, + hostDockerTop5ByCpu, + }, + snapshot: { count, cpu, load, logRate, memory, rx, tx }, + defaultSnapshot: 'cpu', + defaultTimeRangeInSeconds: 3600, // 1 hour +}; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..fa43acb8d6108 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts @@ -0,0 +1,39 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu_user: { + avg: { + field: 'system.cpu.user.pct', + }, + }, + cpu_system: { + avg: { + field: 'system.cpu.system.pct', + }, + }, + cpu_cores: { + max: { + field: 'system.cpu.cores', + }, + }, + cpu: { + bucket_script: { + buckets_path: { + user: 'cpu_user', + system: 'cpu_system', + cores: 'cpu_cores', + }, + script: { + source: '(params.user + params.system) / params.cores', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts new file mode 100644 index 0000000000000..803fb2664ad27 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts @@ -0,0 +1,9 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const load: SnapshotModel = { load: { avg: { field: 'system.load.5' } } }; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts new file mode 100644 index 0000000000000..658111bd07676 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts @@ -0,0 +1,32 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const logRate: SnapshotModel = { + count: { + bucket_script: { + buckets_path: { count: '_count' }, + script: { + source: 'count * 1', + lang: 'expression', + }, + gap_policy: 'skip', + }, + }, + cumsum: { + cumulative_sum: { + buckets_path: 'count', + }, + }, + logRate: { + derivative: { + buckets_path: 'cumsum', + gap_policy: 'skip', + unit: '1s', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..cb08a9eaebb3b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts @@ -0,0 +1,11 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { + memory: { avg: { field: 'system.memory.actual.used.pct' } }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..602169339101e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts @@ -0,0 +1,12 @@ +/* + * 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 { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const rx = networkTrafficWithInterfaces( + 'rx', + 'system.network.in.bytes', + 'system.network.name' +); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..4042a7ab7b66e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts @@ -0,0 +1,12 @@ +/* + * 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 { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const tx = networkTrafficWithInterfaces( + 'tx', + 'system.network.out.bytes', + 'system.network.name' +); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts new file mode 100644 index 0000000000000..c7db1f9e7394c --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts @@ -0,0 +1,253 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostCpuUsage', + requires: ['system.cpu'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'user', + metrics: [ + { + field: 'system.cpu.user.pct', + id: 'avg-cpu-user', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-user', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'system', + metrics: [ + { + field: 'system.cpu.system.pct', + id: 'avg-cpu-system', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-system', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'steal', + metrics: [ + { + field: 'system.cpu.steal.pct', + id: 'avg-cpu-steal', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'avg-cpu-steal', + id: 'var-avg', + name: 'avg', + }, + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'irq', + metrics: [ + { + field: 'system.cpu.irq.pct', + id: 'avg-cpu-irq', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-irq', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'softirq', + metrics: [ + { + field: 'system.cpu.softirq.pct', + id: 'avg-cpu-softirq', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-softirq', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'iowait', + metrics: [ + { + field: 'system.cpu.iowait.pct', + id: 'avg-cpu-iowait', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-iowait', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'nice', + metrics: [ + { + field: 'system.cpu.nice.pct', + id: 'avg-cpu-nice', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + id: 'calc-avg-cores', + script: 'params.avg / params.cores', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + { + field: 'avg-cpu-nice', + id: 'var-avg', + name: 'avg', + }, + ], + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts new file mode 100644 index 0000000000000..9c55eaa932d33 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts @@ -0,0 +1,55 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostDockerInfo: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostDockerInfo', + requires: ['docker.info'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'running', + metrics: [ + { + field: 'docker.info.containers.running', + id: 'max-running', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'paused', + metrics: [ + { + field: 'docker.info.containers.paused', + id: 'max-paused', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'stopped', + metrics: [ + { + field: 'docker.info.containers.stopped', + id: 'max-stopped', + type: 'max', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts new file mode 100644 index 0000000000000..d7026d7648d37 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts @@ -0,0 +1,65 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostDockerOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostDockerOverview', + requires: ['docker.info'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'gauge', + series: [ + { + id: 'total', + metrics: [ + { + field: 'docker.info.containers.total', + id: 'max-total', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'running', + metrics: [ + { + field: 'docker.info.containers.running', + id: 'max-running', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'paused', + metrics: [ + { + field: 'docker.info.containers.paused', + id: 'max-paused', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'stopped', + metrics: [ + { + field: 'docker.info.containers.stopped', + id: 'max-stopped', + type: 'max', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts new file mode 100644 index 0000000000000..a4f8bcd426edd --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts @@ -0,0 +1,36 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostDockerTop5ByCpu', + requires: ['docker.cpu'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'avg-cpu', + metrics: [ + { + field: 'docker.cpu.total.pct', + id: 'avg-cpu-metric', + type: 'avg', + }, + ], + split_mode: 'terms', + terms_field: 'container.name', + terms_order_by: 'avg-cpu', + terms_size: 5, + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts new file mode 100644 index 0000000000000..4441b1824e2a2 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts @@ -0,0 +1,36 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostDockerTop5ByMemory', + requires: ['docker.memory'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'avg-memory', + metrics: [ + { + field: 'docker.memory.usage.pct', + id: 'avg-memory-metric', + type: 'avg', + }, + ], + split_mode: 'terms', + terms_field: 'container.name', + terms_order_by: 'avg-memory', + terms_size: 5, + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts new file mode 100644 index 0000000000000..850674ce89c75 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts @@ -0,0 +1,37 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostFilesystem: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostFilesystem', + requires: ['system.filesystem'], + filter: 'system.filesystem.device_name:\\/*', + index_pattern: indexPattern, + time_field: timeField, + interval, + type: 'timeseries', + series: [ + { + id: 'used', + metrics: [ + { + field: 'system.filesystem.used.pct', + id: 'avg-filesystem-used', + type: 'avg', + }, + ], + split_mode: 'terms', + terms_field: 'system.filesystem.device_name', + terms_order_by: 'used', + terms_size: 5, + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts new file mode 100644 index 0000000000000..97e2bc8f09196 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts @@ -0,0 +1,57 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostK8sCpuCap: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostK8sCpuCap', + map_field_to: 'kubernetes.node.name', + requires: ['kubernetes.node'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'capacity', + metrics: [ + { + field: 'kubernetes.node.cpu.allocatable.cores', + id: 'max-cpu-cap', + type: 'max', + }, + { + id: 'calc-nanocores', + type: 'calculation', + variables: [ + { + id: 'var-cores', + field: 'max-cpu-cap', + name: 'cores', + }, + ], + script: 'params.cores * 1000000000', + }, + ], + split_mode: 'everything', + }, + { + id: 'used', + metrics: [ + { + field: 'kubernetes.node.cpu.usage.nanocores', + id: 'avg-cpu-usage', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts new file mode 100644 index 0000000000000..8ac4c70d06fed --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts @@ -0,0 +1,44 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; +export const hostK8sDiskCap: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostK8sDiskCap', + map_field_to: 'kubernetes.node.name', + requires: ['kubernetes.node'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'capacity', + metrics: [ + { + field: 'kubernetes.node.fs.capacity.bytes', + id: 'max-fs-cap', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'used', + metrics: [ + { + field: 'kubernetes.node.fs.used.bytes', + id: 'avg-fs-used', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts new file mode 100644 index 0000000000000..6bf76b59dd60a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts @@ -0,0 +1,45 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostK8sMemoryCap: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostK8sMemoryCap', + map_field_to: 'kubernetes.node.name', + requires: ['kubernetes.node'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'capacity', + metrics: [ + { + field: 'kubernetes.node.memory.allocatable.bytes', + id: 'max-memory-cap', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'used', + metrics: [ + { + field: 'kubernetes.node.memory.usage.bytes', + id: 'avg-memory-usage', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts new file mode 100644 index 0000000000000..86d615231f070 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts @@ -0,0 +1,154 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostK8sOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostK8sOverview', + requires: ['kubernetes'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'gauge', + series: [ + { + id: 'cpucap', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.node.cpu.allocatable.cores', + id: 'max-cpu-cap', + type: 'max', + }, + { + field: 'kubernetes.node.cpu.usage.nanocores', + id: 'avg-cpu-usage', + type: 'avg', + }, + { + id: 'calc-used-cap', + script: 'params.used / (params.cap * 1000000000)', + type: 'calculation', + variables: [ + { + field: 'max-cpu-cap', + id: 'var-cap', + name: 'cap', + }, + { + field: 'avg-cpu-usage', + id: 'var-used', + name: 'used', + }, + ], + }, + ], + }, + { + id: 'diskcap', + metrics: [ + { + field: 'kubernetes.node.fs.capacity.bytes', + id: 'max-fs-cap', + type: 'max', + }, + { + field: 'kubernetes.node.fs.used.bytes', + id: 'avg-fs-used', + type: 'avg', + }, + { + id: 'calc-used-cap', + script: 'params.used / params.cap', + type: 'calculation', + variables: [ + { + field: 'max-fs-cap', + id: 'var-cap', + name: 'cap', + }, + { + field: 'avg-fs-used', + id: 'var-used', + name: 'used', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'memorycap', + metrics: [ + { + field: 'kubernetes.node.memory.allocatable.bytes', + id: 'max-memory-cap', + type: 'max', + }, + { + field: 'kubernetes.node.memory.usage.bytes', + id: 'avg-memory-usage', + type: 'avg', + }, + { + id: 'calc-used-cap', + script: 'params.used / params.cap', + type: 'calculation', + variables: [ + { + field: 'max-memory-cap', + id: 'var-cap', + name: 'cap', + }, + { + field: 'avg-memory-usage', + id: 'var-used', + name: 'used', + }, + ], + }, + ], + split_mode: 'everything', + }, + { + id: 'podcap', + metrics: [ + { + field: 'kubernetes.node.pod.capacity.total', + id: 'max-pod-cap', + type: 'max', + }, + { + field: 'kubernetes.pod.uid', + id: 'card-pod-name', + type: 'cardinality', + }, + { + id: 'calc-used-cap', + script: 'params.used / params.cap', + type: 'calculation', + variables: [ + { + field: 'max-pod-cap', + id: 'var-cap', + name: 'cap', + }, + { + field: 'card-pod-name', + id: 'var-used', + name: 'used', + }, + ], + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts new file mode 100644 index 0000000000000..e4c844f954599 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts @@ -0,0 +1,46 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostK8sPodCap: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostK8sPodCap', + requires: ['kubernetes.node'], + map_field_to: 'kubernetes.node.name', + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + + series: [ + { + id: 'capacity', + metrics: [ + { + field: 'kubernetes.node.pod.allocatable.total', + id: 'max-pod-cap', + type: 'max', + }, + ], + split_mode: 'everything', + }, + { + id: 'used', + metrics: [ + { + field: 'kubernetes.pod.uid', + id: 'avg-pod', + type: 'cardinality', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts new file mode 100644 index 0000000000000..dcee609e7acd7 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts @@ -0,0 +1,55 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostLoad: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostLoad', + requires: ['system.cpu'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'load_1m', + metrics: [ + { + field: 'system.load.1', + id: 'avg-load-1m', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + { + id: 'load_5m', + metrics: [ + { + field: 'system.load.5', + id: 'avg-load-5m', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + { + id: 'load_15m', + metrics: [ + { + field: 'system.load.15', + id: 'avg-load-15m', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts new file mode 100644 index 0000000000000..ef0f7b44912c7 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts @@ -0,0 +1,77 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostMemoryUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostMemoryUsage', + requires: ['system.memory'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'free', + metrics: [ + { + field: 'system.memory.free', + id: 'avg-memory-free', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + { + id: 'used', + metrics: [ + { + field: 'system.memory.actual.used.bytes', + id: 'avg-memory-used', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + { + id: 'cache', + metrics: [ + { + field: 'system.memory.actual.used.bytes', + id: 'avg-memory-actual-used', + type: 'avg', + }, + { + field: 'system.memory.used.bytes', + id: 'avg-memory-used', + type: 'avg', + }, + { + id: 'calc-used-actual', + script: 'params.used - params.actual', + type: 'calculation', + variables: [ + { + field: 'avg-memory-actual-used', + id: 'var-actual', + name: 'actual', + }, + { + field: 'avg-memory-used', + id: 'var-used', + name: 'used', + }, + ], + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts new file mode 100644 index 0000000000000..94eb03111e855 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts @@ -0,0 +1,92 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostNetworkTraffic: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostNetworkTraffic', + requires: ['system.network'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'tx', + metrics: [ + { + field: 'system.network.out.bytes', + id: 'max-net-out', + type: 'max', + }, + { + field: 'max-net-out', + id: 'deriv-max-net-out', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-out', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-out' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + function: 'sum', + id: 'seriesagg-sum', + type: 'series_agg', + }, + ], + split_mode: 'terms', + terms_field: 'system.network.name', + }, + { + id: 'rx', + metrics: [ + { + field: 'system.network.in.bytes', + id: 'max-net-in', + type: 'max', + }, + { + field: 'max-net-in', + id: 'deriv-max-net-in', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-in', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-in' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + id: 'calc-invert-rate', + script: 'params.rate * -1', + type: 'calculation', + variables: [ + { + field: 'posonly-deriv-max-net-in', + id: 'var-rate', + name: 'rate', + }, + ], + }, + { + function: 'sum', + id: 'seriesagg-sum', + type: 'series_agg', + }, + ], + split_mode: 'terms', + terms_field: 'system.network.name', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts new file mode 100644 index 0000000000000..953c14ab2a9ce --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts @@ -0,0 +1,145 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const hostSystemOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'hostSystemOverview', + requires: ['system.cpu', 'system.memory', 'system.load', 'system.network'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'gauge', + series: [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'system.cpu.user.pct', + id: 'avg-cpu-user', + type: 'avg', + }, + { + field: 'system.cpu.cores', + id: 'max-cpu-cores', + type: 'max', + }, + { + field: 'system.cpu.system.pct', + id: 'avg-cpu-system', + type: 'avg', + }, + { + id: 'calc-user-system-cores', + script: '(params.users + params.system) / params.cores', + type: 'calculation', + variables: [ + { + field: 'avg-cpu-user', + id: 'var-users', + name: 'users', + }, + { + field: 'avg-cpu-system', + id: 'var-system', + name: 'system', + }, + { + field: 'max-cpu-cores', + id: 'var-cores', + name: 'cores', + }, + ], + }, + ], + }, + { + id: 'load', + split_mode: 'everything', + metrics: [ + { + field: 'system.load.5', + id: 'avg-load-5m', + type: 'avg', + }, + ], + }, + { + id: 'memory', + split_mode: 'everything', + metrics: [ + { + field: 'system.memory.actual.used.pct', + id: 'avg-memory-actual-used', + type: 'avg', + }, + ], + }, + { + id: 'rx', + split_mode: 'terms', + terms_field: 'system.network.name', + metrics: [ + { + field: 'system.network.in.bytes', + id: 'max-net-in', + type: 'max', + }, + { + field: 'max-net-in', + id: 'deriv-max-net-in', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-in', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-in' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + function: 'sum', + id: 'seriesagg-sum', + type: 'series_agg', + }, + ], + }, + { + id: 'tx', + split_mode: 'terms', + terms_field: 'system.network.name', + metrics: [ + { + field: 'system.network.out.bytes', + id: 'max-net-out', + type: 'max', + }, + { + field: 'max-net-out', + id: 'deriv-max-net-out', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-out', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-out' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + function: 'sum', + id: 'seriesagg-sum', + type: 'series_agg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/host/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/host/toolbar_items.tsx new file mode 100644 index 0000000000000..f8df81a33a8ec --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/host/toolbar_items.tsx @@ -0,0 +1,35 @@ +/* + * 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 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'; + +export const HostToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.cpu, + InfraSnapshotMetricType.memory, + InfraSnapshotMetricType.load, + InfraSnapshotMetricType.rx, + InfraSnapshotMetricType.tx, + InfraSnapshotMetricType.logRate, + ]; + const groupByFields = [ + 'cloud.availability_zone', + 'cloud.machine.type', + 'cloud.project.id', + 'cloud.provider', + 'service.type', + ]; + return ( + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/index.ts b/x-pack/plugins/infra/common/inventory_models/index.ts new file mode 100644 index 0000000000000..d9fd8fa465b7a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/index.ts @@ -0,0 +1,65 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { host } from './host'; +import { pod } from './pod'; +import { awsEC2 } from './aws_ec2'; +import { awsS3 } from './aws_s3'; +import { awsRDS } from './aws_rds'; +import { awsSQS } from './aws_sqs'; +import { container } from './container'; +import { InventoryItemType } from './types'; +export { metrics } from './metrics'; + +export const inventoryModels = [host, pod, container, awsEC2, awsS3, awsRDS, awsSQS]; + +export const findInventoryModel = (type: InventoryItemType) => { + const model = inventoryModels.find(m => m.id === type); + if (!model) { + throw new Error( + i18n.translate('xpack.infra.inventoryModels.findInventoryModel.error', { + defaultMessage: "The inventory model you've attempted to find does not exist", + }) + ); + } + 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; + } +}; diff --git a/x-pack/plugins/infra/common/inventory_models/intl_strings.ts b/x-pack/plugins/infra/common/inventory_models/intl_strings.ts new file mode 100644 index 0000000000000..08949ed53eb10 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/intl_strings.ts @@ -0,0 +1,70 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +export const CPUUsage = i18n.translate('xpack.infra.waffle.metricOptions.cpuUsageText', { + defaultMessage: 'CPU usage', +}); + +export const MemoryUsage = i18n.translate('xpack.infra.waffle.metricOptions.memoryUsageText', { + defaultMessage: 'Memory usage', +}); + +export const InboundTraffic = i18n.translate( + 'xpack.infra.waffle.metricOptions.inboundTrafficText', + { + defaultMessage: 'Inbound traffic', + } +); + +export const OutboundTraffic = i18n.translate( + 'xpack.infra.waffle.metricOptions.outboundTrafficText', + { + defaultMessage: 'Outbound traffic', + } +); + +export const LogRate = i18n.translate('xpack.infra.waffle.metricOptions.hostLogRateText', { + defaultMessage: 'Log rate', +}); + +export const Load = i18n.translate('xpack.infra.waffle.metricOptions.loadText', { + defaultMessage: 'Load', +}); + +interface Lookup { + [id: string]: string; +} + +export const fieldToName = (field: string) => { + const LOOKUP: Lookup = { + 'kubernetes.namespace': i18n.translate('xpack.infra.groupByDisplayNames.kubernetesNamespace', { + defaultMessage: 'Namespace', + }), + 'kubernetes.node.name': i18n.translate('xpack.infra.groupByDisplayNames.kubernetesNodeName', { + defaultMessage: 'Node', + }), + '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.project.id': i18n.translate('xpack.infra.groupByDisplayNames.projectID', { + defaultMessage: 'Project ID', + }), + 'cloud.provider': i18n.translate('xpack.infra.groupByDisplayNames.provider', { + defaultMessage: 'Cloud provider', + }), + 'service.type': i18n.translate('xpack.infra.groupByDisplayNames.serviceType', { + defaultMessage: 'Service type', + }), + }; + return LOOKUP[field] || field; +}; diff --git a/x-pack/plugins/infra/common/inventory_models/layouts.ts b/x-pack/plugins/infra/common/inventory_models/layouts.ts new file mode 100644 index 0000000000000..d9008753adf7b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/layouts.ts @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/** + * WHY ARE THE LAYOUTS A SEPERATE FILE? + * + * Files with React can not be included on the server without + * crashing due to the requirement of the `window` object. + */ + +import { i18n } from '@kbn/i18n'; + +import { ReactNode, FunctionComponent } from 'react'; +import { Layout as HostLayout } from './host/layout'; +import { Layout as PodLayout } from './pod/layout'; +import { Layout as ContainerLayout } from './container/layout'; +import { Layout as AwsEC2Layout } from './aws_ec2/layout'; +import { Layout as AwsS3Layout } from './aws_s3/layout'; +import { Layout as AwsRDSLayout } from './aws_rds/layout'; +import { Layout as AwsSQSLayout } from './aws_sqs/layout'; +import { InventoryItemType } from './types'; +import { LayoutProps } from '../../public/pages/metrics/types'; + +interface Layouts { + [type: string]: ReactNode; +} + +const layouts: Layouts = { + host: HostLayout, + pod: PodLayout, + container: ContainerLayout, + awsEC2: AwsEC2Layout, + awsS3: AwsS3Layout, + awsRDS: AwsRDSLayout, + awsSQS: AwsSQSLayout, +}; + +export const findLayout = (type: InventoryItemType) => { + const Layout = layouts?.[type]; + if (!Layout) { + throw new Error( + i18n.translate('xpack.infra.inventoryModels.findLayout.error', { + defaultMessage: "The layout you've attempted to find does not exist", + }) + ); + } + return Layout as FunctionComponent; +}; diff --git a/x-pack/plugins/infra/common/inventory_models/metrics.ts b/x-pack/plugins/infra/common/inventory_models/metrics.ts new file mode 100644 index 0000000000000..cadc059fc5aeb --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/metrics.ts @@ -0,0 +1,27 @@ +/* + * 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 { metrics as hostMetrics } from './host/metrics'; +import { metrics as sharedMetrics } from './shared/metrics'; +import { metrics as podMetrics } from './pod/metrics'; +import { metrics as containerMetrics } from './container/metrics'; +import { metrics as awsEC2Metrics } from './aws_ec2/metrics'; +import { metrics as awsS3Metrics } from './aws_s3/metrics'; +import { metrics as awsRDSMetrics } from './aws_rds/metrics'; +import { metrics as awsSQSMetrics } from './aws_sqs/metrics'; + +export const metrics = { + tsvb: { + ...hostMetrics.tsvb, + ...sharedMetrics.tsvb, + ...podMetrics.tsvb, + ...containerMetrics.tsvb, + ...awsEC2Metrics.tsvb, + ...awsS3Metrics.tsvb, + ...awsRDSMetrics.tsvb, + ...awsSQSMetrics.tsvb, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/index.ts b/x-pack/plugins/infra/common/inventory_models/pod/index.ts new file mode 100644 index 0000000000000..f76a0304e26c0 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/index.ts @@ -0,0 +1,37 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; +import { nginx as nginxRequiredMetrics } from '../shared/metrics/required_metrics'; + +export const pod: InventoryModel = { + id: 'pod', + displayName: i18n.translate('xpack.infra.inventoryModel.pod.displayName', { + defaultMessage: 'Kubernetes Pods', + }), + requiredModule: 'kubernetes', + crosslinkSupport: { + details: true, + logs: true, + apm: true, + uptime: true, + }, + fields: { + id: 'kubernetes.pod.uid', + name: 'kubernetes.pod.name', + ip: 'kubernetes.pod.ip', + }, + metrics, + requiredMetrics: [ + 'podOverview', + 'podCpuUsage', + 'podMemoryUsage', + 'podNetworkTraffic', + ...nginxRequiredMetrics, + ], +}; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/layout.tsx b/x-pack/plugins/infra/common/inventory_models/pod/layout.tsx new file mode 100644 index 0000000000000..f0c27ccff13b1 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/layout.tsx @@ -0,0 +1,159 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types'; +import { Section } from '../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../public/pages/metrics/components/sub_section'; +import { GaugesSectionVis } from '../../../public/pages/metrics/components/gauges_section_vis'; +import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../common/eui_styled_components'; +import * as Nginx from '../shared/layouts/nginx'; +import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details'; +import { LayoutContent } from '../../../public/pages/metrics/components/layout_content'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + + + +
+ + + + + + + + + + + + +
+ +
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/index.ts new file mode 100644 index 0000000000000..b4420b5532cc6 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/index.ts @@ -0,0 +1,30 @@ +/* + * 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 { cpu } from './snapshot/cpu'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { podOverview } from './tsvb/pod_overview'; +import { podCpuUsage } from './tsvb/pod_cpu_usage'; +import { podLogUsage } from './tsvb/pod_log_usage'; +import { podMemoryUsage } from './tsvb/pod_memory_usage'; +import { podNetworkTraffic } from './tsvb/pod_network_traffic'; +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + podOverview, + podCpuUsage, + podLogUsage, + podNetworkTraffic, + podMemoryUsage, + }, + snapshot: { cpu, memory, rx, tx }, + defaultSnapshot: 'cpu', + defaultTimeRangeInSeconds: 3600, // 1 hour +}; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..f25dd8179aa1a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts @@ -0,0 +1,15 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu: { + avg: { + field: 'kubernetes.pod.cpu.usage.node.pct', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..28a71d9b0275a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts @@ -0,0 +1,11 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { + memory: { avg: { field: 'kubernetes.pod.memory.usage.node.pct' } }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..e9e1b1ddd9b41 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts @@ -0,0 +1,8 @@ +/* + * 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 { networkTraffic } from '../../../shared/metrics/snapshot/network_traffic'; +export const rx = networkTraffic('rx', 'kubernetes.pod.network.rx.bytes'); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..198355ca29ff6 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts @@ -0,0 +1,8 @@ +/* + * 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 { networkTraffic } from '../../../shared/metrics/snapshot/network_traffic'; +export const tx = networkTraffic('tx', 'kubernetes.pod.network.tx.bytes'); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts new file mode 100644 index 0000000000000..1d778d11e0725 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const podCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'podCpuUsage', + requires: ['kubernetes.pod'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.cpu.usage.node.pct', + id: 'avg-cpu-usage', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts new file mode 100644 index 0000000000000..d960322a477aa --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts @@ -0,0 +1,55 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const podLogUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'podLogUsage', + requires: ['kubernetes.pod'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'logs', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.container.logs.used.bytes', + id: 'avg-log-used', + type: 'avg', + }, + { + field: 'kubernetes.container.logs.capacity.bytes', + id: 'max-log-cap', + type: 'max', + }, + { + id: 'calc-usage-limit', + script: 'params.usage / params.limit', + type: 'calculation', + variables: [ + { + field: 'avg-log-userd', + id: 'var-usage', + name: 'usage', + }, + { + field: 'max-log-cap', + id: 'var-limit', + name: 'limit', + }, + ], + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts new file mode 100644 index 0000000000000..8dd63787c605a --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const podMemoryUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'podMemoryUsage', + requires: ['kubernetes.pod'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'memory', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.memory.usage.node.pct', + id: 'avg-memory-usage', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts new file mode 100644 index 0000000000000..139e592609ae1 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts @@ -0,0 +1,80 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const podNetworkTraffic: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'podNetworkTraffic', + requires: ['kubernetes.pod'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'tx', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.network.tx.bytes', + id: 'max-network-tx', + type: 'max', + }, + { + field: 'max-network-tx', + id: 'deriv-max-network-tx', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-tx', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + }, + { + id: 'rx', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.network.rx.bytes', + id: 'max-network-rx', + type: 'max', + }, + { + field: 'max-network-rx', + id: 'deriv-max-network-rx', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-net-tx', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + { + id: 'invert-posonly-deriv-max-network-rx', + script: 'params.rate * -1', + type: 'calculation', + variables: [ + { + field: 'posonly-deriv-max-network-rx', + id: 'var-rate', + name: 'rate', + }, + ], + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts new file mode 100644 index 0000000000000..129cbd96eb2ce --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts @@ -0,0 +1,90 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const podOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'podOverview', + requires: ['kubernetes.pod'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'cpu', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.cpu.usage.node.pct', + id: 'avg-cpu-usage', + type: 'avg', + }, + ], + }, + { + id: 'memory', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.memory.usage.node.pct', + id: 'avg-memory-usage', + type: 'avg', + }, + ], + }, + { + id: 'rx', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.network.rx.bytes', + id: 'max-network-rx', + type: 'max', + }, + { + field: 'max-network-rx', + id: 'deriv-max-network-rx', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-network-rx', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-rx' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + }, + { + id: 'tx', + split_mode: 'everything', + metrics: [ + { + field: 'kubernetes.pod.network.tx.bytes', + id: 'max-network-tx', + type: 'max', + }, + { + field: 'max-network-tx', + id: 'deriv-max-network-tx', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-deriv-max-network-tx', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/pod/toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/pod/toolbar_items.tsx new file mode 100644 index 0000000000000..9ef4a889dc589 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/pod/toolbar_items.tsx @@ -0,0 +1,27 @@ +/* + * 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 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'; + +export const PodToolbarItems = (props: ToolbarProps) => { + const metricTypes = [ + InfraSnapshotMetricType.cpu, + InfraSnapshotMetricType.memory, + InfraSnapshotMetricType.rx, + InfraSnapshotMetricType.tx, + ]; + const groupByFields = ['kubernetes.namespace', 'kubernetes.node.name', 'service.type']; + return ( + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/compontents/cloud_toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/shared/compontents/cloud_toolbar_items.tsx new file mode 100644 index 0000000000000..7150d58be4eb7 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/compontents/cloud_toolbar_items.tsx @@ -0,0 +1,38 @@ +/* + * 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 React from 'react'; +import { EuiFlexItem } from '@elastic/eui'; +import { ToolbarProps } from '../../../../public/components/inventory/toolbars/toolbar'; +import { WaffleAccountsControls } from '../../../../public/components/waffle/waffle_accounts_controls'; +import { WaffleRegionControls } from '../../../../public/components/waffle/waffle_region_controls'; + +type Props = ToolbarProps; + +export const CloudToolbarItems = (props: Props) => { + return ( + <> + {props.accounts.length > 0 && ( + + + + )} + {props.regions.length > 0 && ( + + + + )} + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/compontents/metrics_and_groupby_toolbar_items.tsx b/x-pack/plugins/infra/common/inventory_models/shared/compontents/metrics_and_groupby_toolbar_items.tsx new file mode 100644 index 0000000000000..c46ad5c6df952 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/compontents/metrics_and_groupby_toolbar_items.tsx @@ -0,0 +1,52 @@ +/* + * 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 React, { useMemo } from 'react'; +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'; + +interface Props extends ToolbarProps { + metricTypes: InfraSnapshotMetricType[]; + groupByFields: string[]; +} + +export const MetricsAndGroupByToolbarItems = (props: Props) => { + const metricOptions = useMemo(() => props.metricTypes.map(toMetricOpt), [props.metricTypes]); + + const groupByOptions = useMemo(() => props.groupByFields.map(toGroupByOpt), [ + props.groupByFields, + ]); + + return ( + <> + + + + + + + + ); +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/layouts/aws.tsx b/x-pack/plugins/infra/common/inventory_models/shared/layouts/aws.tsx new file mode 100644 index 0000000000000..2cabbe4c33ff3 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/layouts/aws.tsx @@ -0,0 +1,237 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../../public/pages/metrics/types'; +import { Section } from '../../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../../public/pages/metrics/components/sub_section'; +import { GaugesSectionVis } from '../../../../public/pages/metrics/components/gauges_section_vis'; +import { ChartSectionVis } from '../../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../../common/eui_styled_components'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + +
+ + + + + + + + + + + + + + + + + + +
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/layouts/nginx.tsx b/x-pack/plugins/infra/common/inventory_models/shared/layouts/nginx.tsx new file mode 100644 index 0000000000000..9d31ffa775d21 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/layouts/nginx.tsx @@ -0,0 +1,103 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { LayoutPropsWithTheme } from '../../../../public/pages/metrics/types'; +import { Section } from '../../../../public/pages/metrics/components/section'; +import { SubSection } from '../../../../public/pages/metrics/components/sub_section'; +import { ChartSectionVis } from '../../../../public/pages/metrics/components/chart_section_vis'; +import { withTheme } from '../../../../../../common/eui_styled_components'; + +export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => ( + +
+ + + + + + + + + + + + +
+
+)); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/index.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/index.ts new file mode 100644 index 0000000000000..2bab5c5229c5b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/index.ts @@ -0,0 +1,39 @@ +/* + * 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 { nginxRequestRate } from './tsvb/nginx_request_rate'; +import { nginxActiveConnections } from './tsvb/nginx_active_connections'; +import { nginxHits } from './tsvb/nginx_hits'; +import { nginxRequestsPerConnection } from './tsvb/nginx_requests_per_connection'; + +import { awsCpuUtilization } from './tsvb/aws_cpu_utilization'; +import { awsDiskioBytes } from './tsvb/aws_diskio_bytes'; +import { awsDiskioOps } from './tsvb/aws_diskio_ops'; +import { awsNetworkBytes } from './tsvb/aws_network_bytes'; +import { awsNetworkPackets } from './tsvb/aws_network_packets'; +import { awsOverview } from './tsvb/aws_overview'; +import { InventoryMetrics } from '../../types'; +import { count } from './snapshot/count'; + +export const metrics: InventoryMetrics = { + tsvb: { + nginxActiveConnections, + nginxHits, + nginxRequestRate, + nginxRequestsPerConnection, + awsCpuUtilization, + awsDiskioBytes, + awsDiskioOps, + awsNetworkBytes, + awsNetworkPackets, + awsOverview, + }, + snapshot: { + count, + }, + defaultSnapshot: 'count', + defaultTimeRangeInSeconds: 3600, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/required_metrics.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/required_metrics.ts new file mode 100644 index 0000000000000..0b2623c448646 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/required_metrics.ts @@ -0,0 +1,23 @@ +/* + * 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 { InventoryMetric } from '../../types'; + +export const nginx: InventoryMetric[] = [ + 'nginxHits', + 'nginxRequestRate', + 'nginxActiveConnections', + 'nginxRequestsPerConnection', +]; + +export const aws: InventoryMetric[] = [ + 'awsOverview', + 'awsCpuUtilization', + 'awsNetworkBytes', + 'awsNetworkPackets', + 'awsDiskioOps', + 'awsDiskioBytes', +]; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts new file mode 100644 index 0000000000000..ed8398a5d4a77 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts @@ -0,0 +1,20 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const count: SnapshotModel = { + count: { + bucket_script: { + buckets_path: { count: '_count' }, + script: { + source: 'count * 1', + lang: 'expression', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts new file mode 100644 index 0000000000000..37e90a6416ba7 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts @@ -0,0 +1,30 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const networkTraffic = (id: string, field: string): SnapshotModel => { + return { + [`${id}_max`]: { max: { field } }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_max`, + gap_policy: 'skip', + unit: '1s', + }, + }, + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, + }; +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts new file mode 100644 index 0000000000000..1ba5cf037e708 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts @@ -0,0 +1,42 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const networkTrafficWithInterfaces = ( + id: string, + metricField: string, + interfaceField: string +): SnapshotModel => ({ + [`${id}_interfaces`]: { + terms: { field: interfaceField }, + aggregations: { + [`${id}_interface_max`]: { max: { field: metricField } }, + }, + }, + [`${id}_sum_of_interfaces`]: { + sum_bucket: { + buckets_path: `${id}_interfaces>${id}_interface_max`, + }, + }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_sum_of_interfaces`, + gap_policy: 'skip', + unit: '1s', + }, + }, + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts new file mode 100644 index 0000000000000..e1c7c7df52628 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts @@ -0,0 +1,30 @@ +/* + * 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 { SnapshotModel } from '../../../types'; + +export const rate = (id: string, field: string): SnapshotModel => { + return { + [`${id}_max`]: { max: { field } }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_max`, + gap_policy: 'skip', + unit: '1s', + }, + }, + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, + }; +}; diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts new file mode 100644 index 0000000000000..9092d8f3f5d54 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts @@ -0,0 +1,34 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const awsCpuUtilization: TSVBMetricModelCreator = ( + timeField, + indexPattern +): TSVBMetricModel => ({ + id: 'awsCpuUtilization', + requires: ['aws.ec2'], + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + index_pattern: indexPattern, + interval: '>=5m', + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'cpu-util', + metrics: [ + { + field: 'aws.ec2.cpu.total.pct', + id: 'avg-cpu-util', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts new file mode 100644 index 0000000000000..8abb6f5d5ddff --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts @@ -0,0 +1,83 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const awsDiskioBytes: TSVBMetricModelCreator = ( + timeField, + indexPattern +): TSVBMetricModel => ({ + id: 'awsDiskioBytes', + requires: ['aws.ec2'], + index_pattern: indexPattern, + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + interval: '>=5m', + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'writes', + metrics: [ + { + field: 'aws.ec2.diskio.write.bytes', + id: 'sum-diskio-out', + type: 'sum', + }, + { + id: 'csum-sum-diskio-out', + field: 'sum-diskio-out', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-diskio-out', + unit: '1s', + type: 'derivative', + field: 'csum-sum-diskio-out', + }, + { + id: 'posonly-deriv-csum-sum-diskio-out', + field: 'deriv-csum-sum-diskio-out', + type: 'positive_only', + }, + ], + split_mode: 'everything', + }, + { + id: 'reads', + metrics: [ + { + field: 'aws.ec2.diskio.read.bytes', + id: 'sum-diskio-in', + type: 'sum', + }, + { + id: 'csum-sum-diskio-in', + field: 'sum-diskio-in', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-diskio-in', + unit: '1s', + type: 'derivative', + field: 'csum-sum-diskio-in', + }, + { + id: 'posonly-deriv-csum-sum-diskio-in', + field: 'deriv-csum-sum-diskio-in', + type: 'positive_only', + }, + { + id: 'inverted-posonly-deriv-csum-sum-diskio-in', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-diskio-in' }], + script: 'params.rate * -1', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts new file mode 100644 index 0000000000000..d81438e3b5a61 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts @@ -0,0 +1,81 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const awsDiskioOps: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ + id: 'awsDiskioOps', + requires: ['aws.ec2'], + index_pattern: indexPattern, + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + interval: '>=5m', + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'writes', + metrics: [ + { + field: 'aws.ec2.diskio.write.count', + id: 'sum-diskio-writes', + type: 'sum', + }, + { + id: 'csum-sum-diskio-writes', + field: 'sum-diskio-writes', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-diskio-writes', + unit: '1s', + type: 'derivative', + field: 'csum-sum-diskio-writes', + }, + { + id: 'posonly-deriv-csum-sum-diskio-writes', + field: 'deriv-csum-sum-diskio-writes', + type: 'positive_only', + }, + ], + split_mode: 'everything', + }, + { + id: 'reads', + metrics: [ + { + field: 'aws.ec2.diskio.read.count', + id: 'sum-diskio-reads', + type: 'sum', + }, + { + id: 'csum-sum-diskio-reads', + field: 'sum-diskio-reads', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-diskio-reads', + unit: '1s', + type: 'derivative', + field: 'csum-sum-diskio-reads', + }, + { + id: 'posonly-deriv-csum-sum-diskio-reads', + field: 'deriv-csum-sum-diskio-reads', + type: 'positive_only', + }, + { + id: 'inverted-posonly-deriv-csum-sum-diskio-reads', + type: 'calculation', + variables: [ + { id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-diskio-reads' }, + ], + script: 'params.rate * -1', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts new file mode 100644 index 0000000000000..bbae45a5b4b8e --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts @@ -0,0 +1,85 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +// see discussion in: https://github.com/elastic/kibana/issues/42687 + +export const awsNetworkBytes: TSVBMetricModelCreator = ( + timeField, + indexPattern +): TSVBMetricModel => ({ + id: 'awsNetworkBytes', + requires: ['aws.ec2'], + index_pattern: indexPattern, + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + interval: '>=5m', + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'tx', + metrics: [ + { + field: 'aws.ec2.network.out.bytes', + id: 'sum-net-out', + type: 'sum', + }, + { + id: 'csum-sum-net-out', + field: 'sum-net-out', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-net-out', + unit: '1s', + type: 'derivative', + field: 'csum-sum-net-out', + }, + { + id: 'posonly-deriv-csum-sum-net-out', + field: 'deriv-csum-sum-net-out', + type: 'positive_only', + }, + ], + split_mode: 'everything', + }, + { + id: 'rx', + metrics: [ + { + field: 'aws.ec2.network.in.bytes', + id: 'sum-net-in', + type: 'sum', + }, + { + id: 'csum-sum-net-in', + field: 'sum-net-in', + type: 'cumulative_sum', + }, + { + id: 'deriv-csum-sum-net-in', + unit: '1s', + type: 'derivative', + field: 'csum-sum-net-in', + }, + { + id: 'posonly-deriv-csum-sum-net-in', + field: 'deriv-csum-sum-net-in', + type: 'positive_only', + }, + { + id: 'inverted-posonly-deriv-csum-sum-net-in', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-net-in' }], + script: 'params.rate * -1', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts new file mode 100644 index 0000000000000..e2e6c4846a412 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts @@ -0,0 +1,51 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const awsNetworkPackets: TSVBMetricModelCreator = ( + timeField, + indexPattern +): TSVBMetricModel => ({ + id: 'awsNetworkPackets', + requires: ['aws.ec2'], + index_pattern: indexPattern, + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + interval: '>=5m', + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'packets-out', + metrics: [ + { + field: 'aws.ec2.network.out.packets', + id: 'avg-net-out', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + { + id: 'packets-in', + metrics: [ + { + field: 'aws.ec2.network.in.packets', + id: 'avg-net-in', + type: 'avg', + }, + { + id: 'inverted-avg-net-in', + type: 'calculation', + variables: [{ id: 'var-avg', name: 'avg', field: 'avg-net-in' }], + script: 'params.avg * -1', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts new file mode 100644 index 0000000000000..5ba61d1f92517 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts @@ -0,0 +1,64 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const awsOverview: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ + id: 'awsOverview', + requires: ['aws.ec2'], + index_pattern: indexPattern, + map_field_to: 'cloud.instance.id', + id_type: 'cloud', + interval: '>=5m', + time_field: timeField, + type: 'gauge', + series: [ + { + id: 'cpu-util', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.cpu.total.pct', + id: 'cpu-total-pct', + type: 'max', + }, + ], + }, + { + id: 'status-check-failed', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.status.check_failed', + id: 'status-check-failed', + type: 'max', + }, + ], + }, + { + id: 'packets-out', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.network.out.packets', + id: 'network-out-packets', + type: 'avg', + }, + ], + }, + { + id: 'packets-in', + split_mode: 'everything', + metrics: [ + { + field: 'aws.ec2.network.in.packets', + id: 'network-in-packets', + type: 'avg', + }, + ], + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts new file mode 100644 index 0000000000000..61e7fc88496a3 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts @@ -0,0 +1,33 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const nginxActiveConnections: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'nginxActiveConnections', + requires: ['nginx.stubstatus'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'connections', + metrics: [ + { + field: 'nginx.stubstatus.active', + id: 'avg-active', + type: 'avg', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts new file mode 100644 index 0000000000000..546102ec0ad8b --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts @@ -0,0 +1,78 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const nginxHits: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'nginxHits', + requires: ['nginx.access'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: '200s', + metrics: [ + { + id: 'count-200', + type: 'count', + }, + ], + split_mode: 'filter', + filter: { + query: 'http.response.status_code:[200 TO 299]', + language: 'lucene', + }, + }, + { + id: '300s', + metrics: [ + { + id: 'count-300', + type: 'count', + }, + ], + split_mode: 'filter', + filter: { + query: 'http.response.status_code:[300 TO 399]', + language: 'lucene', + }, + }, + { + id: '400s', + metrics: [ + { + id: 'count-400', + type: 'count', + }, + ], + split_mode: 'filter', + filter: { + query: 'http.response.status_code:[400 TO 499]', + language: 'lucene', + }, + }, + { + id: '500s', + metrics: [ + { + id: 'count-500', + type: 'count', + }, + ], + split_mode: 'filter', + filter: { + query: 'http.response.status_code:[500 TO 599]', + language: 'lucene', + }, + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts new file mode 100644 index 0000000000000..5904ba62cd309 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts @@ -0,0 +1,44 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const nginxRequestRate: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'nginxRequestRate', + requires: ['nginx.stubstatus'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'rate', + metrics: [ + { + field: 'nginx.stubstatus.requests', + id: 'max-requests', + type: 'max', + }, + { + field: 'max-requests', + id: 'derv-max-requests', + type: 'derivative', + unit: '1s', + }, + { + id: 'posonly-derv-max-requests', + type: 'calculation', + variables: [{ id: 'var-rate', name: 'rate', field: 'derv-max-requests' }], + script: 'params.rate > 0.0 ? params.rate : 0.0', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts new file mode 100644 index 0000000000000..c76d5a9edf8fc --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts @@ -0,0 +1,48 @@ +/* + * 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 { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; + +export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'nginxRequestsPerConnection', + requires: ['nginx.stubstatus'], + index_pattern: indexPattern, + interval, + time_field: timeField, + type: 'timeseries', + series: [ + { + id: 'reqPerConns', + metrics: [ + { + field: 'nginx.stubstatus.handled', + id: 'max-handled', + type: 'max', + }, + { + field: 'nginx.stubstatus.requests', + id: 'max-requests', + type: 'max', + }, + { + id: 'reqs-per-connection', + type: 'calculation', + variables: [ + { id: 'var-handled', name: 'handled', field: 'max-handled' }, + { id: 'var-requests', name: 'requests', field: 'max-requests' }, + ], + script: + 'params.handled > 0.0 && params.requests > 0.0 ? params.handled / params.requests : 0.0', + }, + ], + split_mode: 'everything', + }, + ], +}); diff --git a/x-pack/plugins/infra/common/inventory_models/toolbars.ts b/x-pack/plugins/infra/common/inventory_models/toolbars.ts new file mode 100644 index 0000000000000..05def078c7f2d --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/toolbars.ts @@ -0,0 +1,43 @@ +/* + * 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 { ReactNode, FunctionComponent } from 'react'; +import { i18n } from '@kbn/i18n'; +import { InventoryItemType } from './types'; +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'; +import { AwsS3ToolbarItems } from './aws_s3/toolbar_items'; +import { AwsRDSToolbarItems } from './aws_rds/toolbar_items'; +import { AwsSQSToolbarItems } from './aws_sqs/toolbar_items'; + +interface Toolbars { + [type: string]: ReactNode; +} + +const toolbars: Toolbars = { + host: HostToolbarItems, + container: ContainerToolbarItems, + pod: PodToolbarItems, + awsEC2: AwsEC2ToolbarItems, + awsS3: AwsS3ToolbarItems, + awsRDS: AwsRDSToolbarItems, + awsSQS: AwsSQSToolbarItems, +}; + +export const findToolbar = (type: InventoryItemType) => { + const Toolbar = toolbars?.[type]; + if (!Toolbar) { + throw new Error( + i18n.translate('xpack.infra.inventoryModels.findToolbar.error', { + defaultMessage: "The toolbar you've attempted to find does not exist.", + }) + ); + } + return Toolbar as FunctionComponent; +}; diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts new file mode 100644 index 0000000000000..cc2396547edc4 --- /dev/null +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -0,0 +1,337 @@ +/* + * 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 * as rt from 'io-ts'; + +export const ItemTypeRT = rt.keyof({ + host: null, + pod: null, + container: null, + awsEC2: null, + awsS3: null, + awsSQS: null, + awsRDS: null, +}); + +export const InventoryVisTypeRT = rt.keyof({ + line: null, + area: null, + bar: null, +}); + +export type InventoryVisType = rt.TypeOf; + +export const InventoryFormatterTypeRT = rt.keyof({ + abbreviatedNumber: null, + bits: null, + bytes: null, + number: null, + percent: null, + highPercision: null, +}); +export type InventoryFormatterType = rt.TypeOf; +export type InventoryItemType = rt.TypeOf; + +export const InventoryMetricRT = rt.keyof({ + hostSystemOverview: null, + hostCpuUsage: null, + hostFilesystem: null, + hostK8sOverview: null, + hostK8sCpuCap: null, + hostK8sDiskCap: null, + hostK8sMemoryCap: null, + hostK8sPodCap: null, + hostLoad: null, + hostMemoryUsage: null, + hostNetworkTraffic: null, + hostDockerOverview: null, + hostDockerInfo: null, + hostDockerTop5ByCpu: null, + hostDockerTop5ByMemory: null, + podOverview: null, + podCpuUsage: null, + podMemoryUsage: null, + podLogUsage: null, + podNetworkTraffic: null, + containerOverview: null, + containerCpuKernel: null, + containerCpuUsage: null, + containerDiskIOOps: null, + containerDiskIOBytes: null, + containerMemory: null, + containerNetworkTraffic: null, + nginxHits: null, + nginxRequestRate: null, + nginxActiveConnections: null, + nginxRequestsPerConnection: null, + awsOverview: null, + awsCpuUtilization: null, + awsNetworkBytes: null, + awsNetworkPackets: null, + awsDiskioBytes: null, + awsDiskioOps: null, + awsEC2CpuUtilization: null, + awsEC2NetworkTraffic: null, + awsEC2DiskIOBytes: null, + awsS3TotalRequests: null, + awsS3NumberOfObjects: null, + awsS3BucketSize: null, + awsS3DownloadBytes: null, + awsS3UploadBytes: null, + awsRDSCpuTotal: null, + awsRDSConnections: null, + awsRDSQueriesExecuted: null, + awsRDSActiveTransactions: null, + awsRDSLatency: null, + awsSQSMessagesVisible: null, + awsSQSMessagesDelayed: null, + awsSQSMessagesSent: null, + awsSQSMessagesEmpty: null, + awsSQSOldestMessage: null, + custom: null, +}); +export type InventoryMetric = rt.TypeOf; + +export const TSVBMetricTypeRT = rt.keyof({ + avg: null, + max: null, + min: null, + calculation: null, + cardinality: null, + series_agg: null, + positive_only: null, + derivative: null, + count: null, + sum: null, + cumulative_sum: null, +}); + +export type TSVBMetricType = rt.TypeOf; + +export const TSVBMetricModelCountRT = rt.type({ + id: rt.string, + type: rt.literal('count'), +}); + +export const TSVBMetricModelBasicMetricRT = rt.intersection([ + rt.type({ + id: rt.string, + type: TSVBMetricTypeRT, + }), + rt.partial({ + field: rt.string, + }), +]); + +export const TSVBMetricModelVariableRT = rt.type({ + field: rt.string, + id: rt.string, + name: rt.string, +}); + +export const TSVBMetricModelBucketScriptRT = rt.type({ + id: rt.string, + script: rt.string, + type: rt.literal('calculation'), + variables: rt.array(TSVBMetricModelVariableRT), +}); + +export const TSVBMetricModelDerivativeRT = rt.type({ + id: rt.string, + field: rt.string, + unit: rt.string, + type: rt.literal('derivative'), +}); + +export const TSVBMetricModelSeriesAggRT = rt.type({ + id: rt.string, + function: rt.string, + type: rt.literal('series_agg'), +}); + +export const TSVBMetricRT = rt.union([ + TSVBMetricModelCountRT, + TSVBMetricModelBasicMetricRT, + TSVBMetricModelBucketScriptRT, + TSVBMetricModelDerivativeRT, + TSVBMetricModelSeriesAggRT, +]); +export type TSVBMetric = rt.TypeOf; + +export const TSVBSeriesRT = rt.intersection([ + rt.type({ + id: rt.string, + metrics: rt.array(TSVBMetricRT), + split_mode: rt.string, + }), + rt.partial({ + terms_field: rt.string, + terms_size: rt.number, + terms_order_by: rt.string, + filter: rt.type({ + query: rt.string, + language: rt.keyof({ + lucene: null, + kuery: null, + }), + }), + }), +]); + +export type TSVBSeries = rt.TypeOf; + +export const TSVBMetricModelRT = rt.intersection([ + rt.type({ + id: InventoryMetricRT, + requires: rt.array(rt.string), + index_pattern: rt.union([rt.string, rt.array(rt.string)]), + interval: rt.string, + time_field: rt.string, + type: rt.string, + series: rt.array(TSVBSeriesRT), + }), + rt.partial({ + filter: rt.string, + map_field_to: rt.string, + id_type: rt.keyof({ cloud: null, node: null }), + drop_last_bucket: rt.boolean, + }), +]); + +export type TSVBMetricModel = rt.TypeOf; + +export type TSVBMetricModelCreator = ( + timeField: string, + indexPattern: string | string[], + interval: string +) => TSVBMetricModel; + +export const SnapshotModelMetricAggRT = rt.record( + rt.string, + rt.union([ + rt.undefined, + rt.type({ + field: rt.string, + }), + ]) +); + +export const SnapshotModelBucketScriptRT = rt.type({ + bucket_script: rt.intersection([ + rt.type({ + buckets_path: rt.record(rt.string, rt.union([rt.undefined, rt.string])), + script: rt.type({ + source: rt.string, + lang: rt.keyof({ painless: null, expression: null }), + }), + }), + rt.partial({ gap_policy: rt.keyof({ skip: null, insert_zeros: null }) }), + ]), +}); + +export const SnapshotModelCumulativeSumRT = rt.type({ + cumulative_sum: rt.type({ + buckets_path: rt.string, + }), +}); + +export const SnapshotModelDerivativeRT = rt.type({ + derivative: rt.type({ + buckets_path: rt.string, + gap_policy: rt.keyof({ skip: null, insert_zeros: null }), + unit: rt.string, + }), +}); + +export const SnapshotModelSumBucketRT = rt.type({ + sum_bucket: rt.type({ + buckets_path: rt.string, + }), +}); + +interface SnapshotTermsWithAggregation { + terms: { field: string }; + aggregations: SnapshotModel; +} + +export const SnapshotTermsWithAggregationRT: rt.Type = rt.recursion( + 'SnapshotModelRT', + () => + rt.type({ + terms: rt.type({ field: rt.string }), + aggregations: SnapshotModelRT, + }) +); + +export const SnapshotModelAggregationRT = rt.union([ + SnapshotModelMetricAggRT, + SnapshotModelBucketScriptRT, + SnapshotModelCumulativeSumRT, + SnapshotModelDerivativeRT, + SnapshotModelSumBucketRT, + SnapshotTermsWithAggregationRT, +]); + +export const SnapshotModelRT = rt.record( + rt.string, + rt.union([rt.undefined, SnapshotModelAggregationRT]) +); +export type SnapshotModel = rt.TypeOf; + +export const SnapshotMetricTypeRT = rt.keyof({ + count: null, + cpu: null, + load: null, + memory: null, + tx: null, + rx: null, + logRate: null, + diskIOReadBytes: null, + diskIOWriteBytes: null, + s3TotalRequests: null, + s3NumberOfObjects: null, + s3BucketSize: null, + s3DownloadBytes: null, + s3UploadBytes: null, + rdsConnections: null, + rdsQueriesExecuted: null, + rdsActiveTransactions: null, + rdsLatency: null, + sqsMessagesVisible: null, + sqsMessagesDelayed: null, + sqsMessagesSent: null, + sqsMessagesEmpty: null, + sqsOldestMessage: null, +}); + +export type SnapshotMetricType = rt.TypeOf; + +export interface InventoryMetrics { + tsvb: { [name: string]: TSVBMetricModelCreator }; + snapshot: { [name: string]: SnapshotModel }; + defaultSnapshot: SnapshotMetricType; + /** This is used by the inventory view to calculate the appropriate amount of time for the metrics detail page. Some metris like awsS3 require multiple days where others like host only need an hour.*/ + defaultTimeRangeInSeconds: number; +} + +export interface InventoryModel { + id: string; + displayName: string; + requiredModule: string; + fields: { + id: string; + name: string; + ip?: string; + }; + crosslinkSupport: { + details: boolean; + logs: boolean; + apm: boolean; + uptime: boolean; + }; + metrics: InventoryMetrics; + requiredMetrics: InventoryMetric[]; +} diff --git a/x-pack/plugins/infra/common/log_analysis/index.ts b/x-pack/plugins/infra/common/log_analysis/index.ts new file mode 100644 index 0000000000000..79913f829191d --- /dev/null +++ b/x-pack/plugins/infra/common/log_analysis/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './log_analysis'; +export * from './job_parameters'; diff --git a/x-pack/plugins/infra/common/log_analysis/job_parameters.ts b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts new file mode 100644 index 0000000000000..8c08e24d8665d --- /dev/null +++ b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts @@ -0,0 +1,30 @@ +/* + * 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 * as rt from 'io-ts'; + +export const bucketSpan = 900000; + +export const categoriesMessageField = 'message'; + +export const partitionField = 'event.dataset'; + +export const getJobIdPrefix = (spaceId: string, sourceId: string) => + `kibana-logs-ui-${spaceId}-${sourceId}-`; + +export const getJobId = (spaceId: string, sourceId: string, jobType: string) => + `${getJobIdPrefix(spaceId, sourceId)}${jobType}`; + +export const getDatafeedId = (spaceId: string, sourceId: string, jobType: string) => + `datafeed-${getJobId(spaceId, sourceId, jobType)}`; + +export const jobSourceConfigurationRT = rt.type({ + indexPattern: rt.string, + timestampField: rt.string, + bucketSpan: rt.number, +}); + +export type JobSourceConfiguration = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/log_analysis/log_analysis.ts b/x-pack/plugins/infra/common/log_analysis/log_analysis.ts new file mode 100644 index 0000000000000..4a6f20d549799 --- /dev/null +++ b/x-pack/plugins/infra/common/log_analysis/log_analysis.ts @@ -0,0 +1,61 @@ +/* + * 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 * as rt from 'io-ts'; + +export const jobTypeRT = rt.keyof({ + 'log-entry-rate': null, +}); + +export type JobType = rt.TypeOf; + +// combines and abstracts job and datafeed status +export type JobStatus = + | 'unknown' + | 'missing' + | 'initializing' + | 'stopped' + | 'started' + | 'finished' + | 'failed'; + +export type SetupStatus = + | 'initializing' // acquiring job statuses to determine setup status + | 'unknown' // job status could not be acquired (failed request etc) + | 'required' // jobs are missing + | 'requiredForReconfiguration' // the configurations don't match the source configurations + | 'requiredForUpdate' // the definitions don't match the module definitions + | 'pending' // In the process of setting up the module for the first time or retrying, waiting for response + | 'succeeded' // setup succeeded, notifying user + | 'failed' // setup failed, notifying user + | 'hiddenAfterSuccess' // hide the setup screen and we show the results for the first time + | 'skipped' // setup hidden because the module is in a correct state already + | 'skippedButReconfigurable' // setup hidden even though the job configurations are outdated + | 'skippedButUpdatable'; // setup hidden even though the job definitions are outdated + +/** + * Maps a job status to the possibility that results have already been produced + * before this state was reached. + */ +export const isJobStatusWithResults = (jobStatus: JobStatus) => + ['started', 'finished', 'stopped', 'failed'].includes(jobStatus); + +export const isHealthyJobStatus = (jobStatus: JobStatus) => + ['started', 'finished'].includes(jobStatus); + +/** + * Maps a setup status to the possibility that results have already been + * produced before this state was reached. + */ +export const isSetupStatusWithResults = (setupStatus: SetupStatus) => + ['skipped', 'hiddenAfterSuccess', 'skippedButReconfigurable', 'skippedButUpdatable'].includes( + setupStatus + ); + +const KIBANA_SAMPLE_DATA_INDICES = ['kibana_sample_data_logs*']; + +export const isExampleDataIndex = (indexName: string) => + KIBANA_SAMPLE_DATA_INDICES.includes(indexName); diff --git a/x-pack/plugins/infra/common/log_entry/index.ts b/x-pack/plugins/infra/common/log_entry/index.ts new file mode 100644 index 0000000000000..66cc5108b6692 --- /dev/null +++ b/x-pack/plugins/infra/common/log_entry/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './log_entry'; diff --git a/x-pack/plugins/infra/common/log_entry/log_entry.ts b/x-pack/plugins/infra/common/log_entry/log_entry.ts new file mode 100644 index 0000000000000..e02acebe27711 --- /dev/null +++ b/x-pack/plugins/infra/common/log_entry/log_entry.ts @@ -0,0 +1,44 @@ +/* + * 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 { TimeKey } from '../time'; +import { InfraLogEntry } from '../graphql/types'; + +export type LogEntry = InfraLogEntry; + +export interface LogEntryOrigin { + id: string; + index: string; + type: string; +} + +export type LogEntryTime = TimeKey; + +export interface LogEntryFieldsMapping { + message: string; + tiebreaker: string; + time: string; +} + +export function isEqual(time1: LogEntryTime, time2: LogEntryTime) { + return time1.time === time2.time && time1.tiebreaker === time2.tiebreaker; +} + +export function isLess(time1: LogEntryTime, time2: LogEntryTime) { + return ( + time1.time < time2.time || (time1.time === time2.time && time1.tiebreaker < time2.tiebreaker) + ); +} + +export function isLessOrEqual(time1: LogEntryTime, time2: LogEntryTime) { + return ( + time1.time < time2.time || (time1.time === time2.time && time1.tiebreaker <= time2.tiebreaker) + ); +} + +export function isBetween(min: LogEntryTime, max: LogEntryTime, operand: LogEntryTime) { + return isLessOrEqual(min, operand) && isLessOrEqual(operand, max); +} diff --git a/x-pack/plugins/infra/common/log_search_result/index.ts b/x-pack/plugins/infra/common/log_search_result/index.ts new file mode 100644 index 0000000000000..6795cc1543798 --- /dev/null +++ b/x-pack/plugins/infra/common/log_search_result/index.ts @@ -0,0 +1,12 @@ +/* + * 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. + */ + +export { + getSearchResultIndexBeforeTime, + getSearchResultIndexAfterTime, + getSearchResultKey, + SearchResult, +} from './log_search_result'; diff --git a/x-pack/plugins/infra/common/log_search_result/log_search_result.ts b/x-pack/plugins/infra/common/log_search_result/log_search_result.ts new file mode 100644 index 0000000000000..a56a9d8e3531c --- /dev/null +++ b/x-pack/plugins/infra/common/log_search_result/log_search_result.ts @@ -0,0 +1,30 @@ +/* + * 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 { bisector } from 'd3-array'; + +import { compareToTimeKey, TimeKey } from '../time'; + +export interface SearchResult { + gid: string; + fields: TimeKey; + matches: SearchResultFieldMatches; +} + +export interface SearchResultFieldMatches { + [field: string]: string[]; +} + +export const getSearchResultKey = (result: SearchResult) => + ({ + gid: result.gid, + tiebreaker: result.fields.tiebreaker, + time: result.fields.time, + } as TimeKey); + +const searchResultTimeBisector = bisector(compareToTimeKey(getSearchResultKey)); +export const getSearchResultIndexBeforeTime = searchResultTimeBisector.left; +export const getSearchResultIndexAfterTime = searchResultTimeBisector.right; diff --git a/x-pack/plugins/infra/common/log_search_summary/index.ts b/x-pack/plugins/infra/common/log_search_summary/index.ts new file mode 100644 index 0000000000000..4ba04cb3ea6a4 --- /dev/null +++ b/x-pack/plugins/infra/common/log_search_summary/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export { SearchSummaryBucket } from './log_search_summary'; diff --git a/x-pack/plugins/infra/common/log_search_summary/log_search_summary.ts b/x-pack/plugins/infra/common/log_search_summary/log_search_summary.ts new file mode 100644 index 0000000000000..72cf643311798 --- /dev/null +++ b/x-pack/plugins/infra/common/log_search_summary/log_search_summary.ts @@ -0,0 +1,14 @@ +/* + * 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 { SearchResult } from '../log_search_result'; + +export interface SearchSummaryBucket { + start: number; + end: number; + count: number; + representative: SearchResult; +} diff --git a/x-pack/plugins/infra/common/log_text_scale/index.ts b/x-pack/plugins/infra/common/log_text_scale/index.ts new file mode 100644 index 0000000000000..7fee2bbd398bd --- /dev/null +++ b/x-pack/plugins/infra/common/log_text_scale/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './log_text_scale'; diff --git a/x-pack/plugins/infra/common/log_text_scale/log_text_scale.ts b/x-pack/plugins/infra/common/log_text_scale/log_text_scale.ts new file mode 100644 index 0000000000000..6b8b26498ea45 --- /dev/null +++ b/x-pack/plugins/infra/common/log_text_scale/log_text_scale.ts @@ -0,0 +1,11 @@ +/* + * 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. + */ + +export type TextScale = 'small' | 'medium' | 'large'; + +export function isTextScale(maybeTextScale: string): maybeTextScale is TextScale { + return ['small', 'medium', 'large'].includes(maybeTextScale); +} diff --git a/x-pack/plugins/infra/common/runtime_types.ts b/x-pack/plugins/infra/common/runtime_types.ts new file mode 100644 index 0000000000000..297743f9b3456 --- /dev/null +++ b/x-pack/plugins/infra/common/runtime_types.ts @@ -0,0 +1,14 @@ +/* + * 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 { Errors } from 'io-ts'; +import { failure } from 'io-ts/lib/PathReporter'; + +export const createPlainError = (message: string) => new Error(message); + +export const throwErrors = (createError: (message: string) => Error) => (errors: Errors) => { + throw createError(failure(errors).join('\n')); +}; diff --git a/x-pack/plugins/infra/common/time/index.ts b/x-pack/plugins/infra/common/time/index.ts new file mode 100644 index 0000000000000..f49d46fa4920f --- /dev/null +++ b/x-pack/plugins/infra/common/time/index.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export * from './time_unit'; +export * from './time_scale'; +export * from './time_key'; diff --git a/x-pack/plugins/infra/common/time/time_key.ts b/x-pack/plugins/infra/common/time/time_key.ts new file mode 100644 index 0000000000000..e4f41615eb484 --- /dev/null +++ b/x-pack/plugins/infra/common/time/time_key.ts @@ -0,0 +1,96 @@ +/* + * 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 { ascending, bisector } from 'd3-array'; +import { pick } from 'lodash'; + +export interface TimeKey { + time: number; + tiebreaker: number; + gid?: string; + fromAutoReload?: boolean; +} + +export interface UniqueTimeKey extends TimeKey { + gid: string; +} + +export type Comparator = (firstValue: any, secondValue: any) => number; + +export const isTimeKey = (value: any): value is TimeKey => + value && + typeof value === 'object' && + typeof value.time === 'number' && + typeof value.tiebreaker === 'number'; + +export const pickTimeKey = (value: T): TimeKey => + pick(value, ['time', 'tiebreaker']); + +export function compareTimeKeys( + firstKey: TimeKey, + secondKey: TimeKey, + compareValues: Comparator = ascending +): number { + const timeComparison = compareValues(firstKey.time, secondKey.time); + + if (timeComparison === 0) { + const tiebreakerComparison = compareValues(firstKey.tiebreaker, secondKey.tiebreaker); + + if ( + tiebreakerComparison === 0 && + typeof firstKey.gid !== 'undefined' && + typeof secondKey.gid !== 'undefined' + ) { + return compareValues(firstKey.gid, secondKey.gid); + } + + return tiebreakerComparison; + } + + return timeComparison; +} + +export const compareToTimeKey = ( + keyAccessor: (value: Value) => TimeKey, + compareValues?: Comparator +) => (value: Value, key: TimeKey) => compareTimeKeys(keyAccessor(value), key, compareValues); + +export const getIndexAtTimeKey = ( + keyAccessor: (value: Value) => TimeKey, + compareValues?: Comparator +) => { + const comparator = compareToTimeKey(keyAccessor, compareValues); + const collectionBisector = bisector(comparator); + + return (collection: Value[], key: TimeKey): number | null => { + const index = collectionBisector.left(collection, key); + + if (index >= collection.length) { + return null; + } + + if (comparator(collection[index], key) !== 0) { + return null; + } + + return index; + }; +}; + +export const timeKeyIsBetween = (min: TimeKey, max: TimeKey, operand: TimeKey) => + compareTimeKeys(min, operand) <= 0 && compareTimeKeys(max, operand) >= 0; + +export const getPreviousTimeKey = (timeKey: TimeKey) => ({ + ...timeKey, + time: timeKey.time, + tiebreaker: timeKey.tiebreaker - 1, +}); + +export const getNextTimeKey = (timeKey: TimeKey) => ({ + ...timeKey, + time: timeKey.time, + tiebreaker: timeKey.tiebreaker + 1, +}); diff --git a/x-pack/plugins/infra/common/time/time_scale.ts b/x-pack/plugins/infra/common/time/time_scale.ts new file mode 100644 index 0000000000000..0381f294f81cb --- /dev/null +++ b/x-pack/plugins/infra/common/time/time_scale.ts @@ -0,0 +1,37 @@ +/* + * 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 { TimeUnit, timeUnitLabels } from './time_unit'; + +export interface TimeScale { + unit: TimeUnit; + value: number; +} + +export const getMillisOfScale = (scale: TimeScale) => scale.unit * scale.value; + +export const getLabelOfScale = (scale: TimeScale) => `${scale.value}${timeUnitLabels[scale.unit]}`; + +export const decomposeIntoUnits = (time: number, units: TimeUnit[]) => + units.reduce((result, unitMillis) => { + const offset = result.reduce( + (accumulatedOffset, timeScale) => accumulatedOffset + getMillisOfScale(timeScale), + 0 + ); + const value = Math.floor((time - offset) / unitMillis); + + if (value > 0) { + return [ + ...result, + { + unit: unitMillis, + value, + }, + ]; + } else { + return result; + } + }, []); diff --git a/x-pack/plugins/infra/common/time/time_unit.ts b/x-pack/plugins/infra/common/time/time_unit.ts new file mode 100644 index 0000000000000..4273a9fcf2ef3 --- /dev/null +++ b/x-pack/plugins/infra/common/time/time_unit.ts @@ -0,0 +1,41 @@ +/* + * 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. + */ + +export enum TimeUnit { + Millisecond = 1, + Second = Millisecond * 1000, + Minute = Second * 60, + Hour = Minute * 60, + Day = Hour * 24, + Month = Day * 30, + Year = Month * 12, +} + +export type ElasticsearchTimeUnit = 's' | 'm' | 'h' | 'd' | 'M' | 'y'; + +export const timeUnitLabels = { + [TimeUnit.Millisecond]: 'ms', + [TimeUnit.Second]: 's', + [TimeUnit.Minute]: 'm', + [TimeUnit.Hour]: 'h', + [TimeUnit.Day]: 'd', + [TimeUnit.Month]: 'M', + [TimeUnit.Year]: 'y', +}; + +export const elasticSearchTimeUnits: { + [key: string]: ElasticsearchTimeUnit; +} = { + [TimeUnit.Second]: 's', + [TimeUnit.Minute]: 'm', + [TimeUnit.Hour]: 'h', + [TimeUnit.Day]: 'd', + [TimeUnit.Month]: 'M', + [TimeUnit.Year]: 'y', +}; + +export const getElasticSearchTimeUnit = (scale: TimeUnit): ElasticsearchTimeUnit => + elasticSearchTimeUnits[scale]; diff --git a/x-pack/plugins/infra/common/typed_json.ts b/x-pack/plugins/infra/common/typed_json.ts new file mode 100644 index 0000000000000..98b5456fe44b8 --- /dev/null +++ b/x-pack/plugins/infra/common/typed_json.ts @@ -0,0 +1,14 @@ +/* + * 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. + */ + +export type JsonValue = null | boolean | number | string | JsonObject | JsonArray; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface JsonArray extends Array {} + +export interface JsonObject { + [key: string]: JsonValue; +} diff --git a/x-pack/plugins/infra/common/utility_types.ts b/x-pack/plugins/infra/common/utility_types.ts new file mode 100644 index 0000000000000..93fc9b729ca74 --- /dev/null +++ b/x-pack/plugins/infra/common/utility_types.ts @@ -0,0 +1,45 @@ +/* + * 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. + */ + +export type Pick2 = { + [P1 in K1]: { [P2 in K2]: T[K1][P2] }; +}; +export type Pick3 = { + [P1 in K1]: { [P2 in K2]: { [P3 in K3]: T[K1][K2][P3] } }; +}; + +export type MandatoryProperty = T & + { + [prop in Prop]-?: NonNullable; + }; + +/** + * Portions of below code are derived from https://github.com/tycho01/typical + * under the MIT License + * + * Copyright (c) 2017 Thomas Crockett + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +export type DeepPartial = T extends any[] + ? DeepPartialArray + : T extends object + ? DeepPartialObject + : T; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface DeepPartialArray extends Array> {} + +type DeepPartialObject = { [P in keyof T]+?: DeepPartial }; diff --git a/x-pack/plugins/infra/kibana.json b/x-pack/plugins/infra/kibana.json index ec5420a4d28d5..98385e7c50f4a 100644 --- a/x-pack/plugins/infra/kibana.json +++ b/x-pack/plugins/infra/kibana.json @@ -2,5 +2,7 @@ "id": "infra", "version": "8.0.0", "kibanaVersion": "kibana", - "server": true + "requiredPlugins": ["features", "apm", "usageCollection", "spaces", "metrics"], + "server": true, + "ui": false } diff --git a/x-pack/legacy/plugins/infra/server/features.ts b/x-pack/plugins/infra/server/features.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/features.ts rename to x-pack/plugins/infra/server/features.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/index.ts b/x-pack/plugins/infra/server/graphql/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/index.ts rename to x-pack/plugins/infra/server/graphql/index.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/log_entries/index.ts b/x-pack/plugins/infra/server/graphql/log_entries/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/log_entries/index.ts rename to x-pack/plugins/infra/server/graphql/log_entries/index.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/log_entries/resolvers.ts b/x-pack/plugins/infra/server/graphql/log_entries/resolvers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/log_entries/resolvers.ts rename to x-pack/plugins/infra/server/graphql/log_entries/resolvers.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/log_entries/schema.gql.ts b/x-pack/plugins/infra/server/graphql/log_entries/schema.gql.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/log_entries/schema.gql.ts rename to x-pack/plugins/infra/server/graphql/log_entries/schema.gql.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/source_status/index.ts b/x-pack/plugins/infra/server/graphql/source_status/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/source_status/index.ts rename to x-pack/plugins/infra/server/graphql/source_status/index.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/source_status/resolvers.ts b/x-pack/plugins/infra/server/graphql/source_status/resolvers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/source_status/resolvers.ts rename to x-pack/plugins/infra/server/graphql/source_status/resolvers.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/source_status/schema.gql.ts b/x-pack/plugins/infra/server/graphql/source_status/schema.gql.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/source_status/schema.gql.ts rename to x-pack/plugins/infra/server/graphql/source_status/schema.gql.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/sources/index.ts b/x-pack/plugins/infra/server/graphql/sources/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/sources/index.ts rename to x-pack/plugins/infra/server/graphql/sources/index.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/sources/resolvers.ts b/x-pack/plugins/infra/server/graphql/sources/resolvers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/sources/resolvers.ts rename to x-pack/plugins/infra/server/graphql/sources/resolvers.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/sources/schema.gql.ts b/x-pack/plugins/infra/server/graphql/sources/schema.gql.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/sources/schema.gql.ts rename to x-pack/plugins/infra/server/graphql/sources/schema.gql.ts diff --git a/x-pack/legacy/plugins/infra/server/graphql/types.ts b/x-pack/plugins/infra/server/graphql/types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/graphql/types.ts rename to x-pack/plugins/infra/server/graphql/types.ts diff --git a/x-pack/plugins/infra/server/index.ts b/x-pack/plugins/infra/server/index.ts index b12f92c8c5a9d..1853509dfa8e7 100644 --- a/x-pack/plugins/infra/server/index.ts +++ b/x-pack/plugins/infra/server/index.ts @@ -4,21 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { schema, TypeOf } from '@kbn/config-schema'; import { PluginInitializerContext } from 'src/core/server'; -import { InfraPlugin } from './plugin'; +import { config, InfraConfig, InfraServerPlugin } from './plugin'; -export const config = { - schema: schema.object({ - enabled: schema.maybe(schema.boolean()), - query: schema.object({ - partitionSize: schema.maybe(schema.number()), - partitionFactor: schema.maybe(schema.number()), - }), - }), -}; +export { config, InfraConfig }; -export const plugin = (initContext: PluginInitializerContext) => new InfraPlugin(initContext); - -export type InfraConfig = TypeOf; -export { InfraSetup } from './plugin'; +export function plugin(context: PluginInitializerContext) { + return new InfraServerPlugin(context); +} diff --git a/x-pack/legacy/plugins/infra/server/infra_server.ts b/x-pack/plugins/infra/server/infra_server.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/infra_server.ts rename to x-pack/plugins/infra/server/infra_server.ts diff --git a/x-pack/legacy/plugins/infra/server/kibana.index.ts b/x-pack/plugins/infra/server/kibana.index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/kibana.index.ts rename to x-pack/plugins/infra/server/kibana.index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/fields/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/fields/adapter_types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/fields/adapter_types.ts rename to x-pack/plugins/infra/server/lib/adapters/fields/adapter_types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/fields/framework_fields_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/fields/framework_fields_adapter.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/fields/framework_fields_adapter.ts rename to x-pack/plugins/infra/server/lib/adapters/fields/framework_fields_adapter.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/fields/index.ts b/x-pack/plugins/infra/server/lib/adapters/fields/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/fields/index.ts rename to x-pack/plugins/infra/server/lib/adapters/fields/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts rename to x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/index.ts b/x-pack/plugins/infra/server/lib/adapters/framework/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/framework/index.ts rename to x-pack/plugins/infra/server/lib/adapters/framework/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts similarity index 92% rename from x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts rename to x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index 4409667d8390a..f91533be305f9 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -6,7 +6,6 @@ /* eslint-disable @typescript-eslint/array-type */ -import { GenericParams } from 'elasticsearch'; import { GraphQLSchema } from 'graphql'; import { Legacy } from 'kibana'; import { runHttpQuery } from 'apollo-server-core'; @@ -30,9 +29,11 @@ import { RequestHandlerContext, KibanaResponseFactory, RouteMethod, -} from '../../../../../../../../src/core/server'; -import { RequestHandler } from '../../../../../../../../src/core/server'; -import { InfraConfig } from '../../../../../../../plugins/infra/server'; + APICaller, +} from '../../../../../../../src/core/server'; +import { RequestHandler } from '../../../../../../../src/core/server'; +import { InfraConfig } from '../../../plugin'; +import { IndexPatternsFetcher } from '../../../../../../../src/plugins/data/server'; export class KibanaFramework { public router: IRouter; @@ -214,14 +215,10 @@ export class KibanaFramework { public getIndexPatternsService( requestContext: RequestHandlerContext ): Legacy.IndexPatternsService { - return this.plugins.indexPatterns.indexPatternsServiceFactory({ - callCluster: async (method: string, args: [GenericParams], ...rest: any[]) => { - const fieldCaps = await this.callWithRequest(requestContext, method, { - ...args, - allowNoIndices: true, - } as GenericParams); - return fieldCaps; - }, + return new IndexPatternsFetcher((...rest: Parameters) => { + rest[1] = rest[1] || {}; + rest[1].allowNoIndices = true; + return requestContext.core.elasticsearch.adminClient.callAsCurrentUser(...rest); }); } diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/log_entries/adapter_types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/adapter_types.ts rename to x-pack/plugins/infra/server/lib/adapters/log_entries/adapter_types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/index.ts b/x-pack/plugins/infra/server/lib/adapters/log_entries/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/index.ts rename to x-pack/plugins/infra/server/lib/adapters/log_entries/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts similarity index 97% rename from x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts rename to x-pack/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts index ec45171baa7b0..e7b1692547ead 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts @@ -8,10 +8,7 @@ import { timeMilliseconds } from 'd3-time'; import * as runtimeTypes from 'io-ts'; -import first from 'lodash/fp/first'; -import get from 'lodash/fp/get'; -import has from 'lodash/fp/has'; -import zip from 'lodash/fp/zip'; +import { first, get, has, zip } from 'lodash'; import { pipe } from 'fp-ts/lib/pipeable'; import { map, fold } from 'fp-ts/lib/Either'; import { identity, constant } from 'fp-ts/lib/function'; @@ -325,13 +322,13 @@ const convertHitToLogEntryDocument = (fields: string[]) => ( gid: hit._id, fields: fields.reduce( (flattenedFields, fieldName) => - has(fieldName, hit._source) + has(hit._source, fieldName) ? { ...flattenedFields, - [fieldName]: get(fieldName, hit._source), + [fieldName]: get(hit._source, fieldName), } : flattenedFields, - {} as { [fieldName: string]: string | number | boolean | null } + {} as { [fieldName: string]: string | number | object | boolean | null } ), highlights: hit.highlight || {}, key: { diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/adapter_types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/adapter_types.ts rename to x-pack/plugins/infra/server/lib/adapters/metrics/adapter_types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/index.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/index.ts rename to x-pack/plugins/infra/server/lib/adapters/metrics/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts rename to x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/lib/check_valid_node.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/lib/check_valid_node.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/lib/check_valid_node.ts rename to x-pack/plugins/infra/server/lib/adapters/metrics/lib/check_valid_node.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/lib/errors.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/lib/errors.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/lib/errors.ts rename to x-pack/plugins/infra/server/lib/adapters/metrics/lib/errors.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/source_status/elasticsearch_source_status_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/source_status/elasticsearch_source_status_adapter.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/source_status/elasticsearch_source_status_adapter.ts rename to x-pack/plugins/infra/server/lib/adapters/source_status/elasticsearch_source_status_adapter.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/source_status/index.ts b/x-pack/plugins/infra/server/lib/adapters/source_status/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/adapters/source_status/index.ts rename to x-pack/plugins/infra/server/lib/adapters/source_status/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/compose/kibana.ts b/x-pack/plugins/infra/server/lib/compose/kibana.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/compose/kibana.ts rename to x-pack/plugins/infra/server/lib/compose/kibana.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/constants.ts b/x-pack/plugins/infra/server/lib/constants.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/constants.ts rename to x-pack/plugins/infra/server/lib/constants.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/fields_domain.ts b/x-pack/plugins/infra/server/lib/domains/fields_domain.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/fields_domain.ts rename to x-pack/plugins/infra/server/lib/domains/fields_domain.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_apache2.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_auditd.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_haproxy.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_icinga.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_iis.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_kafka.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_kafka.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_kafka.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_kafka.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_logstash.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mongodb.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_mysql.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_nginx.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_osquery.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_redis.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_redis.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_redis.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_redis.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_system.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_system.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_system.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_system.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/filebeat_traefik.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic_webserver.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic_webserver.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic_webserver.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/generic_webserver.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/helpers.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/helpers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/helpers.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/helpers.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/index.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/index.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/builtin_rules/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.test.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.test.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/convert_document_source_to_log_item_fields.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/index.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/index.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/message.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/message.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/message.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/message.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/rule_types.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/rule_types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/log_entries_domain/rule_types.ts rename to x-pack/plugins/infra/server/lib/domains/log_entries_domain/rule_types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/domains/metrics_domain.ts b/x-pack/plugins/infra/server/lib/domains/metrics_domain.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/domains/metrics_domain.ts rename to x-pack/plugins/infra/server/lib/domains/metrics_domain.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/infra_types.ts b/x-pack/plugins/infra/server/lib/infra_types.ts similarity index 91% rename from x-pack/legacy/plugins/infra/server/lib/infra_types.ts rename to x-pack/plugins/infra/server/lib/infra_types.ts index 46d32885600df..fc92dacde4f7b 100644 --- a/x-pack/legacy/plugins/infra/server/lib/infra_types.ts +++ b/x-pack/plugins/infra/server/lib/infra_types.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraSourceConfiguration } from '../../public/graphql/types'; +import { InfraSourceConfiguration } from '../../common/graphql/types'; import { InfraFieldsDomain } from './domains/fields_domain'; import { InfraLogEntriesDomain } from './domains/log_entries_domain'; import { InfraMetricsDomain } from './domains/metrics_domain'; @@ -12,7 +12,7 @@ import { InfraLogAnalysis } from './log_analysis/log_analysis'; import { InfraSnapshot } from './snapshot'; import { InfraSources } from './sources'; import { InfraSourceStatus } from './source_status'; -import { InfraConfig } from '../../../../../plugins/infra/server'; +import { InfraConfig } from '../plugin'; import { KibanaFramework } from './adapters/framework/kibana_framework_adapter'; // NP_TODO: We shouldn't need this context anymore but I am diff --git a/x-pack/legacy/plugins/infra/server/lib/log_analysis/errors.ts b/x-pack/plugins/infra/server/lib/log_analysis/errors.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/log_analysis/errors.ts rename to x-pack/plugins/infra/server/lib/log_analysis/errors.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/log_analysis/index.ts b/x-pack/plugins/infra/server/lib/log_analysis/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/log_analysis/index.ts rename to x-pack/plugins/infra/server/lib/log_analysis/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/log_analysis/log_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_analysis.ts similarity index 99% rename from x-pack/legacy/plugins/infra/server/lib/log_analysis/log_analysis.ts rename to x-pack/plugins/infra/server/lib/log_analysis/log_analysis.ts index fac49a7980f26..f46713bb300a8 100644 --- a/x-pack/legacy/plugins/infra/server/lib/log_analysis/log_analysis.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_analysis.ts @@ -17,7 +17,7 @@ import { LogRateModelPlotBucket, CompositeTimestampPartitionKey, } from './queries'; -import { RequestHandlerContext, KibanaRequest } from '../../../../../../../src/core/server'; +import { RequestHandlerContext, KibanaRequest } from '../../../../../../src/core/server'; const COMPOSITE_AGGREGATION_BATCH_SIZE = 1000; diff --git a/x-pack/legacy/plugins/infra/server/routes/log_analysis/results/index.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_analysis/results/index.ts rename to x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/log_analysis/queries/log_entry_rate.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_rate.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/log_analysis/queries/log_entry_rate.ts rename to x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_rate.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/constants.ts b/x-pack/plugins/infra/server/lib/snapshot/constants.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/constants.ts rename to x-pack/plugins/infra/server/lib/snapshot/constants.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/create_timerange_with_interval.ts b/x-pack/plugins/infra/server/lib/snapshot/create_timerange_with_interval.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/create_timerange_with_interval.ts rename to x-pack/plugins/infra/server/lib/snapshot/create_timerange_with_interval.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/index.ts b/x-pack/plugins/infra/server/lib/snapshot/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/index.ts rename to x-pack/plugins/infra/server/lib/snapshot/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts b/x-pack/plugins/infra/server/lib/snapshot/query_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts rename to x-pack/plugins/infra/server/lib/snapshot/query_helpers.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/response_helpers.test.ts b/x-pack/plugins/infra/server/lib/snapshot/response_helpers.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/response_helpers.test.ts rename to x-pack/plugins/infra/server/lib/snapshot/response_helpers.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/response_helpers.ts b/x-pack/plugins/infra/server/lib/snapshot/response_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/response_helpers.ts rename to x-pack/plugins/infra/server/lib/snapshot/response_helpers.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/snapshot.ts b/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/snapshot.ts rename to x-pack/plugins/infra/server/lib/snapshot/snapshot.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/types.ts b/x-pack/plugins/infra/server/lib/snapshot/types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/types.ts rename to x-pack/plugins/infra/server/lib/snapshot/types.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/source_status.ts b/x-pack/plugins/infra/server/lib/source_status.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/source_status.ts rename to x-pack/plugins/infra/server/lib/source_status.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/defaults.ts b/x-pack/plugins/infra/server/lib/sources/defaults.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/defaults.ts rename to x-pack/plugins/infra/server/lib/sources/defaults.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/errors.ts b/x-pack/plugins/infra/server/lib/sources/errors.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/errors.ts rename to x-pack/plugins/infra/server/lib/sources/errors.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/index.ts b/x-pack/plugins/infra/server/lib/sources/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/index.ts rename to x-pack/plugins/infra/server/lib/sources/index.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/saved_object_mappings.ts b/x-pack/plugins/infra/server/lib/sources/saved_object_mappings.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/saved_object_mappings.ts rename to x-pack/plugins/infra/server/lib/sources/saved_object_mappings.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/sources.test.ts b/x-pack/plugins/infra/server/lib/sources/sources.test.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/sources.test.ts rename to x-pack/plugins/infra/server/lib/sources/sources.test.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/sources.ts b/x-pack/plugins/infra/server/lib/sources/sources.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/sources.ts rename to x-pack/plugins/infra/server/lib/sources/sources.ts diff --git a/x-pack/legacy/plugins/infra/server/lib/sources/types.ts b/x-pack/plugins/infra/server/lib/sources/types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/lib/sources/types.ts rename to x-pack/plugins/infra/server/lib/sources/types.ts diff --git a/x-pack/legacy/plugins/infra/server/new_platform_plugin.ts b/x-pack/plugins/infra/server/new_platform_plugin.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/new_platform_plugin.ts rename to x-pack/plugins/infra/server/new_platform_plugin.ts diff --git a/x-pack/plugins/infra/server/plugin.ts b/x-pack/plugins/infra/server/plugin.ts index 0c763313fb973..b06ff20031ad7 100644 --- a/x-pack/plugins/infra/server/plugin.ts +++ b/x-pack/plugins/infra/server/plugin.ts @@ -4,30 +4,134 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, PluginInitializerContext } from 'src/core/server'; +import { CoreSetup, PluginInitializerContext } from 'src/core/server'; +import { Server } from 'hapi'; +import { schema, TypeOf } from '@kbn/config-schema'; +import { initInfraServer } from './infra_server'; +import { InfraBackendLibs, InfraDomainLibs } from './lib/infra_types'; +import { FrameworkFieldsAdapter } from './lib/adapters/fields/framework_fields_adapter'; +import { KibanaFramework } from './lib/adapters/framework/kibana_framework_adapter'; +import { InfraKibanaLogEntriesAdapter } from './lib/adapters/log_entries/kibana_log_entries_adapter'; +import { KibanaMetricsAdapter } from './lib/adapters/metrics/kibana_metrics_adapter'; +import { InfraElasticsearchSourceStatusAdapter } from './lib/adapters/source_status'; +import { InfraFieldsDomain } from './lib/domains/fields_domain'; +import { InfraLogEntriesDomain } from './lib/domains/log_entries_domain'; +import { InfraMetricsDomain } from './lib/domains/metrics_domain'; +import { InfraLogAnalysis } from './lib/log_analysis'; +import { InfraSnapshot } from './lib/snapshot'; +import { InfraSourceStatus } from './lib/source_status'; +import { InfraSources } from './lib/sources'; +import { InfraServerPluginDeps } from './lib/adapters/framework'; +import { METRICS_FEATURE, LOGS_FEATURE } from './features'; +import { UsageCollector } from './usage/usage_collector'; +import { InfraStaticSourceConfiguration } from './lib/sources/types'; -export class InfraPlugin implements Plugin { - private readonly initContext: PluginInitializerContext; +export const config = { + schema: schema.object({ + enabled: schema.maybe(schema.boolean()), + query: schema.object({ + partitionSize: schema.maybe(schema.number()), + partitionFactor: schema.maybe(schema.number()), + }), + }), +}; - constructor(initContext: PluginInitializerContext) { - this.initContext = initContext; +export type InfraConfig = TypeOf; + +export interface KbnServer extends Server { + usage: any; +} + +export interface InfraPluginSetup { + defineInternalSourceConfiguration: ( + sourceId: string, + sourceProperties: InfraStaticSourceConfiguration + ) => void; +} + +const DEFAULT_CONFIG: InfraConfig = { + enabled: true, + query: { + partitionSize: 75, + partitionFactor: 1.2, + }, +}; + +export class InfraServerPlugin { + public config: InfraConfig = DEFAULT_CONFIG; + public libs: InfraBackendLibs | undefined; + + constructor(context: PluginInitializerContext) { + const config$ = context.config.create(); + config$.subscribe(configValue => { + this.config = { + ...DEFAULT_CONFIG, + enabled: configValue.enabled, + query: { + ...DEFAULT_CONFIG.query, + ...configValue.query, + }, + }; + }); } - public setup() { + getLibs() { + if (!this.libs) { + throw new Error('libs not set up yet'); + } + return this.libs; + } + + setup(core: CoreSetup, plugins: InfraServerPluginDeps) { + const framework = new KibanaFramework(core, this.config, plugins); + const sources = new InfraSources({ + config: this.config, + }); + const sourceStatus = new InfraSourceStatus( + new InfraElasticsearchSourceStatusAdapter(framework), + { + sources, + } + ); + const snapshot = new InfraSnapshot({ sources, framework }); + const logAnalysis = new InfraLogAnalysis({ framework }); + + // TODO: separate these out individually and do away with "domains" as a temporary group + const domainLibs: InfraDomainLibs = { + fields: new InfraFieldsDomain(new FrameworkFieldsAdapter(framework), { + sources, + }), + logEntries: new InfraLogEntriesDomain(new InfraKibanaLogEntriesAdapter(framework), { + sources, + }), + metrics: new InfraMetricsDomain(new KibanaMetricsAdapter(framework)), + }; + + this.libs = { + configuration: this.config, + framework, + logAnalysis, + snapshot, + sources, + sourceStatus, + ...domainLibs, + }; + + plugins.features.registerFeature(METRICS_FEATURE); + plugins.features.registerFeature(LOGS_FEATURE); + + initInfraServer(this.libs); + + // Telemetry + UsageCollector.registerUsageCollector(plugins.usageCollection); + return { - __legacy: { - config: this.initContext.config, + defineInternalSourceConfiguration(sourceId, sourceProperties) { + sources.defineInternalSourceConfiguration(sourceId, sourceProperties); }, - }; + } as InfraPluginSetup; } - public start() {} - public stop() {} -} - -export interface InfraSetup { - /** @deprecated */ - __legacy: { - config: PluginInitializerContext['config']; - }; + start() {} + stop() {} } diff --git a/x-pack/legacy/plugins/infra/server/routes/inventory_metadata/index.ts b/x-pack/plugins/infra/server/routes/inventory_metadata/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/inventory_metadata/index.ts rename to x-pack/plugins/infra/server/routes/inventory_metadata/index.ts diff --git a/x-pack/plugins/infra/server/routes/inventory_metadata/lib/get_cloud_metadata.ts b/x-pack/plugins/infra/server/routes/inventory_metadata/lib/get_cloud_metadata.ts new file mode 100644 index 0000000000000..dcac23d1a3d9d --- /dev/null +++ b/x-pack/plugins/infra/server/routes/inventory_metadata/lib/get_cloud_metadata.ts @@ -0,0 +1,108 @@ +/* + * 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 { RequestHandlerContext } from 'kibana/server'; +import { InventoryCloudAccount } from '../../../../common/http_api/inventory_meta_api'; +import { + InfraMetadataAggregationResponse, + InfraMetadataAggregationBucket, +} from '../../../lib/adapters/framework'; +import { InfraSourceConfiguration } from '../../../lib/sources'; +import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framework_adapter'; +import { InventoryItemType } from '../../../../common/inventory_models/types'; +import { findInventoryModel } from '../../../../common/inventory_models'; + +export interface CloudMetaData { + accounts: InventoryCloudAccount[]; + projects: string[]; + regions: string[]; +} + +export const getCloudMetadata = async ( + framework: KibanaFramework, + req: RequestHandlerContext, + sourceConfiguration: InfraSourceConfiguration, + nodeType: InventoryItemType +): Promise => { + const model = findInventoryModel(nodeType); + + const metricQuery = { + allowNoIndices: true, + ignoreUnavailable: true, + index: sourceConfiguration.metricAlias, + body: { + query: { + bool: { + must: [{ match: { 'event.module': model.requiredModule } }], + }, + }, + size: 0, + aggs: { + accounts: { + terms: { + field: 'cloud.account.id', + size: 1000, + }, + aggs: { + accountNames: { + terms: { + field: 'cloud.account.name', + size: 1000, + }, + }, + }, + }, + regions: { + terms: { + field: 'cloud.region', + size: 1000, + }, + }, + }, + }, + }; + + const response = await framework.callWithRequest< + {}, + { + accounts?: { + buckets: Array< + InfraMetadataAggregationBucket & { accountNames: InfraMetadataAggregationResponse } + >; + }; + projects?: InfraMetadataAggregationResponse; + regions?: InfraMetadataAggregationResponse; + } + >(req, 'search', metricQuery); + + const projectBuckets = + response.aggregations && response.aggregations.projects + ? response.aggregations.projects.buckets + : []; + + const regionBuckets = + response.aggregations && response.aggregations.regions + ? response.aggregations.regions.buckets + : []; + + const accounts: InventoryCloudAccount[] = []; + if (response.aggregations && response.aggregations.accounts) { + response.aggregations.accounts.buckets.forEach(b => { + if (b.accountNames.buckets.length) { + accounts.push({ + value: b.key, + // There should only be one account name for each account id. + name: b.accountNames.buckets[0].key, + }); + } + }); + } + return { + accounts, + projects: projectBuckets.map(b => b.key), + regions: regionBuckets.map(b => b.key), + }; +}; diff --git a/x-pack/legacy/plugins/infra/server/routes/ip_to_hostname.ts b/x-pack/plugins/infra/server/routes/ip_to_hostname.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/ip_to_hostname.ts rename to x-pack/plugins/infra/server/routes/ip_to_hostname.ts diff --git a/x-pack/plugins/infra/server/routes/log_analysis/index.ts b/x-pack/plugins/infra/server/routes/log_analysis/index.ts new file mode 100644 index 0000000000000..378e32cb3582c --- /dev/null +++ b/x-pack/plugins/infra/server/routes/log_analysis/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './results'; +export * from './validation'; diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts new file mode 100644 index 0000000000000..1749421277719 --- /dev/null +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './log_entry_rate'; diff --git a/x-pack/legacy/plugins/infra/server/routes/log_analysis/results/log_entry_rate.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_rate.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_analysis/results/log_entry_rate.ts rename to x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_rate.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/log_analysis/validation/index.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_analysis/validation/index.ts rename to x-pack/plugins/infra/server/routes/log_analysis/validation/index.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/log_analysis/validation/indices.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_analysis/validation/indices.ts rename to x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts diff --git a/x-pack/plugins/infra/server/routes/log_entries/index.ts b/x-pack/plugins/infra/server/routes/log_entries/index.ts new file mode 100644 index 0000000000000..8fed914c3dc8c --- /dev/null +++ b/x-pack/plugins/infra/server/routes/log_entries/index.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export * from './item'; +export * from './summary'; +export * from './summary_highlights'; diff --git a/x-pack/plugins/infra/server/routes/log_entries/item.ts b/x-pack/plugins/infra/server/routes/log_entries/item.ts new file mode 100644 index 0000000000000..22663cb2001f0 --- /dev/null +++ b/x-pack/plugins/infra/server/routes/log_entries/item.ts @@ -0,0 +1,55 @@ +/* + * 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 Boom from 'boom'; + +import { pipe } from 'fp-ts/lib/pipeable'; +import { fold } from 'fp-ts/lib/Either'; +import { identity } from 'fp-ts/lib/function'; +import { schema } from '@kbn/config-schema'; + +import { throwErrors } from '../../../common/runtime_types'; + +import { InfraBackendLibs } from '../../lib/infra_types'; +import { + LOG_ENTRIES_ITEM_PATH, + logEntriesItemRequestRT, + logEntriesItemResponseRT, +} from '../../../common/http_api'; + +const escapeHatch = schema.object({}, { allowUnknowns: true }); + +export const initLogEntriesItemRoute = ({ framework, sources, logEntries }: InfraBackendLibs) => { + framework.registerRoute( + { + method: 'post', + path: LOG_ENTRIES_ITEM_PATH, + validate: { body: escapeHatch }, + }, + async (requestContext, request, response) => { + try { + const payload = pipe( + logEntriesItemRequestRT.decode(request.body), + fold(throwErrors(Boom.badRequest), identity) + ); + + const { id, sourceId } = payload; + const sourceConfiguration = (await sources.getSourceConfiguration(requestContext, sourceId)) + .configuration; + + const logEntry = await logEntries.getLogItem(requestContext, id, sourceConfiguration); + + return response.ok({ + body: logEntriesItemResponseRT.encode({ + data: logEntry, + }), + }); + } catch (error) { + return response.internalError({ body: error.message }); + } + } + ); +}; diff --git a/x-pack/legacy/plugins/infra/server/routes/log_entries/summary.ts b/x-pack/plugins/infra/server/routes/log_entries/summary.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_entries/summary.ts rename to x-pack/plugins/infra/server/routes/log_entries/summary.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/log_entries/summary_highlights.ts b/x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/log_entries/summary_highlights.ts rename to x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/index.ts b/x-pack/plugins/infra/server/routes/metadata/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/index.ts rename to x-pack/plugins/infra/server/routes/metadata/index.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_cloud_metric_metadata.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_cloud_metric_metadata.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_cloud_metric_metadata.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/get_cloud_metric_metadata.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_node_info.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_node_info.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_pod_node_name.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_pod_node_name.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/get_pod_node_name.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/get_pod_node_name.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/has_apm_data.ts b/x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/has_apm_data.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metadata/lib/pick_feature_name.ts b/x-pack/plugins/infra/server/routes/metadata/lib/pick_feature_name.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metadata/lib/pick_feature_name.ts rename to x-pack/plugins/infra/server/routes/metadata/lib/pick_feature_name.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/index.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metrics_explorer/index.ts rename to x-pack/plugins/infra/server/routes/metrics_explorer/index.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts rename to x-pack/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/get_groupings.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_groupings.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/get_groupings.ts rename to x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_groupings.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/populate_series_with_tsvb_data.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/populate_series_with_tsvb_data.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/populate_series_with_tsvb_data.ts rename to x-pack/plugins/infra/server/routes/metrics_explorer/lib/populate_series_with_tsvb_data.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/types.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts rename to x-pack/plugins/infra/server/routes/metrics_explorer/types.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/node_details/index.ts b/x-pack/plugins/infra/server/routes/node_details/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/node_details/index.ts rename to x-pack/plugins/infra/server/routes/node_details/index.ts diff --git a/x-pack/legacy/plugins/infra/server/routes/snapshot/index.ts b/x-pack/plugins/infra/server/routes/snapshot/index.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/routes/snapshot/index.ts rename to x-pack/plugins/infra/server/routes/snapshot/index.ts diff --git a/x-pack/legacy/plugins/infra/server/usage/usage_collector.ts b/x-pack/plugins/infra/server/usage/usage_collector.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/usage/usage_collector.ts rename to x-pack/plugins/infra/server/usage/usage_collector.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/README.md b/x-pack/plugins/infra/server/utils/README.md similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/README.md rename to x-pack/plugins/infra/server/utils/README.md diff --git a/x-pack/legacy/plugins/infra/server/utils/calculate_metric_interval.ts b/x-pack/plugins/infra/server/utils/calculate_metric_interval.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/calculate_metric_interval.ts rename to x-pack/plugins/infra/server/utils/calculate_metric_interval.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/create_afterkey_handler.ts b/x-pack/plugins/infra/server/utils/create_afterkey_handler.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/create_afterkey_handler.ts rename to x-pack/plugins/infra/server/utils/create_afterkey_handler.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/get_all_composite_data.ts b/x-pack/plugins/infra/server/utils/get_all_composite_data.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/get_all_composite_data.ts rename to x-pack/plugins/infra/server/utils/get_all_composite_data.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/get_interval_in_seconds.ts b/x-pack/plugins/infra/server/utils/get_interval_in_seconds.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/get_interval_in_seconds.ts rename to x-pack/plugins/infra/server/utils/get_interval_in_seconds.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/serialized_query.ts b/x-pack/plugins/infra/server/utils/serialized_query.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/serialized_query.ts rename to x-pack/plugins/infra/server/utils/serialized_query.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/typed_elasticsearch_mappings.ts b/x-pack/plugins/infra/server/utils/typed_elasticsearch_mappings.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/typed_elasticsearch_mappings.ts rename to x-pack/plugins/infra/server/utils/typed_elasticsearch_mappings.ts diff --git a/x-pack/legacy/plugins/infra/server/utils/typed_resolvers.ts b/x-pack/plugins/infra/server/utils/typed_resolvers.ts similarity index 100% rename from x-pack/legacy/plugins/infra/server/utils/typed_resolvers.ts rename to x-pack/plugins/infra/server/utils/typed_resolvers.ts