From 54ec71adc5ee7070e927d351b119efca721385e2 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 20 Oct 2021 13:02:41 -0500 Subject: [PATCH 01/21] [Logs UI][Metrics UI] Remove deprecated config fields from APIs --- x-pack/plugins/infra/common/constants.ts | 7 +++++- .../log_analysis/validation/datasets.ts | 1 - .../infra/common/http_api/metrics_api.ts | 1 - .../infra/common/http_api/metrics_explorer.ts | 1 - .../metrics/tsvb/container_cpu_kernel.ts | 3 ++- .../metrics/tsvb/container_cpu_usage.ts | 3 ++- .../metrics/tsvb/container_disk_io_bytes.ts | 3 ++- .../metrics/tsvb/container_diskio_ops.ts | 3 ++- .../metrics/tsvb/container_memory.ts | 3 ++- .../metrics/tsvb/container_network_traffic.ts | 3 ++- .../metrics/tsvb/container_overview.ts | 3 ++- .../inventory_models/create_tsvb_model.ts | 5 ++-- .../host/metrics/tsvb/host_cpu_usage.ts | 3 ++- .../host/metrics/tsvb/host_docker_info.ts | 3 ++- .../host/metrics/tsvb/host_docker_overview.ts | 3 ++- .../metrics/tsvb/host_docker_top_5_by_cpu.ts | 3 ++- .../tsvb/host_docker_top_5_by_memory.ts | 3 ++- .../host/metrics/tsvb/host_filesystem.ts | 3 ++- .../host/metrics/tsvb/host_k8s_cpu_cap.ts | 3 ++- .../host/metrics/tsvb/host_k8s_disk_cap.ts | 3 ++- .../host/metrics/tsvb/host_k8s_memory_cap.ts | 3 ++- .../host/metrics/tsvb/host_k8s_overview.ts | 3 ++- .../host/metrics/tsvb/host_k8s_pod_cap.ts | 3 ++- .../host/metrics/tsvb/host_load.ts | 3 ++- .../host/metrics/tsvb/host_memory_usage.ts | 3 ++- .../host/metrics/tsvb/host_network_traffic.ts | 3 ++- .../host/metrics/tsvb/host_system_overview.ts | 3 ++- .../infra/common/inventory_models/index.ts | 23 +++++++------------ .../pod/metrics/tsvb/pod_cpu_usage.ts | 3 ++- .../pod/metrics/tsvb/pod_log_usage.ts | 3 ++- .../pod/metrics/tsvb/pod_memory_usage.ts | 3 ++- .../pod/metrics/tsvb/pod_network_traffic.ts | 3 ++- .../pod/metrics/tsvb/pod_overview.ts | 3 ++- .../metrics/tsvb/aws_cpu_utilization.ts | 3 ++- .../shared/metrics/tsvb/aws_diskio_bytes.ts | 3 ++- .../shared/metrics/tsvb/aws_diskio_ops.ts | 3 ++- .../shared/metrics/tsvb/aws_network_bytes.ts | 3 ++- .../metrics/tsvb/aws_network_packets.ts | 3 ++- .../shared/metrics/tsvb/aws_overview.ts | 3 ++- .../metrics/tsvb/nginx_active_connections.ts | 3 ++- .../shared/metrics/tsvb/nginx_hits.ts | 3 ++- .../shared/metrics/tsvb/nginx_request_rate.ts | 3 ++- .../tsvb/nginx_requests_per_connection.ts | 3 ++- .../infra/common/inventory_models/types.ts | 1 - .../common/log_analysis/job_parameters.ts | 1 - .../log_sources/log_source_configuration.ts | 5 ---- .../resolved_log_source_configuration.ts | 6 ----- .../infra/common/metrics_sources/index.ts | 5 ---- .../source_configuration.ts | 10 -------- .../components/expression_chart.test.tsx | 7 ------ .../log_analysis/api/validate_datasets.ts | 4 +--- .../logs/log_analysis/log_analysis_module.tsx | 5 ++-- .../log_analysis_module_configuration.ts | 1 - .../log_analysis/log_analysis_module_types.ts | 3 --- .../log_analysis/log_analysis_setup_state.ts | 6 ++--- .../log_entry_categories/module_descriptor.ts | 16 +++++-------- .../use_log_entry_categories_module.tsx | 5 +--- .../log_entry_rate/module_descriptor.ts | 16 +++++-------- .../use_log_entry_rate_module.tsx | 5 +--- .../public/containers/ml/infra_ml_module.tsx | 5 ++-- .../ml/infra_ml_module_configuration.ts | 3 +-- .../containers/ml/infra_ml_module_types.ts | 3 --- .../ml/modules/metrics_hosts/module.tsx | 5 +--- .../metrics_hosts/module_descriptor.ts | 7 +++--- .../ml/modules/metrics_k8s/module.tsx | 5 +--- .../modules/metrics_k8s/module_descriptor.ts | 7 +++--- x-pack/plugins/infra/public/lib/lib.ts | 2 -- .../log_entry_categories/page_providers.tsx | 1 - .../logs/log_entry_rate/page_providers.tsx | 2 -- .../inventory_view/components/layout.tsx | 3 --- .../anomaly_detection_flyout.tsx | 2 -- .../node_details/tabs/metrics/metrics.tsx | 4 +--- .../node_details/tabs/processes/index.tsx | 6 ++--- .../inventory_view/components/waffle/node.tsx | 6 +---- .../components/waffle/node_context_menu.tsx | 20 ++++++---------- .../inventory_view/hooks/use_process_list.ts | 12 +++------- .../inventory_view/lib/create_uptime_link.ts | 4 ++-- .../components/chart_context_menu.tsx | 7 +++--- .../components/helpers/create_tsvb_link.ts | 3 ++- .../hooks/use_metrics_explorer_data.ts | 1 - .../public/utils/logs_overview_fetchers.ts | 8 +++---- x-pack/plugins/infra/server/deprecations.ts | 17 ++++++++++---- .../log_entries/kibana_log_entries_adapter.ts | 16 ++++++------- .../metrics/kibana_metrics_adapter.ts | 9 ++------ .../metric_threshold/lib/evaluate_alert.ts | 4 ---- .../metric_threshold/lib/metric_query.ts | 6 ++--- .../server/lib/host_details/process_list.ts | 9 ++++---- .../queries/metrics_hosts_anomalies.ts | 4 +--- .../infra_ml/queries/metrics_k8s_anomalies.ts | 4 +--- .../lib/log_analysis/log_entry_anomalies.ts | 11 ++------- .../log_entry_categories_analysis.ts | 11 ++------- .../queries/log_entry_category_examples.ts | 7 +++--- .../queries/log_entry_examples.ts | 7 +++--- .../infra/server/lib/sources/defaults.ts | 11 +-------- .../sources/saved_object_references.test.ts | 5 ---- x-pack/plugins/infra/server/plugin.ts | 5 ---- .../lib/get_cloud_metadata.ts | 3 ++- .../metadata/lib/get_cloud_metric_metadata.ts | 3 ++- .../metadata/lib/get_metric_metadata.ts | 5 ++-- .../routes/metadata/lib/get_node_info.ts | 8 +++---- .../routes/metadata/lib/get_pod_node_name.ts | 8 +++---- .../lib/find_interval_for_metrics.ts | 1 - .../lib/get_dataset_for_field.ts | 7 +++--- .../lib/query_total_groupings.ts | 3 ++- .../overview/lib/create_top_nodes_query.ts | 5 ++-- .../lib/create_timerange_with_interval.ts | 2 -- ...orm_request_to_metrics_api_request.test.ts | 5 ---- ...ransform_request_to_metrics_api_request.ts | 9 +++----- .../log_entries_search_strategy.test.ts | 5 ---- .../log_entries_search_strategy.ts | 4 +--- .../log_entry_search_strategy.test.ts | 5 ---- .../log_entries/log_entry_search_strategy.ts | 15 ++---------- .../log_entries/queries/log_entries.ts | 7 +++--- .../services/log_entries/queries/log_entry.ts | 5 ++-- .../server/utils/calculate_metric_interval.ts | 4 ++-- 115 files changed, 227 insertions(+), 364 deletions(-) diff --git a/x-pack/plugins/infra/common/constants.ts b/x-pack/plugins/infra/common/constants.ts index 1c3aa550f2f62..4c70e34c9899f 100644 --- a/x-pack/plugins/infra/common/constants.ts +++ b/x-pack/plugins/infra/common/constants.ts @@ -8,7 +8,6 @@ export const DEFAULT_SOURCE_ID = 'default'; export const METRICS_INDEX_PATTERN = 'metrics-*,metricbeat-*'; export const LOGS_INDEX_PATTERN = 'logs-*,filebeat-*,kibana_sample_data_logs*'; -export const TIMESTAMP_FIELD = '@timestamp'; export const METRICS_APP = 'metrics'; export const LOGS_APP = 'logs'; @@ -16,3 +15,9 @@ export const METRICS_FEATURE_ID = 'infrastructure'; export const LOGS_FEATURE_ID = 'logs'; export type InfraFeatureId = typeof METRICS_FEATURE_ID | typeof LOGS_FEATURE_ID; + +export const TIMESTAMP_FIELD = '@timestamp'; +export const TIEBREAKER_FIELD = '_doc'; +export const HOST_FIELD = 'host.name'; +export const CONTAINER_FIELD = 'container.id'; +export const POD_FIELD = 'kubernetes.pod.uid'; diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts index ff4ee4fd328da..19f71800ab1b6 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts @@ -16,7 +16,6 @@ export const LOG_ANALYSIS_VALIDATE_DATASETS_PATH = export const validateLogEntryDatasetsRequestPayloadRT = rt.type({ data: rt.type({ indices: rt.array(rt.string), - timestampField: rt.string, startTime: rt.number, endTime: rt.number, runtimeMappings: rt.UnknownRecord, diff --git a/x-pack/plugins/infra/common/http_api/metrics_api.ts b/x-pack/plugins/infra/common/http_api/metrics_api.ts index c2449707647d7..315a42380397b 100644 --- a/x-pack/plugins/infra/common/http_api/metrics_api.ts +++ b/x-pack/plugins/infra/common/http_api/metrics_api.ts @@ -10,7 +10,6 @@ import { MetricsUIAggregationRT } from '../inventory_models/types'; import { afterKeyObjectRT } from './metrics_explorer'; export const MetricsAPITimerangeRT = rt.type({ - field: rt.string, from: rt.number, to: rt.number, interval: rt.string, diff --git a/x-pack/plugins/infra/common/http_api/metrics_explorer.ts b/x-pack/plugins/infra/common/http_api/metrics_explorer.ts index 5617bd0954f5d..de00d521126e3 100644 --- a/x-pack/plugins/infra/common/http_api/metrics_explorer.ts +++ b/x-pack/plugins/infra/common/http_api/metrics_explorer.ts @@ -41,7 +41,6 @@ export const metricsExplorerMetricRT = rt.intersection([ ]); export const timeRangeRT = rt.type({ - field: rt.string, from: rt.number, to: rt.number, interval: rt.string, 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 index f469a9e86ad49..c30c98585bfe8 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuKernel: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerCpuKernel: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index f4efc7de43663..0e4bbfa51ac33 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerCpuUsage: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 3ba2b11740b6e..9ae3daa1bac99 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOBytes: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerDiskIOBytes: TSVBMetricModelCreator = ( requires: ['docker.disk'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 772c0d6c0a33e..cd71d5878451a 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOOps: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerDiskIOOps: TSVBMetricModelCreator = ( requires: ['docker.disk'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index e0572692d60fc..5d00a2517ce61 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerMemory: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerMemory: TSVBMetricModelCreator = ( requires: ['docker.memory'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index d957d51a41648..fa52a955c7765 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerNetworkTraffic: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerNetworkTraffic: TSVBMetricModelCreator = ( requires: ['docker.network'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index c2d234be2eed7..cda78201d9104 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerOverview: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const containerOverview: TSVBMetricModelCreator = ( requires: ['docker'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 5c9b3beb31c7c..fbddb47e2175b 100644 --- a/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts +++ b/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../constants'; import { TSVBMetricModelCreator, TSVBMetricModel, TSVBSeries, InventoryMetric } from './types'; export const createTSVBModel = @@ -15,13 +16,13 @@ export const createTSVBModel = interval = '>=300s', dropLastBucket = true ): TSVBMetricModelCreator => - (timeField, indexPattern): TSVBMetricModel => ({ + (indexPattern): TSVBMetricModel => ({ id, requires, drop_last_bucket: dropLastBucket, index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series, }); 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 index bcafeb4ebc4cf..8fa74e17826b0 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostCpuUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostCpuUsage: TSVBMetricModelCreator = ( requires: ['system.cpu'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 4cc2b574362d7..c3f6c83334486 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerInfo: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostDockerInfo: TSVBMetricModelCreator = ( requires: ['docker.info'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index df56a21dbf5b7..8738bea2631b2 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerOverview: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostDockerOverview: TSVBMetricModelCreator = ( requires: ['docker.info'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'top_n', series: [ { 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 index fd9eb97419736..54066cdba26ef 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index cad828671d232..ffbf509672768 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( requires: ['docker.memory'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index ce284345410fc..52db291e60f01 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostFilesystem: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostFilesystem: TSVBMetricModelCreator = ( requires: ['system.filesystem'], filter: 'system.filesystem.device_name:\\/*', index_pattern: indexPattern, - time_field: timeField, + time_field: TIMESTAMP_FIELD, interval, type: 'timeseries', series: [ 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 index d33e4cdeb34cd..84f9c77cffda1 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sCpuCap: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const hostK8sCpuCap: TSVBMetricModelCreator = ( requires: ['kubernetes.node'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index e9e512a136631..57b9ee724670e 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sDiskCap: TSVBMetricModelCreator = ( timeField, @@ -16,7 +17,7 @@ export const hostK8sDiskCap: TSVBMetricModelCreator = ( requires: ['kubernetes.node'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index ccc227ef1854e..6d358927950f7 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sMemoryCap: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const hostK8sMemoryCap: TSVBMetricModelCreator = ( requires: ['kubernetes.node'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 2da74d50dff1b..3668a1eb9ba57 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sOverview: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostK8sOverview: TSVBMetricModelCreator = ( requires: ['kubernetes'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'top_n', series: [ { 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 index 85cb798eaf9b9..557de523f7b15 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sPodCap: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const hostK8sPodCap: TSVBMetricModelCreator = ( map_field_to: 'kubernetes.node.name', index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ 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 index bef170c743e6c..36b97b91baec6 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostLoad: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostLoad: TSVBMetricModelCreator = ( requires: ['system.cpu'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index bda81dea4bd28..833a43af45946 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostMemoryUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostMemoryUsage: TSVBMetricModelCreator = ( requires: ['system.memory'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index ec8c0937ce0ea..fbaa48b493c64 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostNetworkTraffic: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostNetworkTraffic: TSVBMetricModelCreator = ( requires: ['system.network'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index eef480e12aab0..b40a84d6d7835 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostSystemOverview: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const hostSystemOverview: TSVBMetricModelCreator = ( requires: ['system.cpu', 'system.memory', 'system.load', 'system.network'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'top_n', series: [ { diff --git a/x-pack/plugins/infra/common/inventory_models/index.ts b/x-pack/plugins/infra/common/inventory_models/index.ts index 6350e76ca7f29..81f89be8cd6a6 100644 --- a/x-pack/plugins/infra/common/inventory_models/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/index.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { POD_FIELD, HOST_FIELD, CONTAINER_FIELD } from '../constants'; import { host } from './host'; import { pod } from './pod'; import { awsEC2 } from './aws_ec2'; @@ -30,31 +31,23 @@ export const findInventoryModel = (type: InventoryItemType) => { return model; }; -interface InventoryFields { - host: string; - pod: string; - container: string; - timestamp: string; - tiebreaker: string; -} - const LEGACY_TYPES = ['host', 'pod', 'container']; -const getFieldByType = (type: InventoryItemType, fields: InventoryFields) => { +export const getFieldByType = (type: InventoryItemType) => { switch (type) { case 'pod': - return fields.pod; + return POD_FIELD; case 'host': - return fields.host; + return HOST_FIELD; case 'container': - return fields.container; + return CONTAINER_FIELD; } }; -export const findInventoryFields = (type: InventoryItemType, fields?: InventoryFields) => { +export const findInventoryFields = (type: InventoryItemType) => { const inventoryModel = findInventoryModel(type); - if (fields && LEGACY_TYPES.includes(type)) { - const id = getFieldByType(type, fields) || inventoryModel.fields.id; + if (LEGACY_TYPES.includes(type)) { + const id = getFieldByType(type) || inventoryModel.fields.id; return { ...inventoryModel.fields, id, 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 index a7574fc68813f..b038d80d6afe1 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podCpuUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const podCpuUsage: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 0e2a588463160..26b06e1fd555a 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podLogUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const podLogUsage: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 9c774e1b18ed0..b882cb7c6b18f 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podMemoryUsage: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const podMemoryUsage: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index f9b8737f54a91..6f964c6411d7c 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podNetworkTraffic: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const podNetworkTraffic: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 5746410f03388..b97f0389dd00c 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podOverview: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const podOverview: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 51b9a4cfc7b3f..a37d82f20231f 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const awsCpuUtilization: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const awsCpuUtilization: TSVBMetricModelCreator = ( id_type: 'cloud', index_pattern: indexPattern, interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 5224545c006b7..6704e4895108c 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const awsDiskioBytes: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const awsDiskioBytes: TSVBMetricModelCreator = ( map_field_to: 'cloud.instance.id', id_type: 'cloud', interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index c362a6d88c27a..cb4dd3ad4e8b8 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const awsDiskioOps: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ @@ -14,7 +15,7 @@ export const awsDiskioOps: TSVBMetricModelCreator = (timeField, indexPattern): T map_field_to: 'cloud.instance.id', id_type: 'cloud', interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index b142feb95450c..9c31897718f5b 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; // see discussion in: https://github.com/elastic/kibana/issues/42687 @@ -19,7 +20,7 @@ export const awsNetworkBytes: TSVBMetricModelCreator = ( map_field_to: 'cloud.instance.id', id_type: 'cloud', interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 9d39582b66864..dd34d4a6b710a 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const awsNetworkPackets: TSVBMetricModelCreator = ( @@ -17,7 +18,7 @@ export const awsNetworkPackets: TSVBMetricModelCreator = ( map_field_to: 'cloud.instance.id', id_type: 'cloud', interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 3fe12d62d3352..16df717f400be 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const awsOverview: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ @@ -14,7 +15,7 @@ export const awsOverview: TSVBMetricModelCreator = (timeField, indexPattern): TS map_field_to: 'cloud.instance.id', id_type: 'cloud', interval: '>=5m', - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'top_n', series: [ { 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 index 23b9c274b4335..06b93bdbc1022 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxActiveConnections: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const nginxActiveConnections: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 3b467bbe52fcd..89a1de03724d8 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxHits: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const nginxHits: TSVBMetricModelCreator = ( requires: ['nginx.access'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index 9fbf0c38ba3b8..3cf34a67ca797 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestRate: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const nginxRequestRate: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { 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 index f825dbe7b7543..dcfb17a097e82 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( @@ -16,7 +17,7 @@ export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: timeField, + time_field: TIMESTAMP_FIELD, type: 'timeseries', series: [ { diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts index 35fd7a13a4084..7ca0b69a25be9 100644 --- a/x-pack/plugins/infra/common/inventory_models/types.ts +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -220,7 +220,6 @@ export const TSVBMetricModelRT = rt.intersection([ export type TSVBMetricModel = rt.TypeOf; export type TSVBMetricModelCreator = ( - timeField: string, indexPattern: string | string[], interval: string ) => TSVBMetricModel; diff --git a/x-pack/plugins/infra/common/log_analysis/job_parameters.ts b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts index b8fa429195ff3..6e964e3a94f65 100644 --- a/x-pack/plugins/infra/common/log_analysis/job_parameters.ts +++ b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts @@ -36,7 +36,6 @@ export type DatasetFilter = rt.TypeOf; export const jobSourceConfigurationRT = rt.partial({ indexPattern: rt.string, - timestampField: rt.string, bucketSpan: rt.number, datasetFilter: datasetFilterRT, }); diff --git a/x-pack/plugins/infra/common/log_sources/log_source_configuration.ts b/x-pack/plugins/infra/common/log_sources/log_source_configuration.ts index ab98ad75b8433..5d46ce59457da 100644 --- a/x-pack/plugins/infra/common/log_sources/log_source_configuration.ts +++ b/x-pack/plugins/infra/common/log_sources/log_source_configuration.ts @@ -16,11 +16,6 @@ export const logSourceConfigurationOriginRT = rt.keyof({ export type LogSourceConfigurationOrigin = rt.TypeOf; const logSourceFieldsConfigurationRT = rt.strict({ - container: rt.string, - host: rt.string, - pod: rt.string, - timestamp: rt.string, - tiebreaker: rt.string, message: rt.array(rt.string), }); diff --git a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts index 567acf1fc4134..4bcee63f3642b 100644 --- a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts +++ b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts @@ -18,8 +18,6 @@ export interface ResolvedLogSourceConfiguration { name: string; description: string; indices: string; - timestampField: string; - tiebreakerField: string; messageField: string[]; fields: DataView['fields']; runtimeMappings: estypes.MappingRuntimeFields; @@ -61,8 +59,6 @@ const resolveLegacyReference = async ( return { indices: sourceConfiguration.logIndices.indexName, - timestampField: sourceConfiguration.fields.timestamp, - tiebreakerField: sourceConfiguration.fields.tiebreaker, messageField: sourceConfiguration.fields.message, fields, runtimeMappings: {}, @@ -91,8 +87,6 @@ const resolveKibanaIndexPatternReference = async ( return { indices: indexPattern.title, - timestampField: indexPattern.timeFieldName ?? '@timestamp', - tiebreakerField: '_doc', messageField: ['message'], fields: indexPattern.fields, runtimeMappings: resolveRuntimeMappings(indexPattern), diff --git a/x-pack/plugins/infra/common/metrics_sources/index.ts b/x-pack/plugins/infra/common/metrics_sources/index.ts index a697c65e5a0aa..7fae908707a89 100644 --- a/x-pack/plugins/infra/common/metrics_sources/index.ts +++ b/x-pack/plugins/infra/common/metrics_sources/index.ts @@ -6,7 +6,6 @@ */ import * as rt from 'io-ts'; -import { omit } from 'lodash'; import { SourceConfigurationRT, SourceStatusRuntimeType, @@ -22,7 +21,6 @@ export const metricsSourceConfigurationPropertiesRT = rt.strict({ metricAlias: SourceConfigurationRT.props.metricAlias, inventoryDefaultView: SourceConfigurationRT.props.inventoryDefaultView, metricsExplorerDefaultView: SourceConfigurationRT.props.metricsExplorerDefaultView, - fields: rt.strict(omit(SourceConfigurationRT.props.fields.props, 'message')), anomalyThreshold: rt.number, }); @@ -32,9 +30,6 @@ export type MetricsSourceConfigurationProperties = rt.TypeOf< export const partialMetricsSourceConfigurationPropertiesRT = rt.partial({ ...metricsSourceConfigurationPropertiesRT.type.props, - fields: rt.partial({ - ...metricsSourceConfigurationPropertiesRT.type.props.fields.type.props, - }), }); export type PartialMetricsSourceConfigurationProperties = rt.TypeOf< diff --git a/x-pack/plugins/infra/common/source_configuration/source_configuration.ts b/x-pack/plugins/infra/common/source_configuration/source_configuration.ts index 436432e9f0caf..4795c3f641f63 100644 --- a/x-pack/plugins/infra/common/source_configuration/source_configuration.ts +++ b/x-pack/plugins/infra/common/source_configuration/source_configuration.ts @@ -52,12 +52,7 @@ export const sourceConfigurationConfigFilePropertiesRT = rt.type({ logAlias: rt.string, // Cannot be deprecated until 8.0.0. Will be converted to an indexName reference. metricAlias: rt.string, fields: rt.partial({ - timestamp: rt.string, message: rt.array(rt.string), - tiebreaker: rt.string, - host: rt.string, - container: rt.string, - pod: rt.string, }), }), }), @@ -115,11 +110,6 @@ export type InfraSourceConfigurationColumn = rt.TypeOf { metricAlias: 'metricbeat-*', inventoryDefaultView: 'host', metricsExplorerDefaultView: 'host', - fields: { - timestamp: '@timestamp', - container: 'container.id', - host: 'host.name', - pod: 'kubernetes.pod.uid', - tiebreaker: '_doc', - }, anomalyThreshold: 20, }, }; diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts index 9de6e574ecb5b..9ffc33c5f9c2a 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts @@ -16,14 +16,13 @@ import { decodeOrThrow } from '../../../../../common/runtime_types'; interface RequestArgs { indices: string[]; - timestampField: string; startTime: number; endTime: number; runtimeMappings: estypes.MappingRuntimeFields; } export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: HttpHandler) => { - const { indices, timestampField, startTime, endTime, runtimeMappings } = requestArgs; + const { indices, startTime, endTime, runtimeMappings } = requestArgs; const response = await fetch(LOG_ANALYSIS_VALIDATE_DATASETS_PATH, { method: 'POST', body: JSON.stringify( @@ -32,7 +31,6 @@ export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: H endTime, indices, startTime, - timestampField, runtimeMappings, }, }) diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx index d844b7439710c..15b7eea0487af 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx @@ -21,7 +21,7 @@ export const useLogAnalysisModule = ({ moduleDescriptor: ModuleDescriptor; }) => { const { services } = useKibanaContextForPlugin(); - const { spaceId, sourceId, timestampField, runtimeMappings } = sourceConfiguration; + const { spaceId, sourceId, runtimeMappings } = sourceConfiguration; const [moduleStatus, dispatchModuleStatus] = useModuleStatus(moduleDescriptor.jobTypes); const trackMetric = useUiTracker({ app: 'infra_logs' }); @@ -66,7 +66,6 @@ export const useLogAnalysisModule = ({ indices: selectedIndices, sourceId, spaceId, - timestampField, runtimeMappings, }, services.http.fetch @@ -114,7 +113,7 @@ export const useLogAnalysisModule = ({ } }, }, - [moduleDescriptor.setUpModule, spaceId, sourceId, timestampField] + [moduleDescriptor.setUpModule, spaceId, sourceId] ); const [cleanUpModuleRequest, cleanUpModule] = useTrackedPromise( diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts index 057580679210a..b77e195cf050e 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts @@ -52,7 +52,6 @@ export const isJobConfigurationOutdated = new Set(jobConfiguration.indexPattern.split(',')), new Set(currentSourceConfiguration.indices) ) && - jobConfiguration.timestampField === currentSourceConfiguration.timestampField && equal(datafeedRuntimeMappings, currentSourceConfiguration.runtimeMappings) ); }; diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts index 4ae99b95cfff8..117df40c0c9bc 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts @@ -46,13 +46,11 @@ export interface ModuleDescriptor { ) => Promise; validateSetupIndices: ( indices: string[], - timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => Promise; validateSetupDatasets: ( indices: string[], - timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, @@ -64,6 +62,5 @@ export interface ModuleSourceConfiguration { indices: string[]; sourceId: string; spaceId: string; - timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; } diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts index fad6fd56f6251..39bb9b2948590 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts @@ -161,7 +161,6 @@ export const useAnalysisSetupState = ({ createPromise: async () => { return await validateSetupIndices( sourceConfiguration.indices, - sourceConfiguration.timestampField, sourceConfiguration.runtimeMappings, services.http.fetch ); @@ -173,7 +172,7 @@ export const useAnalysisSetupState = ({ setValidatedIndices([]); }, }, - [sourceConfiguration.indices, sourceConfiguration.timestampField] + [sourceConfiguration.indices] ); const [validateDatasetsRequest, validateDatasets] = useTrackedPromise( @@ -186,7 +185,6 @@ export const useAnalysisSetupState = ({ return await validateSetupDatasets( validIndexNames, - sourceConfiguration.timestampField, startTime ?? 0, endTime ?? Date.now(), sourceConfiguration.runtimeMappings, @@ -197,7 +195,7 @@ export const useAnalysisSetupState = ({ updateIndicesWithAvailableDatasets(datasets); }, }, - [validIndexNames, sourceConfiguration.timestampField, startTime, endTime] + [validIndexNames, startTime, endTime] ); const setUp = useCallback(() => { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts index 6823ed173a740..b2a3e9f2df4f2 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts @@ -8,6 +8,7 @@ import type { estypes } from '@elastic/elasticsearch'; import { i18n } from '@kbn/i18n'; import type { HttpHandler } from 'src/core/public'; +import { TIMESTAMP_FIELD } from '../../../../../../common/constants'; import { bucketSpan, categoriesMessageField, @@ -63,7 +64,7 @@ const setUpModule = async ( start: number | undefined, end: number | undefined, datasetFilter: DatasetFilter, - { spaceId, sourceId, indices, timestampField, runtimeMappings }: ModuleSourceConfiguration, + { spaceId, sourceId, indices, runtimeMappings }: ModuleSourceConfiguration, fetch: HttpHandler ) => { const indexNamePattern = indices.join(','); @@ -74,12 +75,12 @@ const setUpModule = async ( bucket_span: `${bucketSpan}ms`, }, data_description: { - time_field: timestampField, + time_field: TIMESTAMP_FIELD, }, custom_settings: { logs_source_config: { indexPattern: indexNamePattern, - timestampField, + timestampField: TIMESTAMP_FIELD, bucketSpan, datasetFilter, }, @@ -136,7 +137,6 @@ const cleanUpModule = async (spaceId: string, sourceId: string, fetch: HttpHandl const validateSetupIndices = async ( indices: string[], - timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { @@ -145,7 +145,7 @@ const validateSetupIndices = async ( indices, fields: [ { - name: timestampField, + name: TIMESTAMP_FIELD, validTypes: ['date'], }, { @@ -165,16 +165,12 @@ const validateSetupIndices = async ( const validateSetupDatasets = async ( indices: string[], - timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { - return await callValidateDatasetsAPI( - { indices, timestampField, startTime, endTime, runtimeMappings }, - fetch - ); + return await callValidateDatasetsAPI({ indices, startTime, endTime, runtimeMappings }, fetch); }; export const logEntryCategoriesModule: ModuleDescriptor = { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx index 99d4ab4becee5..adb2822649f73 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx @@ -19,13 +19,11 @@ export const useLogEntryCategoriesModule = ({ indexPattern, sourceId, spaceId, - timestampField, runtimeMappings, }: { indexPattern: string; sourceId: string; spaceId: string; - timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( @@ -33,10 +31,9 @@ export const useLogEntryCategoriesModule = ({ indices: indexPattern.split(','), sourceId, spaceId, - timestampField, runtimeMappings, }), - [indexPattern, sourceId, spaceId, timestampField, runtimeMappings] + [indexPattern, sourceId, spaceId, runtimeMappings] ); const logAnalysisModule = useLogAnalysisModule({ diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts index c4c939d0ebb9d..053d34e686313 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts @@ -16,6 +16,7 @@ import { logEntryRateJobTypes, partitionField, } from '../../../../../../common/log_analysis'; +import { TIMESTAMP_FIELD } from '../../../../../../common/constants'; import { ModuleDescriptor, ModuleSourceConfiguration } from '../../log_analysis_module_types'; import { cleanUpJobsAndDatafeeds } from '../../log_analysis_cleanup'; import { callJobsSummaryAPI } from '../../api/ml_get_jobs_summary_api'; @@ -62,7 +63,7 @@ const setUpModule = async ( start: number | undefined, end: number | undefined, datasetFilter: DatasetFilter, - { spaceId, sourceId, indices, timestampField, runtimeMappings }: ModuleSourceConfiguration, + { spaceId, sourceId, indices, runtimeMappings }: ModuleSourceConfiguration, fetch: HttpHandler ) => { const indexNamePattern = indices.join(','); @@ -73,12 +74,12 @@ const setUpModule = async ( bucket_span: `${bucketSpan}ms`, }, data_description: { - time_field: timestampField, + time_field: TIMESTAMP_FIELD, }, custom_settings: { logs_source_config: { indexPattern: indexNamePattern, - timestampField, + timestampField: TIMESTAMP_FIELD, bucketSpan, }, }, @@ -128,7 +129,6 @@ const cleanUpModule = async (spaceId: string, sourceId: string, fetch: HttpHandl const validateSetupIndices = async ( indices: string[], - timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { @@ -137,7 +137,7 @@ const validateSetupIndices = async ( indices, fields: [ { - name: timestampField, + name: TIMESTAMP_FIELD, validTypes: ['date'], }, { @@ -153,16 +153,12 @@ const validateSetupIndices = async ( const validateSetupDatasets = async ( indices: string[], - timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { - return await callValidateDatasetsAPI( - { indices, timestampField, startTime, endTime, runtimeMappings }, - fetch - ); + return await callValidateDatasetsAPI({ indices, startTime, endTime, runtimeMappings }, fetch); }; export const logEntryRateModule: ModuleDescriptor = { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx index f3e8f7e777597..480e3bc10fc62 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx @@ -18,13 +18,11 @@ export const useLogEntryRateModule = ({ indexPattern, sourceId, spaceId, - timestampField, runtimeMappings, }: { indexPattern: string; sourceId: string; spaceId: string; - timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( @@ -32,10 +30,9 @@ export const useLogEntryRateModule = ({ indices: indexPattern.split(','), sourceId, spaceId, - timestampField, runtimeMappings, }), - [indexPattern, sourceId, spaceId, timestampField, runtimeMappings] + [indexPattern, sourceId, spaceId, runtimeMappings] ); const logAnalysisModule = useLogAnalysisModule({ diff --git a/x-pack/plugins/infra/public/containers/ml/infra_ml_module.tsx b/x-pack/plugins/infra/public/containers/ml/infra_ml_module.tsx index 198a99f394850..22376648ca003 100644 --- a/x-pack/plugins/infra/public/containers/ml/infra_ml_module.tsx +++ b/x-pack/plugins/infra/public/containers/ml/infra_ml_module.tsx @@ -19,7 +19,7 @@ export const useInfraMLModule = ({ moduleDescriptor: ModuleDescriptor; }) => { const { services } = useKibanaContextForPlugin(); - const { spaceId, sourceId, timestampField } = sourceConfiguration; + const { spaceId, sourceId } = sourceConfiguration; const [moduleStatus, dispatchModuleStatus] = useModuleStatus(moduleDescriptor.jobTypes); const [, fetchJobStatus] = useTrackedPromise( @@ -64,7 +64,6 @@ export const useInfraMLModule = ({ indices: selectedIndices, sourceId, spaceId, - timestampField, }, partitionField, }, @@ -91,7 +90,7 @@ export const useInfraMLModule = ({ dispatchModuleStatus({ type: 'failedSetup' }); }, }, - [moduleDescriptor.setUpModule, spaceId, sourceId, timestampField] + [moduleDescriptor.setUpModule, spaceId, sourceId] ); const [cleanUpModuleRequest, cleanUpModule] = useTrackedPromise( diff --git a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_configuration.ts b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_configuration.ts index 4c876c1705364..c258debdddbca 100644 --- a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_configuration.ts +++ b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_configuration.ts @@ -45,8 +45,7 @@ export const isJobConfigurationOutdated = isSubset( new Set(jobConfiguration.indexPattern.split(',')), new Set(currentSourceConfiguration.indices) - ) && - jobConfiguration.timestampField === currentSourceConfiguration.timestampField + ) ); }; diff --git a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts index 5a5272f783053..3fbe7dc9d1df0 100644 --- a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts +++ b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts @@ -49,12 +49,10 @@ export interface ModuleDescriptor { ) => Promise; validateSetupIndices?: ( indices: string[], - timestampField: string, fetch: HttpHandler ) => Promise; validateSetupDatasets?: ( indices: string[], - timestampField: string, startTime: number, endTime: number, fetch: HttpHandler @@ -65,7 +63,6 @@ export interface ModuleSourceConfiguration { indices: string[]; sourceId: string; spaceId: string; - timestampField: string; } interface ManyCategoriesWarningReason { diff --git a/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module.tsx b/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module.tsx index f892ab62ee3d8..f200ab22c043f 100644 --- a/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module.tsx +++ b/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module.tsx @@ -17,21 +17,18 @@ export const useMetricHostsModule = ({ indexPattern, sourceId, spaceId, - timestampField, }: { indexPattern: string; sourceId: string; spaceId: string; - timestampField: string; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( () => ({ indices: indexPattern.split(','), sourceId, spaceId, - timestampField, }), - [indexPattern, sourceId, spaceId, timestampField] + [indexPattern, sourceId, spaceId] ); const infraMLModule = useInfraMLModule({ diff --git a/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module_descriptor.ts b/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module_descriptor.ts index a7ab948d052aa..f87cd78f4ff34 100644 --- a/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/ml/modules/metrics_hosts/module_descriptor.ts @@ -18,6 +18,7 @@ import { MetricsHostsJobType, bucketSpan, } from '../../../../../common/infra_ml'; +import { TIMESTAMP_FIELD } from '../../../../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import MemoryJob from '../../../../../../ml/server/models/data_recognizer/modules/metrics_ui_hosts/ml/hosts_memory_usage.json'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -68,7 +69,7 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler) start, end, filter, - moduleSourceConfiguration: { spaceId, sourceId, indices, timestampField }, + moduleSourceConfiguration: { spaceId, sourceId, indices }, partitionField, } = setUpModuleArgs; @@ -93,13 +94,13 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler) return { job_id: id, data_description: { - time_field: timestampField, + time_field: TIMESTAMP_FIELD, }, analysis_config, custom_settings: { metrics_source_config: { indexPattern: indexNamePattern, - timestampField, + timestampField: TIMESTAMP_FIELD, bucketSpan, }, }, diff --git a/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module.tsx b/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module.tsx index eadc374434817..08f4f49058dbe 100644 --- a/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module.tsx +++ b/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module.tsx @@ -17,21 +17,18 @@ export const useMetricK8sModule = ({ indexPattern, sourceId, spaceId, - timestampField, }: { indexPattern: string; sourceId: string; spaceId: string; - timestampField: string; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( () => ({ indices: indexPattern.split(','), sourceId, spaceId, - timestampField, }), - [indexPattern, sourceId, spaceId, timestampField] + [indexPattern, sourceId, spaceId] ); const infraMLModule = useInfraMLModule({ diff --git a/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module_descriptor.ts b/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module_descriptor.ts index 4c5eb5fd4bf23..388a7dd0a5656 100644 --- a/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/ml/modules/metrics_k8s/module_descriptor.ts @@ -18,6 +18,7 @@ import { MetricK8sJobType, bucketSpan, } from '../../../../../common/infra_ml'; +import { TIMESTAMP_FIELD } from '../../../../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import MemoryJob from '../../../../../../ml/server/models/data_recognizer/modules/metrics_ui_k8s/ml/k8s_memory_usage.json'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -69,7 +70,7 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler) start, end, filter, - moduleSourceConfiguration: { spaceId, sourceId, indices, timestampField }, + moduleSourceConfiguration: { spaceId, sourceId, indices }, partitionField, } = setUpModuleArgs; @@ -93,13 +94,13 @@ const setUpModule = async (setUpModuleArgs: SetUpModuleArgs, fetch: HttpHandler) return { job_id: id, data_description: { - time_field: timestampField, + time_field: TIMESTAMP_FIELD, }, analysis_config, custom_settings: { metrics_source_config: { indexPattern: indexNamePattern, - timestampField, + timestampField: TIMESTAMP_FIELD, bucketSpan, }, }, diff --git a/x-pack/plugins/infra/public/lib/lib.ts b/x-pack/plugins/infra/public/lib/lib.ts index 4541eb6518788..a37a9af7d9320 100644 --- a/x-pack/plugins/infra/public/lib/lib.ts +++ b/x-pack/plugins/infra/public/lib/lib.ts @@ -14,7 +14,6 @@ import { SnapshotNodeMetric, SnapshotNodePath, } from '../../common/http_api/snapshot_api'; -import { MetricsSourceConfigurationProperties } from '../../common/metrics_sources'; import { WaffleSortOption } from '../pages/metrics/inventory_view/hooks/use_waffle_options'; export interface InfraWaffleMapNode { @@ -124,7 +123,6 @@ export enum InfraWaffleMapRuleOperator { } export interface InfraWaffleMapOptions { - fields?: MetricsSourceConfigurationProperties['fields'] | null; formatter: InfraFormatterType; formatTemplate: string; metric: SnapshotMetricInput; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx index 1eed4b6af65e8..1e2f885a936fb 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx @@ -40,7 +40,6 @@ export const LogEntryCategoriesPageProviders: React.FunctionComponent = ({ child indexPattern={resolvedSourceConfiguration.indices} sourceId={sourceId} spaceId={space.id} - timestampField={resolvedSourceConfiguration.timestampField} runtimeMappings={resolvedSourceConfiguration.runtimeMappings} > {children} diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx index 043ed2501c973..5526873da14c9 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx @@ -43,14 +43,12 @@ export const LogEntryRatePageProviders: React.FunctionComponent = ({ children }) indexPattern={resolvedSourceConfiguration.indices} sourceId={sourceId} spaceId={space.id} - timestampField={resolvedSourceConfiguration.timestampField} runtimeMappings={resolvedSourceConfiguration.runtimeMappings} > {children} diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx index de0a56c5be73d..f46a379f52d50 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx @@ -18,7 +18,6 @@ import { PageContent } from '../../../../components/page'; import { useWaffleTimeContext } from '../hooks/use_waffle_time'; import { useWaffleFiltersContext } from '../hooks/use_waffle_filters'; import { DEFAULT_LEGEND, useWaffleOptionsContext } from '../hooks/use_waffle_options'; -import { useSourceContext } from '../../../../containers/metrics_source'; import { InfraFormatterType } from '../../../../lib/lib'; import { euiStyled } from '../../../../../../../../src/plugins/kibana_react/common'; import { Toolbar } from './toolbars/toolbar'; @@ -41,7 +40,6 @@ interface Props { export const Layout = React.memo( ({ shouldLoadDefault, currentView, reload, interval, nodes, loading }: Props) => { const [showLoading, setShowLoading] = useState(true); - const { source } = useSourceContext(); const { metric, groupBy, @@ -65,7 +63,6 @@ export const Layout = React.memo( legend: createLegend(legendPalette, legendSteps, legendReverseColors), metric, sort, - fields: source?.configuration?.fields, groupBy, }; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomaly_detection_flyout.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomaly_detection_flyout.tsx index 4e28fb4202bdc..1fcec291fcc29 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomaly_detection_flyout.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/ml/anomaly_detection/anomaly_detection_flyout.tsx @@ -67,13 +67,11 @@ export const AnomalyDetectionFlyout = () => { indexPattern={source?.configuration.metricAlias ?? ''} sourceId={'default'} spaceId={space.id} - timestampField={source?.configuration.fields.timestamp ?? ''} > {screenName === 'home' && ( diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx index fbb8bd469c1e1..15bebfd2086e3 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx @@ -76,9 +76,7 @@ const TabComponent = (props: TabProps) => { () => createDerivedIndexPattern('metrics'), [createDerivedIndexPattern] ); - let filter = options.fields - ? `${findInventoryFields(nodeType, options.fields).id}: "${node.id}"` - : ''; + let filter = `${findInventoryFields(nodeType).id}: "${node.id}"`; if (filter) { filter = convertKueryToElasticSearchQuery(filter, derivedIndexPattern); diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx index c227a31edc4ab..7cab8148bb797 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx @@ -36,8 +36,6 @@ const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { isAscending: false, }); - const timefield = options.fields!.timestamp; - const hostTerm = useMemo(() => { const field = options.fields && Reflect.has(options.fields, nodeType) @@ -51,7 +49,7 @@ const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { error, response, makeRequest: reload, - } = useProcessList(hostTerm, timefield, currentTime, sortBy, parseSearchString(searchFilter)); + } = useProcessList(hostTerm, currentTime, sortBy, parseSearchString(searchFilter)); const debouncedSearchOnChange = useMemo( () => debounce<(queryText: string) => void>((queryText) => setSearchFilter(queryText), 500), @@ -73,7 +71,7 @@ const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { return ( - + { {isAlertFlyoutVisible && ( = withTheme return { label: host.ip, value: node.ip }; } } else { - if (options.fields) { - const { id } = findInventoryFields(nodeType, options.fields); - return { - label: {id}, - value: node.id, - }; - } + const { id } = findInventoryFields(nodeType); + return { + label: {id}, + value: node.id, + }; } return { label: '', value: '' }; - }, [nodeType, node.ip, node.id, options.fields]); + }, [nodeType, node.ip, node.id]); const nodeLogsMenuItemLinkProps = useLinkProps( getNodeLogsUrl({ @@ -184,11 +182,7 @@ export const NodeContextMenu: React.FC = withTheme {flyoutVisible && ( , - timefield: string, to: number, sortBy: SortBy, searchFilter: object @@ -51,7 +50,6 @@ export function useProcessList( 'POST', JSON.stringify({ hostTerm, - timefield, indexPattern, to, sortBy: parsedSortBy, @@ -75,15 +73,11 @@ export function useProcessList( }; } -function useProcessListParams(props: { - hostTerm: Record; - timefield: string; - to: number; -}) { - const { hostTerm, timefield, to } = props; +function useProcessListParams(props: { hostTerm: Record; to: number }) { + const { hostTerm, to } = props; const { createDerivedIndexPattern } = useSourceContext(); const indexPattern = createDerivedIndexPattern('metrics').title; - return { hostTerm, indexPattern, timefield, to }; + return { hostTerm, indexPattern, to }; } const ProcessListContext = createContainter(useProcessListParams); export const [ProcessListContextProvider, useProcessListContext] = ProcessListContext; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.ts b/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.ts index 5c02893b867de..b6fa4fe4273ab 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.ts +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { get } from 'lodash'; import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../../../lib/lib'; import { InventoryItemType } from '../../../../../common/inventory_models/types'; +import { getFieldByType } from '../../../../../common/inventory_models'; import { LinkDescriptor } from '../../../../hooks/use_link_props'; export const createUptimeLink = ( @@ -24,7 +24,7 @@ export const createUptimeLink = ( }, }; } - const field = get(options, ['fields', nodeType], ''); + const field = getFieldByType(nodeType); return { app: 'uptime', hash: '/', diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx index 005dd5cc8c078..581eec3e824ae 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx @@ -27,6 +27,7 @@ import { import { createTSVBLink } from './helpers/create_tsvb_link'; import { getNodeDetailUrl } from '../../../link_to/redirect_to_node_detail'; import { InventoryItemType } from '../../../../../common/inventory_models/types'; +import { HOST_FIELD, POD_FIELD, CONTAINER_FIELD } from '../../../../../common/constants'; import { useLinkProps } from '../../../../hooks/use_link_props'; export interface Props { @@ -44,13 +45,13 @@ const fieldToNodeType = ( groupBy: string | string[] ): InventoryItemType | undefined => { const fields = Array.isArray(groupBy) ? groupBy : [groupBy]; - if (fields.includes(source.fields.host)) { + if (fields.includes(HOST_FIELD)) { return 'host'; } - if (fields.includes(source.fields.pod)) { + if (fields.includes(POD_FIELD)) { return 'pod'; } - if (fields.includes(source.fields.container)) { + if (fields.includes(CONTAINER_FIELD)) { return 'container'; } }; diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts index 84d87ee4ad1b7..5d1f9bafdedaf 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts @@ -8,6 +8,7 @@ import { encode } from 'rison-node'; import uuid from 'uuid'; import { set } from '@elastic/safer-lodash-set'; +import { TIMESTAMP_FIELD } from '../../../../../../common/constants'; import { MetricsSourceConfigurationProperties } from '../../../../../../common/metrics_sources'; import { colorTransformer, Color } from '../../../../../../common/color_palette'; import { MetricsExplorerSeries } from '../../../../../../common/http_api/metrics_explorer'; @@ -169,7 +170,7 @@ export const createTSVBLink = ( series: options.metrics.map(mapMetricToSeries(chartOptions)), show_grid: 1, show_legend: 1, - time_field: (source && source.fields.timestamp) || '@timestamp', + time_field: TIMESTAMP_FIELD, type: 'timeseries', filter: createFilterFromOptions(options, series), }, diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_data.ts b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_data.ts index 6b7e98912fd49..13e9ac527e781 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_data.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_data.ts @@ -83,7 +83,6 @@ export function useMetricsExplorerData( void 0, timerange: { ...timerange, - field: source.fields.timestamp, from: from.valueOf(), to: to.valueOf(), }, diff --git a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts index c813bd3dae781..2bfebd683e2a9 100644 --- a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts +++ b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts @@ -8,7 +8,7 @@ import { encode } from 'rison-node'; import type { estypes } from '@elastic/elasticsearch'; import { FetchData, FetchDataParams, LogsFetchDataResponse } from '../../../observability/public'; -import { DEFAULT_SOURCE_ID } from '../../common/constants'; +import { DEFAULT_SOURCE_ID, TIMESTAMP_FIELD } from '../../common/constants'; import { callFetchLogSourceConfigurationAPI } from '../containers/logs/log_source/api/fetch_log_source_configuration'; import { callFetchLogSourceStatusAPI } from '../containers/logs/log_source/api/fetch_log_source_status'; import { InfraClientCoreSetup, InfraClientStartDeps } from '../types'; @@ -30,7 +30,6 @@ interface StatsAggregation { interface LogParams { index: string; - timestampField: string; } type StatsAndSeries = Pick; @@ -63,7 +62,6 @@ export function getLogsOverviewDataFetcher( const { stats, series } = await fetchLogsOverview( { index: resolvedLogSourceConfiguration.indices, - timestampField: resolvedLogSourceConfiguration.timestampField, }, params, data @@ -117,7 +115,7 @@ async function fetchLogsOverview( function buildLogOverviewQuery(logParams: LogParams, params: FetchDataParams) { return { range: { - [logParams.timestampField]: { + [TIMESTAMP_FIELD]: { gt: new Date(params.absoluteTime.start).toISOString(), lte: new Date(params.absoluteTime.end).toISOString(), format: 'strict_date_optional_time', @@ -137,7 +135,7 @@ function buildLogOverviewAggregations(logParams: LogParams, params: FetchDataPar aggs: { series: { date_histogram: { - field: logParams.timestampField, + field: TIMESTAMP_FIELD, fixed_interval: params.intervalString, }, }, diff --git a/x-pack/plugins/infra/server/deprecations.ts b/x-pack/plugins/infra/server/deprecations.ts index 27c2b235f769b..083876ae85980 100644 --- a/x-pack/plugins/infra/server/deprecations.ts +++ b/x-pack/plugins/infra/server/deprecations.ts @@ -13,6 +13,13 @@ import { DeprecationsDetails, GetDeprecationsContext, } from 'src/core/server'; +import { + TIMESTAMP_FIELD, + TIEBREAKER_FIELD, + CONTAINER_FIELD, + HOST_FIELD, + POD_FIELD, +} from '../common/constants'; import { InfraSources } from './lib/sources'; const deprecatedFieldMessage = (fieldName: string, defaultValue: string, configNames: string[]) => @@ -28,11 +35,11 @@ const deprecatedFieldMessage = (fieldName: string, defaultValue: string, configN }); const DEFAULT_VALUES = { - timestamp: '@timestamp', - tiebreaker: '_doc', - container: 'container.id', - host: 'host.name', - pod: 'kubernetes.pod.uid', + timestamp: TIMESTAMP_FIELD, + tiebreaker: TIEBREAKER_FIELD, + container: CONTAINER_FIELD, + host: HOST_FIELD, + pod: POD_FIELD, }; const FIELD_DEPRECATION_FACTORIES: Record DeprecationsDetails> = diff --git a/x-pack/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 index 524658559eadf..4289fcfd163cd 100644 --- a/x-pack/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 @@ -24,6 +24,7 @@ import { import { SortedSearchHit } from '../framework'; import { KibanaFramework } from '../framework/kibana_framework_adapter'; import { ResolvedLogSourceConfiguration } from '../../../../common/log_sources'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; const TIMESTAMP_FORMAT = 'epoch_millis'; @@ -64,8 +65,8 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter { : {}; const sort = { - [resolvedLogSourceConfiguration.timestampField]: sortDirection, - [resolvedLogSourceConfiguration.tiebreakerField]: sortDirection, + [TIMESTAMP_FIELD]: sortDirection, + [TIEBREAKER_FIELD]: sortDirection, }; const esQuery = { @@ -83,7 +84,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter { ...createFilterClauses(query, highlightQuery), { range: { - [resolvedLogSourceConfiguration.timestampField]: { + [TIMESTAMP_FIELD]: { gte: startTimestamp, lte: endTimestamp, format: TIMESTAMP_FORMAT, @@ -146,7 +147,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter { aggregations: { count_by_date: { date_range: { - field: resolvedLogSourceConfiguration.timestampField, + field: TIMESTAMP_FIELD, format: TIMESTAMP_FORMAT, ranges: bucketIntervalStarts.map((bucketIntervalStart) => ({ from: bucketIntervalStart.getTime(), @@ -157,10 +158,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter { top_hits_by_key: { top_hits: { size: 1, - sort: [ - { [resolvedLogSourceConfiguration.timestampField]: 'asc' }, - { [resolvedLogSourceConfiguration.tiebreakerField]: 'asc' }, - ], + sort: [{ [TIMESTAMP_FIELD]: 'asc' }, { [TIEBREAKER_FIELD]: 'asc' }], _source: false, }, }, @@ -173,7 +171,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter { ...createQueryFilterClauses(filterQuery), { range: { - [resolvedLogSourceConfiguration.timestampField]: { + [TIMESTAMP_FIELD]: { gte: startTimestamp, lte: endTimestamp, format: TIMESTAMP_FORMAT, diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index 730da9511dc38..812012726d68e 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -36,7 +36,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { rawRequest: KibanaRequest ): Promise { const indexPattern = `${options.sourceConfiguration.metricAlias}`; - const fields = findInventoryFields(options.nodeType, options.sourceConfiguration.fields); + const fields = findInventoryFields(options.nodeType); const nodeField = fields.id; const search = (searchOptions: object) => @@ -122,11 +122,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { max: options.timerange.to, }; - const model = createTSVBModel( - options.sourceConfiguration.fields.timestamp, - indexPattern, - options.timerange.interval - ); + const model = createTSVBModel(indexPattern, options.timerange.interval); const client = ( opts: CallWithRequestParams @@ -137,7 +133,6 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { client, { indexPattern: `${options.sourceConfiguration.metricAlias}`, - timestampField: options.sourceConfiguration.fields.timestamp, timerange: options.timerange, }, model.requires diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_alert.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_alert.ts index 5bd7a4947b439..0f94681b0ca8d 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_alert.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_alert.ts @@ -74,7 +74,6 @@ export const evaluateAlert = Record { const body = { size: 0, @@ -22,7 +23,7 @@ export const getProcessList = async ( filter: [ { range: { - [timefield]: { + [TIMESTAMP_FIELD]: { gte: to - 60 * 1000, // 1 minute lte: to, }, @@ -47,7 +48,7 @@ export const getProcessList = async ( size: 1, sort: [ { - [timefield]: { + [TIMESTAMP_FIELD]: { order: 'desc', }, }, @@ -93,7 +94,7 @@ export const getProcessList = async ( size: 1, sort: [ { - [timefield]: { + [TIMESTAMP_FIELD]: { order: 'desc', }, }, diff --git a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts index ab50986c3b3d5..9c0f4313c6bdb 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts @@ -6,6 +6,7 @@ */ import * as rt from 'io-ts'; +import { TIEBREAKER_FIELD } from '../../../../common/constants'; import { ANOMALY_THRESHOLD } from '../../../../common/infra_ml'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { @@ -20,9 +21,6 @@ import { import { InfluencerFilter } from '../common'; import { Sort, Pagination } from '../../../../common/http_api/infra_ml'; -// TODO: Reassess validity of this against ML docs -const TIEBREAKER_FIELD = '_doc'; - const sortToMlFieldMap = { dataset: 'partition_field_value', anomalyScore: 'record_score', diff --git a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts index 8fb8df5eef3d7..23592aad2e322 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts @@ -6,6 +6,7 @@ */ import * as rt from 'io-ts'; +import { TIEBREAKER_FIELD } from '../../../../common/constants'; import { ANOMALY_THRESHOLD } from '../../../../common/infra_ml'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { @@ -20,9 +21,6 @@ import { import { InfluencerFilter } from '../common'; import { Sort, Pagination } from '../../../../common/http_api/infra_ml'; -// TODO: Reassess validity of this against ML docs -const TIEBREAKER_FIELD = '_doc'; - const sortToMlFieldMap = { dataset: 'partition_field_value', anomalyScore: 'record_score', diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts index 3210f01116f76..1a4f40ad3571f 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts @@ -346,10 +346,9 @@ export async function getLogEntryExamples( const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings); const indices = customSettings?.logs_source_config?.indexPattern; - const timestampField = customSettings?.logs_source_config?.timestampField; - const { tiebreakerField, runtimeMappings } = resolvedSourceConfiguration; + const { runtimeMappings } = resolvedSourceConfiguration; - if (indices == null || timestampField == null) { + if (indices == null) { throw new InsufficientLogAnalysisMlJobConfigurationError( `Failed to find index configuration for ml job ${jobId}` ); @@ -363,8 +362,6 @@ export async function getLogEntryExamples( sourceId, indices, runtimeMappings, - timestampField, - tiebreakerField, startTime, endTime, dataset, @@ -388,8 +385,6 @@ export async function fetchLogEntryExamples( sourceId: string, indices: string, runtimeMappings: estypes.MappingRuntimeFields, - timestampField: string, - tiebreakerField: string, startTime: number, endTime: number, dataset: string, @@ -435,8 +430,6 @@ export async function fetchLogEntryExamples( createLogEntryExamplesQuery( indices, runtimeMappings, - timestampField, - tiebreakerField, startTime, endTime, dataset, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts index 7023f7007763c..fb2d3f1cd87cc 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts @@ -165,10 +165,9 @@ export async function getLogEntryCategoryExamples( const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings); const indices = customSettings?.logs_source_config?.indexPattern; - const timestampField = customSettings?.logs_source_config?.timestampField; - const { tiebreakerField, runtimeMappings } = resolvedSourceConfiguration; + const { runtimeMappings } = resolvedSourceConfiguration; - if (indices == null || timestampField == null) { + if (indices == null) { throw new InsufficientLogAnalysisMlJobConfigurationError( `Failed to find index configuration for ml job ${logEntryCategoriesCountJobId}` ); @@ -191,8 +190,6 @@ export async function getLogEntryCategoryExamples( context, indices, runtimeMappings, - timestampField, - tiebreakerField, startTime, endTime, category._source.terms, @@ -404,8 +401,6 @@ async function fetchLogEntryCategoryExamples( requestContext: { core: { elasticsearch: { client: { asCurrentUser: ElasticsearchClient } } } }, indices: string, runtimeMappings: estypes.MappingRuntimeFields, - timestampField: string, - tiebreakerField: string, startTime: number, endTime: number, categoryQuery: string, @@ -421,8 +416,6 @@ async function fetchLogEntryCategoryExamples( createLogEntryCategoryExamplesQuery( indices, runtimeMappings, - timestampField, - tiebreakerField, startTime, endTime, categoryQuery, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts index 8b05d7c44e3f5..a1e4bb505ea9a 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts @@ -7,14 +7,13 @@ import type { estypes } from '@elastic/elasticsearch'; import * as rt from 'io-ts'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { defaultRequestParameters } from './common'; export const createLogEntryCategoryExamplesQuery = ( indices: string, runtimeMappings: estypes.MappingRuntimeFields, - timestampField: string, - tiebreakerField: string, startTime: number, endTime: number, categoryQuery: string, @@ -27,7 +26,7 @@ export const createLogEntryCategoryExamplesQuery = ( filter: [ { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: startTime, lte: endTime, }, @@ -45,7 +44,7 @@ export const createLogEntryCategoryExamplesQuery = ( }, }, runtime_mappings: runtimeMappings, - sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }], + sort: [{ [TIMESTAMP_FIELD]: 'asc' }, { [TIEBREAKER_FIELD]: 'asc' }], _source: false, fields: ['event.dataset', 'message', 'container.id', 'host.name', 'log.file.path'], }, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts index d903225facd57..d0ae561fceb93 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts @@ -7,6 +7,7 @@ import type { estypes } from '@elastic/elasticsearch'; import * as rt from 'io-ts'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { partitionField } from '../../../../common/log_analysis'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { defaultRequestParameters } from './common'; @@ -14,8 +15,6 @@ import { defaultRequestParameters } from './common'; export const createLogEntryExamplesQuery = ( indices: string, runtimeMappings: estypes.MappingRuntimeFields, - timestampField: string, - tiebreakerField: string, startTime: number, endTime: number, dataset: string, @@ -29,7 +28,7 @@ export const createLogEntryExamplesQuery = ( filter: [ { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: startTime, lte: endTime, }, @@ -72,7 +71,7 @@ export const createLogEntryExamplesQuery = ( }, }, runtime_mappings: runtimeMappings, - sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }], + sort: [{ [TIMESTAMP_FIELD]: 'asc' }, { [TIEBREAKER_FIELD]: 'asc' }], _source: false, fields: ['event.dataset', 'message'], }, diff --git a/x-pack/plugins/infra/server/lib/sources/defaults.ts b/x-pack/plugins/infra/server/lib/sources/defaults.ts index b6139613cfce3..db262a432b3fc 100644 --- a/x-pack/plugins/infra/server/lib/sources/defaults.ts +++ b/x-pack/plugins/infra/server/lib/sources/defaults.ts @@ -5,11 +5,7 @@ * 2.0. */ -import { - METRICS_INDEX_PATTERN, - LOGS_INDEX_PATTERN, - TIMESTAMP_FIELD, -} from '../../../common/constants'; +import { METRICS_INDEX_PATTERN, LOGS_INDEX_PATTERN } from '../../../common/constants'; import { InfraSourceConfiguration } from '../../../common/source_configuration/source_configuration'; export const defaultSourceConfiguration: InfraSourceConfiguration = { @@ -21,12 +17,7 @@ export const defaultSourceConfiguration: InfraSourceConfiguration = { indexName: LOGS_INDEX_PATTERN, }, fields: { - container: 'container.id', - host: 'host.name', message: ['message', '@message'], - pod: 'kubernetes.pod.uid', - tiebreaker: '_doc', - timestamp: TIMESTAMP_FIELD, }, inventoryDefaultView: '0', metricsExplorerDefaultView: '0', diff --git a/x-pack/plugins/infra/server/lib/sources/saved_object_references.test.ts b/x-pack/plugins/infra/server/lib/sources/saved_object_references.test.ts index 9f6f9cd284c67..fb550390e25be 100644 --- a/x-pack/plugins/infra/server/lib/sources/saved_object_references.test.ts +++ b/x-pack/plugins/infra/server/lib/sources/saved_object_references.test.ts @@ -101,12 +101,7 @@ const sourceConfigurationWithIndexPatternReference: InfraSourceConfiguration = { name: 'NAME', description: 'DESCRIPTION', fields: { - container: 'CONTAINER_FIELD', - host: 'HOST_FIELD', message: ['MESSAGE_FIELD'], - pod: 'POD_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', - timestamp: 'TIMESTAMP_FIELD', }, logColumns: [], logIndices: { diff --git a/x-pack/plugins/infra/server/plugin.ts b/x-pack/plugins/infra/server/plugin.ts index bf9c5a152058e..a6a2dab64e31c 100644 --- a/x-pack/plugins/infra/server/plugin.ts +++ b/x-pack/plugins/infra/server/plugin.ts @@ -55,12 +55,7 @@ export const config: PluginConfigDescriptor = { metricAlias: schema.maybe(schema.string()), fields: schema.maybe( schema.object({ - timestamp: schema.maybe(schema.string()), message: schema.maybe(schema.arrayOf(schema.string())), - tiebreaker: schema.maybe(schema.string()), - host: schema.maybe(schema.string()), - container: schema.maybe(schema.string()), - pod: schema.maybe(schema.string()), }) ), }) 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 index c721ca75ea978..5c4ae1981c5cd 100644 --- 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 @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { InventoryCloudAccount } from '../../../../common/http_api/inventory_meta_api'; import { InfraMetadataAggregationResponse, @@ -49,7 +50,7 @@ export const getCloudMetadata = async ( must: [ { range: { - [sourceConfiguration.fields.timestamp]: { + [TIMESTAMP_FIELD]: { gte: currentTime - 86400000, // 24 hours ago lte: currentTime, format: 'epoch_millis', diff --git a/x-pack/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 index d9da7bce2246f..126d1485cb702 100644 --- a/x-pack/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 @@ -13,6 +13,7 @@ import { import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framework_adapter'; import { InfraSourceConfiguration } from '../../../lib/sources'; import { CLOUD_METRICS_MODULES } from '../../../lib/constants'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; export interface InfraCloudMetricsAdapterResponse { buckets: InfraMetadataAggregationBucket[]; @@ -36,7 +37,7 @@ export const getCloudMetricsMetadata = async ( { match: { 'cloud.instance.id': instanceId } }, { range: { - [sourceConfiguration.fields.timestamp]: { + [TIMESTAMP_FIELD]: { gte: timeRange.from, lte: timeRange.to, format: 'epoch_millis', diff --git a/x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts index bfa0884bfe199..1962a24f7d4db 100644 --- a/x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts +++ b/x-pack/plugins/infra/server/routes/metadata/lib/get_metric_metadata.ts @@ -15,6 +15,7 @@ import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framewor import { InfraSourceConfiguration } from '../../../lib/sources'; import { findInventoryFields } from '../../../../common/inventory_models'; import { InventoryItemType } from '../../../../common/inventory_models/types'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; export interface InfraMetricsAdapterResponse { id: string; @@ -30,7 +31,7 @@ export const getMetricMetadata = async ( nodeType: InventoryItemType, timeRange: { from: number; to: number } ): Promise => { - const fields = findInventoryFields(nodeType, sourceConfiguration.fields); + const fields = findInventoryFields(nodeType); const metricQuery = { allow_no_indices: true, ignore_unavailable: true, @@ -45,7 +46,7 @@ export const getMetricMetadata = async ( }, { range: { - [sourceConfiguration.fields.timestamp]: { + [TIMESTAMP_FIELD]: { gte: timeRange.from, lte: timeRange.to, format: 'epoch_millis', diff --git a/x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts b/x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts index 06035ed40adf1..95609af166dab 100644 --- a/x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts +++ b/x-pack/plugins/infra/server/routes/metadata/lib/get_node_info.ts @@ -15,6 +15,7 @@ import { getPodNodeName } from './get_pod_node_name'; import { CLOUD_METRICS_MODULES } from '../../../lib/constants'; import { findInventoryFields } from '../../../../common/inventory_models'; import { InventoryItemType } from '../../../../common/inventory_models/types'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; export const getNodeInfo = async ( framework: KibanaFramework, @@ -50,8 +51,7 @@ export const getNodeInfo = async ( } return {}; } - const fields = findInventoryFields(nodeType, sourceConfiguration.fields); - const timestampField = sourceConfiguration.fields.timestamp; + const fields = findInventoryFields(nodeType); const params = { allow_no_indices: true, ignore_unavailable: true, @@ -60,14 +60,14 @@ export const getNodeInfo = async ( body: { size: 1, _source: ['host.*', 'cloud.*', 'agent.*'], - sort: [{ [timestampField]: 'desc' }], + sort: [{ [TIMESTAMP_FIELD]: 'desc' }], query: { bool: { filter: [ { match: { [fields.id]: nodeId } }, { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: timeRange.from, lte: timeRange.to, format: 'epoch_millis', diff --git a/x-pack/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 index 9bf809ba3b3f4..5c605a4c34b54 100644 --- a/x-pack/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 @@ -10,6 +10,7 @@ import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framewor import { InfraSourceConfiguration } from '../../../lib/sources'; import { findInventoryFields } from '../../../../common/inventory_models'; import type { InfraPluginRequestHandlerContext } from '../../../types'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; export const getPodNodeName = async ( framework: KibanaFramework, @@ -19,8 +20,7 @@ export const getPodNodeName = async ( nodeType: 'host' | 'pod' | 'container', timeRange: { from: number; to: number } ): Promise => { - const fields = findInventoryFields(nodeType, sourceConfiguration.fields); - const timestampField = sourceConfiguration.fields.timestamp; + const fields = findInventoryFields(nodeType); const params = { allow_no_indices: true, ignore_unavailable: true, @@ -29,7 +29,7 @@ export const getPodNodeName = async ( body: { size: 1, _source: ['kubernetes.node.name'], - sort: [{ [timestampField]: 'desc' }], + sort: [{ [TIMESTAMP_FIELD]: 'desc' }], query: { bool: { filter: [ @@ -37,7 +37,7 @@ export const getPodNodeName = async ( { exists: { field: `kubernetes.node.name` } }, { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: timeRange.from, lte: timeRange.to, format: 'epoch_millis', diff --git a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts index 9ca8c085eac44..62e99cf8ffd32 100644 --- a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts +++ b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts @@ -44,7 +44,6 @@ export const findIntervalForMetrics = async ( client, { indexPattern: options.indexPattern, - timestampField: options.timerange.field, timerange: options.timerange, }, modules.filter(Boolean) as string[] diff --git a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_dataset_for_field.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_dataset_for_field.ts index be25bbbf022ee..ba05e79db5832 100644 --- a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_dataset_for_field.ts +++ b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/get_dataset_for_field.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { ESSearchClient } from '../../../lib/metrics/types'; interface EventDatasetHit { @@ -19,7 +20,7 @@ export const getDatasetForField = async ( client: ESSearchClient, field: string, indexPattern: string, - timerange: { field: string; to: number; from: number } + timerange: { to: number; from: number } ) => { const params = { allow_no_indices: true, @@ -33,7 +34,7 @@ export const getDatasetForField = async ( { exists: { field } }, { range: { - [timerange.field]: { + [TIMESTAMP_FIELD]: { gte: timerange.from, lte: timerange.to, format: 'epoch_millis', @@ -45,7 +46,7 @@ export const getDatasetForField = async ( }, size: 1, _source: ['event.dataset'], - sort: [{ [timerange.field]: { order: 'desc' } }], + sort: [{ [TIMESTAMP_FIELD]: { order: 'desc' } }], }, }; diff --git a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/query_total_groupings.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/query_total_groupings.ts index a2bf778d5016d..b2e22752609c1 100644 --- a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/query_total_groupings.ts +++ b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/query_total_groupings.ts @@ -6,6 +6,7 @@ */ import { isArray } from 'lodash'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { MetricsAPIRequest } from '../../../../common/http_api'; import { ESSearchClient } from '../../../lib/metrics/types'; @@ -26,7 +27,7 @@ export const queryTotalGroupings = async ( let filters: Array> = [ { range: { - [options.timerange.field]: { + [TIMESTAMP_FIELD]: { gte: options.timerange.from, lte: options.timerange.to, format: 'epoch_millis', diff --git a/x-pack/plugins/infra/server/routes/overview/lib/create_top_nodes_query.ts b/x-pack/plugins/infra/server/routes/overview/lib/create_top_nodes_query.ts index 7533f2801607c..ccead528749cd 100644 --- a/x-pack/plugins/infra/server/routes/overview/lib/create_top_nodes_query.ts +++ b/x-pack/plugins/infra/server/routes/overview/lib/create_top_nodes_query.ts @@ -7,6 +7,7 @@ import { MetricsSourceConfiguration } from '../../../../common/metrics_sources'; import { TopNodesRequest } from '../../../../common/http_api/overview_api'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; export const createTopNodesQuery = ( options: TopNodesRequest, @@ -22,7 +23,7 @@ export const createTopNodesQuery = ( filter: [ { range: { - [source.configuration.fields.timestamp]: { + [TIMESTAMP_FIELD]: { gte: options.timerange.from, lte: options.timerange.to, }, @@ -49,7 +50,7 @@ export const createTopNodesQuery = ( { field: 'host.name' }, { field: 'cloud.provider' }, ], - sort: { '@timestamp': 'desc' }, + sort: { [TIMESTAMP_FIELD]: 'desc' }, size: 1, }, }, diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/create_timerange_with_interval.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/create_timerange_with_interval.ts index 7473907b7410b..bf6e51b9fe94f 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/create_timerange_with_interval.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/create_timerange_with_interval.ts @@ -25,7 +25,6 @@ const createInterval = async (client: ESSearchClient, options: InfraSnapshotRequ client, { indexPattern: options.sourceConfiguration.metricAlias, - timestampField: options.sourceConfiguration.fields.timestamp, timerange: { from: timerange.from, to: timerange.to }, }, modules, @@ -81,7 +80,6 @@ const aggregationsToModules = async ( async (field) => await getDatasetForField(client, field as string, options.sourceConfiguration.metricAlias, { ...options.timerange, - field: options.sourceConfiguration.fields.timestamp, }) ) ); diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts index b4e6983a09900..db65cc75592e6 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts @@ -47,12 +47,7 @@ const source: InfraSource = { indexPatternId: 'kibana_index_pattern', }, fields: { - container: 'container.id', - host: 'host.name', message: ['message', '@message'], - pod: 'kubernetes.pod.uid', - tiebreaker: '_doc', - timestamp: '@timestamp', }, inventoryDefaultView: '0', metricsExplorerDefaultView: '0', diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts index 3901c8677ae9b..b7e389cae9126 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { findInventoryFields, findInventoryModel } from '../../../../common/inventory_models'; import { MetricsAPIRequest, SnapshotRequest } from '../../../../common/http_api'; import { ESSearchClient } from '../../../lib/metrics/types'; @@ -37,7 +38,6 @@ export const transformRequestToMetricsAPIRequest = async ({ const metricsApiRequest: MetricsAPIRequest = { indexPattern: sourceOverrides?.indexPattern ?? source.configuration.metricAlias, timerange: { - field: sourceOverrides?.timestamp ?? source.configuration.fields.timestamp, from: timeRangeWithIntervalApplied.from, to: timeRangeWithIntervalApplied.to, interval: timeRangeWithIntervalApplied.interval, @@ -69,10 +69,7 @@ export const transformRequestToMetricsAPIRequest = async ({ inventoryModel.nodeFilter?.forEach((f) => filters.push(f)); } - const inventoryFields = findInventoryFields( - snapshotRequest.nodeType, - source.configuration.fields - ); + const inventoryFields = findInventoryFields(snapshotRequest.nodeType); if (snapshotRequest.groupBy) { const groupBy = snapshotRequest.groupBy.map((g) => g.field).filter(Boolean) as string[]; metricsApiRequest.groupBy = [...groupBy, inventoryFields.id]; @@ -86,7 +83,7 @@ export const transformRequestToMetricsAPIRequest = async ({ size: 1, metrics: [{ field: inventoryFields.name }], sort: { - [source.configuration.fields.timestamp]: 'desc', + [TIMESTAMP_FIELD]: 'desc', }, }, }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts index 85a1b95cf70aa..401269bd5b2c5 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts @@ -289,12 +289,7 @@ const createSourceConfigurationMock = (): InfraSource => ({ }, ], fields: { - pod: 'POD_FIELD', - host: 'HOST_FIELD', - container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], - timestamp: 'TIMESTAMP_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts index 651758d9cd976..7ee1cc5d4ef9d 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts @@ -109,7 +109,7 @@ export const logEntriesSearchStrategyProvider = ({ forkJoin([resolvedSourceConfiguration$, messageFormattingRules$]).pipe( map( ([ - { indices, timestampField, tiebreakerField, columns, runtimeMappings }, + { indices, columns, runtimeMappings }, messageFormattingRules, ]): IEsSearchRequest => { return { @@ -120,8 +120,6 @@ export const logEntriesSearchStrategyProvider = ({ params.endTimestamp, pickRequestCursor(params), params.size + 1, - timestampField, - tiebreakerField, getRequiredFields(params.columns ?? columns, messageFormattingRules), runtimeMappings, params.query, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts index ec3d4aa52a6b5..7e0a971856c90 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts @@ -244,12 +244,7 @@ const createSourceConfigurationMock = (): InfraSource => ({ metricsExplorerDefaultView: 'DEFAULT_VIEW', logColumns: [], fields: { - pod: 'POD_FIELD', - host: 'HOST_FIELD', - container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], - timestamp: 'TIMESTAMP_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts index 1f0f13eeb6ca9..d2231ec7643e8 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts @@ -78,20 +78,9 @@ export const logEntrySearchStrategyProvider = ({ concatMap(({ params }) => resolvedSourceConfiguration$.pipe( map( - ({ - indices, - timestampField, - tiebreakerField, - runtimeMappings, - }): IEsSearchRequest => ({ + ({ indices, runtimeMappings }): IEsSearchRequest => ({ // @ts-expect-error `Field` is not assignable to `SearchRequest.docvalue_fields` - params: createGetLogEntryQuery( - indices, - params.logEntryId, - timestampField, - tiebreakerField, - runtimeMappings - ), + params: createGetLogEntryQuery(indices, params.logEntryId, runtimeMappings), }) ) ) diff --git a/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts b/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts index 9022195dce85d..dd62ac260da3a 100644 --- a/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts +++ b/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts @@ -7,6 +7,7 @@ import type { estypes } from '@elastic/elasticsearch'; import * as rt from 'io-ts'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { LogEntryAfterCursor, logEntryAfterCursorRT, @@ -26,8 +27,6 @@ export const createGetLogEntriesQuery = ( endTimestamp: number, cursor: LogEntryBeforeCursor | LogEntryAfterCursor | null | undefined, size: number, - timestampField: string, - tiebreakerField: string, fields: string[], runtimeMappings?: estypes.MappingRuntimeFields, query?: JsonObject, @@ -48,7 +47,7 @@ export const createGetLogEntriesQuery = ( filter: [ ...(query ? [query] : []), ...(highlightQuery ? [highlightQuery] : []), - ...createTimeRangeFilterClauses(startTimestamp, endTimestamp, timestampField), + ...createTimeRangeFilterClauses(startTimestamp, endTimestamp, TIMESTAMP_FIELD), ], }, }, @@ -56,7 +55,7 @@ export const createGetLogEntriesQuery = ( // @ts-expect-error @elastic/elasticsearch doesn't declare "runtime_mappings" property runtime_mappings: runtimeMappings, _source: false, - ...createSortClause(sortDirection, timestampField, tiebreakerField), + ...createSortClause(sortDirection, TIMESTAMP_FIELD, TIEBREAKER_FIELD), ...createSearchAfterClause(cursor), ...createHighlightClause(highlightQuery, fields), }, diff --git a/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts b/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts index 8da2f1d685db3..6d944d5c47cda 100644 --- a/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts +++ b/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts @@ -7,6 +7,7 @@ import type { estypes } from '@elastic/elasticsearch'; import * as rt from 'io-ts'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { jsonArrayRT } from '../../../../common/typed_json'; import { commonHitFieldsRT, @@ -16,8 +17,6 @@ import { export const createGetLogEntryQuery = ( logEntryIndex: string, logEntryId: string, - timestampField: string, - tiebreakerField: string, runtimeMappings?: estypes.MappingRuntimeFields ): estypes.AsyncSearchSubmitRequest => ({ index: logEntryIndex, @@ -34,7 +33,7 @@ export const createGetLogEntryQuery = ( fields: ['*'], // @ts-expect-error @elastic/elasticsearch doesn't declare "runtime_mappings" property runtime_mappings: runtimeMappings, - sort: [{ [timestampField]: 'desc' }, { [tiebreakerField]: 'desc' }], + sort: [{ [TIMESTAMP_FIELD]: 'desc' }, { [TIEBREAKER_FIELD]: 'desc' }], _source: false, }, }); diff --git a/x-pack/plugins/infra/server/utils/calculate_metric_interval.ts b/x-pack/plugins/infra/server/utils/calculate_metric_interval.ts index 3357b1a842183..cb754153c6615 100644 --- a/x-pack/plugins/infra/server/utils/calculate_metric_interval.ts +++ b/x-pack/plugins/infra/server/utils/calculate_metric_interval.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../common/constants'; import { findInventoryModel } from '../../common/inventory_models'; // import { KibanaFramework } from '../lib/adapters/framework/kibana_framework_adapter'; import { InventoryItemType } from '../../common/inventory_models/types'; @@ -12,7 +13,6 @@ import { ESSearchClient } from '../lib/metrics/types'; interface Options { indexPattern: string; - timestampField: string; timerange: { from: number; to: number; @@ -44,7 +44,7 @@ export const calculateMetricInterval = async ( filter: [ { range: { - [options.timestampField]: { + [TIMESTAMP_FIELD]: { gte: from, lte: options.timerange.to, format: 'epoch_millis', From 9f4847df3929953890df12f6b9e42aa21b7574f1 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 20 Oct 2021 18:02:19 -0500 Subject: [PATCH 02/21] Fix typecheck --- .../http_api/host_details/process_list.ts | 1 - .../host/metrics/tsvb/host_cpu_usage.ts | 6 +-- .../host/metrics/tsvb/host_docker_info.ts | 1 - .../host/metrics/tsvb/host_docker_overview.ts | 1 - .../metrics/tsvb/host_docker_top_5_by_cpu.ts | 1 - .../tsvb/host_docker_top_5_by_memory.ts | 1 - .../host/metrics/tsvb/host_filesystem.ts | 1 - .../host/metrics/tsvb/host_k8s_cpu_cap.ts | 6 +-- .../host/metrics/tsvb/host_k8s_disk_cap.ts | 1 - .../host/metrics/tsvb/host_k8s_memory_cap.ts | 1 - .../host/metrics/tsvb/host_k8s_overview.ts | 1 - .../host/metrics/tsvb/host_k8s_pod_cap.ts | 6 +-- .../host/metrics/tsvb/host_load.ts | 6 +-- .../host/metrics/tsvb/host_memory_usage.ts | 1 - .../host/metrics/tsvb/host_network_traffic.ts | 1 - .../host/metrics/tsvb/host_system_overview.ts | 1 - .../logs/log_source/log_source.mock.ts | 5 --- .../pages/link_to/redirect_to_node_logs.tsx | 7 +-- .../components/node_details/tabs/logs.tsx | 8 ++-- .../node_details/tabs/metrics/metrics.tsx | 2 +- .../node_details/tabs/processes/index.tsx | 10 ++--- .../hooks/use_process_list_row_chart.ts | 3 +- .../lib/create_uptime_link.test.ts | 7 --- .../metric_detail/lib/get_filtered_metrics.ts | 2 +- .../utils/logs_overview_fetches.test.ts | 1 - .../log_threshold_chart_preview.ts | 17 ++++---- .../log_threshold/log_threshold_executor.ts | 43 ++++++------------- .../lib/alerting/log_threshold/mocks/index.ts | 1 - .../metric_threshold/lib/metric_query.test.ts | 4 +- .../log_entries_domain/log_entries_domain.ts | 2 - .../queries/log_entry_datasets.ts | 4 +- .../lib/host_details/process_list_chart.ts | 7 +-- .../lib/metrics/lib/calculate_interval.ts | 1 - ...rt_histogram_buckets_to_timeseries.test.ts | 1 - .../lib/metrics/lib/create_aggregations.ts | 3 +- .../lib/create_metrics_aggregations.test.ts | 1 - .../log_analysis/validation/datasets.ts | 3 +- ...ert_request_to_metrics_api_options.test.ts | 2 - .../lib/apply_metadata_to_last_path.ts | 5 +-- .../log_queries/get_log_query_fields.ts | 2 - 40 files changed, 48 insertions(+), 129 deletions(-) diff --git a/x-pack/plugins/infra/common/http_api/host_details/process_list.ts b/x-pack/plugins/infra/common/http_api/host_details/process_list.ts index 79835a0a78f26..3764a50a0a01a 100644 --- a/x-pack/plugins/infra/common/http_api/host_details/process_list.ts +++ b/x-pack/plugins/infra/common/http_api/host_details/process_list.ts @@ -102,7 +102,6 @@ export type ProcessListAPIResponse = rt.TypeOf; export const ProcessListAPIChartRequestRT = rt.type({ hostTerm: rt.record(rt.string, rt.string), - timefield: rt.string, indexPattern: rt.string, to: rt.number, command: rt.string, 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 index 8fa74e17826b0..5c4fc8bc8c4cf 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostCpuUsage: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const hostCpuUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'hostCpuUsage', requires: ['system.cpu'], index_pattern: indexPattern, 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 index c3f6c83334486..67f0b95a98a72 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerInfo: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 8738bea2631b2..e4ebbf177d7c7 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerOverview: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 54066cdba26ef..52fc0e9bd07fb 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index ffbf509672768..4547cb3a68981 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 52db291e60f01..20e149a040407 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostFilesystem: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 84f9c77cffda1..2586adba21f66 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sCpuCap: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const hostK8sCpuCap: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'hostK8sCpuCap', map_field_to: 'kubernetes.node.name', requires: ['kubernetes.node'], 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 index 57b9ee724670e..a11267f7f4f02 100644 --- 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 @@ -8,7 +8,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sDiskCap: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 6d358927950f7..9c73a9696c5d5 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sMemoryCap: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 3668a1eb9ba57..ab0dbc453f251 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sOverview: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 557de523f7b15..fddc1ed1cdae3 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sPodCap: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const hostK8sPodCap: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'hostK8sPodCap', requires: ['kubernetes.node'], map_field_to: 'kubernetes.node.name', 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 index 36b97b91baec6..aa12bc79e78e7 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostLoad: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const hostLoad: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'hostLoad', requires: ['system.cpu'], index_pattern: indexPattern, 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 index 833a43af45946..25872e5761f84 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostMemoryUsage: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index fbaa48b493c64..509caed21f063 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostNetworkTraffic: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index b40a84d6d7835..102d069ce1075 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostSystemOverview: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ diff --git a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts index 6021c728d32af..204fae7dc0f2b 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts @@ -73,11 +73,6 @@ export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfi }, logColumns: [], fields: { - container: 'CONTAINER_FIELD', - host: 'HOST_FIELD', - pod: 'POD_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', - timestamp: 'TIMESTAMP_FIELD', message: ['MESSAGE_FIELD'], }, name: sourceId, diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx index bc8c5699229d8..a8d339cfe979a 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx @@ -34,12 +34,11 @@ export const RedirectToNodeLogs = ({ location, }: RedirectToNodeLogsType) => { const { services } = useKibanaContextForPlugin(); - const { isLoading, loadSource, sourceConfiguration } = useLogSource({ + const { isLoading, loadSource } = useLogSource({ fetch: services.http.fetch, sourceId, indexPatternsService: services.data.indexPatterns, }); - const fields = sourceConfiguration?.configuration.fields; useMount(() => { loadSource(); @@ -57,11 +56,9 @@ export const RedirectToNodeLogs = ({ })} /> ); - } else if (fields == null) { - return null; } - const nodeFilter = `${findInventoryFields(nodeType, fields).id}: ${nodeId}`; + const nodeFilter = `${findInventoryFields(nodeType).id}: ${nodeId}`; const userFilter = getFilterFromLocation(location); const filter = userFilter ? `(${nodeFilter}) and (${userFilter})` : nodeFilter; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/logs.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/logs.tsx index b792078c394e9..8b5224068589c 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/logs.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/logs.tsx @@ -25,15 +25,13 @@ const TabComponent = (props: TabProps) => { const endTimestamp = props.currentTime; const startTimestamp = endTimestamp - 60 * 60 * 1000; // 60 minutes const { nodeType } = useWaffleOptionsContext(); - const { options, node } = props; + const { node } = props; const throttledTextQuery = useThrottle(textQuery, textQueryThrottleInterval); const filter = useMemo(() => { const query = [ - ...(options.fields != null - ? [`${findInventoryFields(nodeType, options.fields).id}: "${node.id}"`] - : []), + `${findInventoryFields(nodeType).id}: "${node.id}"`, ...(throttledTextQuery !== '' ? [throttledTextQuery] : []), ].join(' and '); @@ -41,7 +39,7 @@ const TabComponent = (props: TabProps) => { language: 'kuery', query, }; - }, [options.fields, nodeType, node.id, throttledTextQuery]); + }, [nodeType, node.id, throttledTextQuery]); const onQueryChange = useCallback((e: React.ChangeEvent) => { setTextQuery(e.target.value); diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx index 15bebfd2086e3..7ff4720aec01e 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/metrics/metrics.tsx @@ -71,7 +71,7 @@ const TabComponent = (props: TabProps) => { ]); const { sourceId, createDerivedIndexPattern } = useSourceContext(); const { nodeType, accountId, region, customMetrics } = useWaffleOptionsContext(); - const { currentTime, options, node } = props; + const { currentTime, node } = props; const derivedIndexPattern = useMemo( () => createDerivedIndexPattern('metrics'), [createDerivedIndexPattern] diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx index 7cab8148bb797..2bed7681b8d56 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx @@ -17,6 +17,7 @@ import { EuiIconTip, Query, } from '@elastic/eui'; +import { getFieldByType } from '../../../../../../../../common/inventory_models'; import { useProcessList, SortBy, @@ -28,7 +29,7 @@ import { SummaryTable } from './summary_table'; import { ProcessesTable } from './processes_table'; import { parseSearchString } from './parse_search_string'; -const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { +const TabComponent = ({ currentTime, node, nodeType }: TabProps) => { const [searchBarState, setSearchBarState] = useState(Query.MATCH_ALL); const [searchFilter, setSearchFilter] = useState(''); const [sortBy, setSortBy] = useState({ @@ -37,12 +38,9 @@ const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { }); const hostTerm = useMemo(() => { - const field = - options.fields && Reflect.has(options.fields, nodeType) - ? Reflect.get(options.fields, nodeType) - : nodeType; + const field = getFieldByType(nodeType) ?? nodeType; return { [field]: node.name }; - }, [options, node, nodeType]); + }, [node, nodeType]); const { loading, diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts b/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts index 30d4e5960ba5e..0d718ffbe210c 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts @@ -25,14 +25,13 @@ export function useProcessListRowChart(command: string) { fold(throwErrors(createPlainError), identity) ); }; - const { hostTerm, timefield, indexPattern, to } = useProcessListContext(); + const { hostTerm, indexPattern, to } = useProcessListContext(); const { error, loading, response, makeRequest } = useHTTPRequest( '/api/metrics/process_list/chart', 'POST', JSON.stringify({ hostTerm, - timefield, indexPattern, to, command, diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.test.ts b/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.test.ts index dbe45a387891c..af93f6c0d62ce 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.test.ts +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/create_uptime_link.test.ts @@ -10,13 +10,6 @@ import { InfraWaffleMapOptions, InfraFormatterType } from '../../../../lib/lib'; import { SnapshotMetricType } from '../../../../../common/inventory_models/types'; const options: InfraWaffleMapOptions = { - fields: { - container: 'container.id', - pod: 'kubernetes.pod.uid', - host: 'host.name', - timestamp: '@timestanp', - tiebreaker: '@timestamp', - }, formatter: InfraFormatterType.percent, formatTemplate: '{{value}}', metric: { type: 'cpu' }, diff --git a/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts b/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts index 2339319926da8..956c85cf2e673 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts @@ -20,7 +20,7 @@ export const getFilteredMetrics = ( const metricModelCreator = metrics.tsvb[metric]; // We just need to get a dummy version of the model so we can filter // using the `requires` attribute. - const metricModel = metricModelCreator('@timestamp', 'test', '>=1m'); + const metricModel = metricModelCreator('test', '>=1m'); return metricMetadata.some((m) => m && metricModel.requires.includes(m)); }); }; diff --git a/x-pack/plugins/infra/public/utils/logs_overview_fetches.test.ts b/x-pack/plugins/infra/public/utils/logs_overview_fetches.test.ts index d0349ab20710f..8a1920f534cd6 100644 --- a/x-pack/plugins/infra/public/utils/logs_overview_fetches.test.ts +++ b/x-pack/plugins/infra/public/utils/logs_overview_fetches.test.ts @@ -150,7 +150,6 @@ describe('Logs UI Observability Homepage Functions', () => { type: 'index_pattern', indexPatternId: 'test-index-pattern', }, - fields: { timestamp: '@timestamp', tiebreaker: '_doc' }, }, }, } as GetLogSourceConfigurationSuccessResponsePayload); diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts index 7bf2cb5ea3394..52c7cc6223a25 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts @@ -13,6 +13,7 @@ import { Series, Point, } from '../../../../common/http_api/log_alerts'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { getGroupedESQuery, getUngroupedESQuery, @@ -37,7 +38,7 @@ export async function getChartPreviewData( alertParams: GetLogAlertsChartPreviewDataAlertParamsSubset, buckets: number ) { - const { indices, timestampField, runtimeMappings } = resolvedLogSourceConfiguration; + const { indices, runtimeMappings } = resolvedLogSourceConfiguration; const { groupBy, timeSize, timeUnit } = alertParams; const isGrouped = groupBy && groupBy.length > 0 ? true : false; @@ -47,11 +48,11 @@ export async function getChartPreviewData( timeSize: timeSize * buckets, }; - const { rangeFilter } = buildFiltersFromCriteria(expandedAlertParams, timestampField); + const { rangeFilter } = buildFiltersFromCriteria(expandedAlertParams); const query = isGrouped - ? getGroupedESQuery(expandedAlertParams, timestampField, indices, runtimeMappings) - : getUngroupedESQuery(expandedAlertParams, timestampField, indices, runtimeMappings); + ? getGroupedESQuery(expandedAlertParams, indices, runtimeMappings) + : getUngroupedESQuery(expandedAlertParams, indices, runtimeMappings); if (!query) { throw new Error('ES query could not be built from the provided alert params'); @@ -61,7 +62,6 @@ export async function getChartPreviewData( query, rangeFilter, `${timeSize}${timeUnit}`, - timestampField, isGrouped ); @@ -79,19 +79,18 @@ const addHistogramAggregationToQuery = ( query: any, rangeFilter: any, interval: string, - timestampField: string, isGrouped: boolean ) => { const histogramAggregation = { histogramBuckets: { date_histogram: { - field: timestampField, + field: TIMESTAMP_FIELD, fixed_interval: interval, // Utilise extended bounds to make sure we get a full set of buckets even if there are empty buckets // at the start and / or end of the range. extended_bounds: { - min: rangeFilter.range[timestampField].gte, - max: rangeFilter.range[timestampField].lte, + min: rangeFilter.range[TIMESTAMP_FIELD].gte, + max: rangeFilter.range[TIMESTAMP_FIELD].lte, }, }, }, diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index f99f7a96158c3..1fbb8fde90cfa 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -41,6 +41,7 @@ import { UngroupedSearchQueryResponse, UngroupedSearchQueryResponseRT, } from '../../../../common/alerting/logs/log_threshold/types'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { resolveLogSourceConfiguration } from '../../../../common/log_sources'; import { decodeOrThrow } from '../../../../common/runtime_types'; import { getIntervalInSeconds } from '../../../utils/get_interval_in_seconds'; @@ -107,7 +108,7 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => }); const sourceConfiguration = await sources.getSourceConfiguration(savedObjectsClient, 'default'); - const { indices, timestampField, runtimeMappings } = await resolveLogSourceConfiguration( + const { indices, runtimeMappings } = await resolveLogSourceConfiguration( sourceConfiguration.configuration, await libs.framework.getIndexPatternsService( savedObjectsClient, @@ -121,7 +122,6 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => if (!isRatioAlertParams(validatedParams)) { await executeAlert( validatedParams, - timestampField, indices, runtimeMappings, scopedClusterClient.asCurrentUser, @@ -130,7 +130,6 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => } else { await executeRatioAlert( validatedParams, - timestampField, indices, runtimeMappings, scopedClusterClient.asCurrentUser, @@ -144,13 +143,12 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => async function executeAlert( alertParams: CountAlertParams, - timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields, esClient: ElasticsearchClient, alertInstanceFactory: LogThresholdAlertInstanceFactory ) { - const query = getESQuery(alertParams, timestampField, indexPattern, runtimeMappings); + const query = getESQuery(alertParams, indexPattern, runtimeMappings); if (!query) { throw new Error('ES query could not be built from the provided alert params'); @@ -175,7 +173,6 @@ async function executeAlert( async function executeRatioAlert( alertParams: RatioAlertParams, - timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields, esClient: ElasticsearchClient, @@ -192,13 +189,8 @@ async function executeRatioAlert( criteria: getDenominator(alertParams.criteria), }; - const numeratorQuery = getESQuery(numeratorParams, timestampField, indexPattern, runtimeMappings); - const denominatorQuery = getESQuery( - denominatorParams, - timestampField, - indexPattern, - runtimeMappings - ); + const numeratorQuery = getESQuery(numeratorParams, indexPattern, runtimeMappings); + const denominatorQuery = getESQuery(denominatorParams, indexPattern, runtimeMappings); if (!numeratorQuery || !denominatorQuery) { throw new Error('ES query could not be built from the provided ratio alert params'); @@ -229,13 +221,12 @@ async function executeRatioAlert( const getESQuery = ( alertParams: Omit & { criteria: CountCriteria }, - timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields ) => { return hasGroupBy(alertParams) - ? getGroupedESQuery(alertParams, timestampField, indexPattern, runtimeMappings) - : getUngroupedESQuery(alertParams, timestampField, indexPattern, runtimeMappings); + ? getGroupedESQuery(alertParams, indexPattern, runtimeMappings) + : getUngroupedESQuery(alertParams, indexPattern, runtimeMappings); }; export const processUngroupedResults = ( @@ -457,8 +448,7 @@ export const updateAlertInstance: AlertInstanceUpdater = (alertInstance, state, }; export const buildFiltersFromCriteria = ( - params: Pick & { criteria: CountCriteria }, - timestampField: string + params: Pick & { criteria: CountCriteria } ) => { const { timeSize, timeUnit, criteria } = params; const interval = `${timeSize}${timeUnit}`; @@ -482,7 +472,7 @@ export const buildFiltersFromCriteria = ( const rangeFilter = { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: from, lte: to, format: 'epoch_millis', @@ -496,7 +486,7 @@ export const buildFiltersFromCriteria = ( // and match / not match the criteria. const groupedRangeFilter = { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: from - intervalAsMs, lte: to + intervalAsMs, format: 'epoch_millis', @@ -515,7 +505,6 @@ export const getGroupedESQuery = ( value?: AlertParams['count']['value']; }; }, - timestampField: string, index: string, runtimeMappings: estypes.MappingRuntimeFields ): estypes.SearchRequest | undefined => { @@ -536,10 +525,8 @@ export const getGroupedESQuery = ( return; } - const { rangeFilter, groupedRangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria( - params, - timestampField - ); + const { rangeFilter, groupedRangeFilter, mustFilters, mustNotFilters } = + buildFiltersFromCriteria(params); if (isOptimizableGroupedThreshold(comparator, value)) { const aggregations = { @@ -620,14 +607,10 @@ export const getGroupedESQuery = ( export const getUngroupedESQuery = ( params: Pick & { criteria: CountCriteria }, - timestampField: string, index: string, runtimeMappings: estypes.MappingRuntimeFields ): object => { - const { rangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria( - params, - timestampField - ); + const { rangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria(params); const body: estypes.SearchRequest['body'] = { // Ensure we accurately track the hit count for the ungrouped case, otherwise we can only ensure accuracy up to 10,000. diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts index 296a540b4a920..f02dac2139097 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts @@ -17,7 +17,6 @@ export const libsMock = { type: 'index_pattern', indexPatternId: 'some-id', }, - fields: { timestamp: '@timestamp' }, }, }); }, diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts index 2ba8365d6b4a9..463365b6449d0 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts @@ -17,7 +17,6 @@ describe("The Metric Threshold Alert's getElasticsearchMetricQuery", () => { timeSize: 1, } as MetricExpressionParams; - const timefield = '@timestamp'; const groupBy = 'host.doggoname'; const timeframe = { start: moment().subtract(5, 'minutes').valueOf(), @@ -25,7 +24,7 @@ describe("The Metric Threshold Alert's getElasticsearchMetricQuery", () => { }; describe('when passed no filterQuery', () => { - const searchBody = getElasticsearchMetricQuery(expressionParams, timefield, timeframe, groupBy); + const searchBody = getElasticsearchMetricQuery(expressionParams, timeframe, groupBy); test('includes a range filter', () => { expect( searchBody.query.bool.filter.find((filter) => filter.hasOwnProperty('range')) @@ -47,7 +46,6 @@ describe("The Metric Threshold Alert's getElasticsearchMetricQuery", () => { const searchBody = getElasticsearchMetricQuery( expressionParams, - timefield, timeframe, groupBy, filterQuery diff --git a/x-pack/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 index 16209e5e4b684..031ae93b10638 100644 --- a/x-pack/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 @@ -272,7 +272,6 @@ export class InfraLogEntriesDomain { public async getLogEntryDatasets( requestContext: InfraPluginRequestHandlerContext, - timestampField: string, indexName: string, startTime: number, endTime: number, @@ -287,7 +286,6 @@ export class InfraLogEntriesDomain { 'search', createLogEntryDatasetsQuery( indexName, - timestampField, startTime, endTime, runtimeMappings, diff --git a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts index 9eae8daa3e74f..cb92827b24401 100644 --- a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts +++ b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts @@ -8,11 +8,11 @@ import * as rt from 'io-ts'; import { estypes } from '@elastic/elasticsearch'; +import { TIMESTAMP_FIELD } from '../../../../../common/constants'; import { commonSearchSuccessResponseFieldsRT } from '../../../../utils/elasticsearch_runtime_types'; export const createLogEntryDatasetsQuery = ( indexName: string, - timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, @@ -26,7 +26,7 @@ export const createLogEntryDatasetsQuery = ( filter: [ { range: { - [timestampField]: { + [TIMESTAMP_FIELD]: { gte: startTime, lte: endTime, }, diff --git a/x-pack/plugins/infra/server/lib/host_details/process_list_chart.ts b/x-pack/plugins/infra/server/lib/host_details/process_list_chart.ts index 413a97cb7a058..7ff66a80e967b 100644 --- a/x-pack/plugins/infra/server/lib/host_details/process_list_chart.ts +++ b/x-pack/plugins/infra/server/lib/host_details/process_list_chart.ts @@ -6,6 +6,7 @@ */ import { first } from 'lodash'; +import { TIMESTAMP_FIELD } from '../../../common/constants'; import { ProcessListAPIChartRequest, ProcessListAPIChartQueryAggregation, @@ -17,7 +18,7 @@ import { CMDLINE_FIELD } from './common'; export const getProcessListChart = async ( search: ESSearchClient, - { hostTerm, timefield, indexPattern, to, command }: ProcessListAPIChartRequest + { hostTerm, indexPattern, to, command }: ProcessListAPIChartRequest ) => { const body = { size: 0, @@ -26,7 +27,7 @@ export const getProcessListChart = async ( filter: [ { range: { - [timefield]: { + [TIMESTAMP_FIELD]: { gte: to - 60 * 1000, // 1 minute lte: to, }, @@ -60,7 +61,7 @@ export const getProcessListChart = async ( aggs: { timeseries: { date_histogram: { - field: timefield, + field: TIMESTAMP_FIELD, fixed_interval: '1m', extended_bounds: { min: to - 60 * 15 * 1000, // 15 minutes, diff --git a/x-pack/plugins/infra/server/lib/metrics/lib/calculate_interval.ts b/x-pack/plugins/infra/server/lib/metrics/lib/calculate_interval.ts index f6bdfb2de0a29..ee309ad449b2d 100644 --- a/x-pack/plugins/infra/server/lib/metrics/lib/calculate_interval.ts +++ b/x-pack/plugins/infra/server/lib/metrics/lib/calculate_interval.ts @@ -21,7 +21,6 @@ export const calculatedInterval = async (search: ESSearchClient, options: Metric search, { indexPattern: options.indexPattern, - timestampField: options.timerange.field, timerange: { from: options.timerange.from, to: options.timerange.to }, }, options.modules diff --git a/x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.test.ts b/x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.test.ts index b49560f8c25f6..8fe22e6f81d71 100644 --- a/x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.test.ts +++ b/x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.test.ts @@ -13,7 +13,6 @@ const keys = ['example-0']; const options: MetricsAPIRequest = { timerange: { - field: '@timestamp', from: moment('2020-01-01T00:00:00Z').valueOf(), to: moment('2020-01-01T00:00:00Z').add(5, 'minute').valueOf(), interval: '1m', diff --git a/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.ts b/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.ts index 65cd4ebe2d501..769ccce409e65 100644 --- a/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.ts +++ b/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { MetricsAPIRequest } from '../../../../common/http_api/metrics_api'; import { calculateDateHistogramOffset } from './calculate_date_histogram_offset'; import { createMetricsAggregations } from './create_metrics_aggregations'; @@ -15,7 +16,7 @@ export const createAggregations = (options: MetricsAPIRequest) => { const histogramAggregation = { histogram: { date_histogram: { - field: options.timerange.field, + field: TIMESTAMP_FIELD, fixed_interval: intervalString, offset: options.alignDataToEnd ? calculateDateHistogramOffset(options.timerange) : '0s', extended_bounds: { diff --git a/x-pack/plugins/infra/server/lib/metrics/lib/create_metrics_aggregations.test.ts b/x-pack/plugins/infra/server/lib/metrics/lib/create_metrics_aggregations.test.ts index 27fe491d3964b..2e2d1736e5925 100644 --- a/x-pack/plugins/infra/server/lib/metrics/lib/create_metrics_aggregations.test.ts +++ b/x-pack/plugins/infra/server/lib/metrics/lib/create_metrics_aggregations.test.ts @@ -11,7 +11,6 @@ import { createMetricsAggregations } from './create_metrics_aggregations'; const options: MetricsAPIRequest = { timerange: { - field: '@timestamp', from: moment('2020-01-01T00:00:00Z').valueOf(), to: moment('2020-01-01T01:00:00Z').valueOf(), interval: '>=1m', diff --git a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts index ef789c1b41349..0912c3730e6b1 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts @@ -32,14 +32,13 @@ export const initValidateLogAnalysisDatasetsRoute = ({ framework.router.handleLegacyErrors(async (requestContext, request, response) => { try { const { - data: { indices, timestampField, startTime, endTime, runtimeMappings }, + data: { indices, startTime, endTime, runtimeMappings }, } = request.body; const datasets = await Promise.all( indices.map(async (indexName) => { const indexDatasets = await logEntries.getLogEntryDatasets( requestContext, - timestampField, indexName, startTime, endTime, diff --git a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/convert_request_to_metrics_api_options.test.ts b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/convert_request_to_metrics_api_options.test.ts index 539e9a1fee6ef..a6848e4f7a2dd 100644 --- a/x-pack/plugins/infra/server/routes/metrics_explorer/lib/convert_request_to_metrics_api_options.test.ts +++ b/x-pack/plugins/infra/server/routes/metrics_explorer/lib/convert_request_to_metrics_api_options.test.ts @@ -10,7 +10,6 @@ import { convertRequestToMetricsAPIOptions } from './convert_request_to_metrics_ const BASE_REQUEST: MetricsExplorerRequestBody = { timerange: { - field: '@timestamp', from: new Date('2020-01-01T00:00:00Z').getTime(), to: new Date('2020-01-01T01:00:00Z').getTime(), interval: '1m', @@ -22,7 +21,6 @@ const BASE_REQUEST: MetricsExplorerRequestBody = { const BASE_METRICS_UI_OPTIONS: MetricsAPIRequest = { timerange: { - field: '@timestamp', from: new Date('2020-01-01T00:00:00Z').getTime(), to: new Date('2020-01-01T01:00:00Z').getTime(), interval: '1m', diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts index 7de63ae59a329..2931555fc06b0 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/apply_metadata_to_last_path.ts @@ -42,10 +42,7 @@ export const applyMetadataToLastPath = ( if (firstMetaDoc && lastPath) { // We will need the inventory fields so we can use the field paths to get // the values from the metadata document - const inventoryFields = findInventoryFields( - snapshotRequest.nodeType, - source.configuration.fields - ); + const inventoryFields = findInventoryFields(snapshotRequest.nodeType); // Set the label as the name and fallback to the id OR path.value lastPath.label = (firstMetaDoc[inventoryFields.name] ?? lastPath.value) as string; // If the inventory fields contain an ip address, we need to try and set that diff --git a/x-pack/plugins/infra/server/services/log_queries/get_log_query_fields.ts b/x-pack/plugins/infra/server/services/log_queries/get_log_query_fields.ts index 55491db97dbd6..db1696854db83 100644 --- a/x-pack/plugins/infra/server/services/log_queries/get_log_query_fields.ts +++ b/x-pack/plugins/infra/server/services/log_queries/get_log_query_fields.ts @@ -12,7 +12,6 @@ import { KibanaFramework } from '../../lib/adapters/framework/kibana_framework_a export interface LogQueryFields { indexPattern: string; - timestamp: string; } export const createGetLogQueryFields = (sources: InfraSources, framework: KibanaFramework) => { @@ -29,7 +28,6 @@ export const createGetLogQueryFields = (sources: InfraSources, framework: Kibana return { indexPattern: resolvedLogSourceConfiguration.indices, - timestamp: resolvedLogSourceConfiguration.timestampField, }; }; }; From 00bdeaf8300b2c78098efd643e406ad44becde30 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Thu, 21 Oct 2021 11:04:16 -0500 Subject: [PATCH 03/21] Fix typecheck --- .../metrics/tsvb/container_cpu_kernel.ts | 1 - .../metrics/tsvb/container_cpu_usage.ts | 1 - .../metrics/tsvb/container_disk_io_bytes.ts | 1 - .../metrics/tsvb/container_diskio_ops.ts | 1 - .../metrics/tsvb/container_memory.ts | 1 - .../metrics/tsvb/container_network_traffic.ts | 1 - .../metrics/tsvb/container_overview.ts | 1 - .../pod/metrics/tsvb/pod_cpu_usage.ts | 6 +---- .../pod/metrics/tsvb/pod_log_usage.ts | 6 +---- .../pod/metrics/tsvb/pod_memory_usage.ts | 1 - .../pod/metrics/tsvb/pod_network_traffic.ts | 1 - .../pod/metrics/tsvb/pod_overview.ts | 6 +---- .../metrics/tsvb/aws_cpu_utilization.ts | 5 +--- .../shared/metrics/tsvb/aws_diskio_bytes.ts | 5 +--- .../shared/metrics/tsvb/aws_network_bytes.ts | 5 +--- .../metrics/tsvb/aws_network_packets.ts | 5 +--- .../metrics/tsvb/nginx_active_connections.ts | 1 - .../shared/metrics/tsvb/nginx_hits.ts | 6 +---- .../shared/metrics/tsvb/nginx_request_rate.ts | 1 - .../tsvb/nginx_requests_per_connection.ts | 1 - .../log_threshold_executor.test.ts | 27 +++++-------------- .../plugins/infra/server/lib/metrics/index.ts | 3 ++- .../metrics/lib/create_aggregations.test.ts | 1 - .../server/routes/snapshot/lib/get_nodes.ts | 1 - 24 files changed, 16 insertions(+), 72 deletions(-) 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 index c30c98585bfe8..5a4a02d296598 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuKernel: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 0e4bbfa51ac33..20718b4436f0c 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuUsage: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 9ae3daa1bac99..8d895a5b2db26 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOBytes: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index cd71d5878451a..9603157594833 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOOps: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 5d00a2517ce61..52d6a2bf7d587 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerMemory: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index fa52a955c7765..a5054a1c88570 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerNetworkTraffic: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index cda78201d9104..a9c2cae3a7cd8 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerOverview: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index b038d80d6afe1..07adfc667c925 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podCpuUsage: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const podCpuUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'podCpuUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, 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 index 26b06e1fd555a..b659d19712db5 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podLogUsage: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const podLogUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'podLogUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, 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 index b882cb7c6b18f..ff4af90b1494e 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podMemoryUsage: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 6f964c6411d7c..898918d37f980 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podNetworkTraffic: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index b97f0389dd00c..2b035144b9d16 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podOverview: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const podOverview: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'podOverview', requires: ['kubernetes.pod'], index_pattern: indexPattern, 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 index a37d82f20231f..a407c0c27256c 100644 --- 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 @@ -8,10 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsCpuUtilization: TSVBMetricModelCreator = ( - timeField, - indexPattern -): TSVBMetricModel => ({ +export const awsCpuUtilization: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsCpuUtilization', requires: ['aws.ec2'], map_field_to: 'cloud.instance.id', 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 index 6704e4895108c..08ba43e5dac1e 100644 --- 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 @@ -8,10 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsDiskioBytes: TSVBMetricModelCreator = ( - timeField, - indexPattern -): TSVBMetricModel => ({ +export const awsDiskioBytes: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsDiskioBytes', requires: ['aws.ec2'], index_pattern: indexPattern, 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 index 9c31897718f5b..2aadca4909c3c 100644 --- 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 @@ -10,10 +10,7 @@ import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; // see discussion in: https://github.com/elastic/kibana/issues/42687 -export const awsNetworkBytes: TSVBMetricModelCreator = ( - timeField, - indexPattern -): TSVBMetricModel => ({ +export const awsNetworkBytes: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsNetworkBytes', requires: ['aws.ec2'], index_pattern: indexPattern, 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 index dd34d4a6b710a..9cb94ee889df1 100644 --- 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 @@ -8,10 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsNetworkPackets: TSVBMetricModelCreator = ( - timeField, - indexPattern -): TSVBMetricModel => ({ +export const awsNetworkPackets: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsNetworkPackets', requires: ['aws.ec2'], index_pattern: indexPattern, 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 index 06b93bdbc1022..32f612d79aaf4 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxActiveConnections: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index 89a1de03724d8..883f13ba3cced 100644 --- 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 @@ -8,11 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const nginxHits: TSVBMetricModelCreator = ( - timeField, - indexPattern, - interval -): TSVBMetricModel => ({ +export const nginxHits: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ id: 'nginxHits', requires: ['nginx.access'], index_pattern: indexPattern, 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 index 3cf34a67ca797..660c201cdd411 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestRate: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ 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 index dcfb17a097e82..249b0dbd3ac5e 100644 --- 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 @@ -9,7 +9,6 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( - timeField, indexPattern, interval ): TSVBMetricModel => ({ diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts index 1f0521070a1e5..fae99b2395fde 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts @@ -169,7 +169,7 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: positiveCriteria, }; - const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); + const filters = buildFiltersFromCriteria(alertParams); expect(filters.mustFilters).toEqual(expectedPositiveFilterClauses); }); @@ -178,14 +178,14 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: negativeCriteria, }; - const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); + const filters = buildFiltersFromCriteria(alertParams); expect(filters.mustNotFilters).toEqual(expectedNegativeFilterClauses); }); test('Handles time range', () => { const alertParams: AlertParams = { ...baseAlertParams, criteria: [] }; - const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); + const filters = buildFiltersFromCriteria(alertParams); expect(typeof filters.rangeFilter.range[TIMESTAMP_FIELD].gte).toBe('number'); expect(typeof filters.rangeFilter.range[TIMESTAMP_FIELD].lte).toBe('number'); expect(filters.rangeFilter.range[TIMESTAMP_FIELD].format).toBe('epoch_millis'); @@ -203,12 +203,7 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getUngroupedESQuery( - alertParams, - TIMESTAMP_FIELD, - FILEBEAT_INDEX, - runtimeMappings - ); + const query = getUngroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); expect(query).toEqual({ index: 'filebeat-*', allow_no_indices: true, @@ -253,12 +248,7 @@ describe('Log threshold executor', () => { groupBy: ['host.name'], criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getGroupedESQuery( - alertParams, - TIMESTAMP_FIELD, - FILEBEAT_INDEX, - runtimeMappings - ); + const query = getGroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); expect(query).toEqual({ index: 'filebeat-*', @@ -323,12 +313,7 @@ describe('Log threshold executor', () => { criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getGroupedESQuery( - alertParams, - TIMESTAMP_FIELD, - FILEBEAT_INDEX, - runtimeMappings - ); + const query = getGroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); expect(query).toEqual({ index: 'filebeat-*', diff --git a/x-pack/plugins/infra/server/lib/metrics/index.ts b/x-pack/plugins/infra/server/lib/metrics/index.ts index d291dbf88b49a..c4641e265ea55 100644 --- a/x-pack/plugins/infra/server/lib/metrics/index.ts +++ b/x-pack/plugins/infra/server/lib/metrics/index.ts @@ -7,6 +7,7 @@ import { set } from '@elastic/safer-lodash-set'; import { ThrowReporter } from 'io-ts/lib/ThrowReporter'; +import { TIMESTAMP_FIELD } from '../../../common/constants'; import { MetricsAPIRequest, MetricsAPIResponse, afterKeyObjectRT } from '../../../common/http_api'; import { ESSearchClient, @@ -36,7 +37,7 @@ export const query = async ( const filter: Array> = [ { range: { - [options.timerange.field]: { + [TIMESTAMP_FIELD]: { gte: options.timerange.from, lte: options.timerange.to, format: 'epoch_millis', diff --git a/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.test.ts b/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.test.ts index 91bf544b7e48f..9b92793129d44 100644 --- a/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.test.ts +++ b/x-pack/plugins/infra/server/lib/metrics/lib/create_aggregations.test.ts @@ -11,7 +11,6 @@ import { MetricsAPIRequest } from '../../../../common/http_api'; const options: MetricsAPIRequest = { timerange: { - field: '@timestamp', from: moment('2020-01-01T00:00:00Z').valueOf(), to: moment('2020-01-01T01:00:00Z').valueOf(), interval: '>=1m', diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts index f59756e0c5b25..a3ca2cfd683bb 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/get_nodes.ts @@ -16,7 +16,6 @@ import { LogQueryFields } from '../../../services/log_queries/get_log_query_fiel export interface SourceOverrides { indexPattern: string; - timestamp: string; } const transformAndQueryData = async ({ From ae369416a23c0e86c6d324912f0ee3f15adc2911 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Thu, 21 Oct 2021 11:54:07 -0500 Subject: [PATCH 04/21] Fix typecheck --- .../apis/metrics_ui/log_sources.ts | 18 --------- .../apis/metrics_ui/metric_threshold_alert.ts | 5 --- .../apis/metrics_ui/metrics_alerting.ts | 9 +---- .../apis/metrics_ui/sources.ts | 39 ------------------- 4 files changed, 1 insertion(+), 70 deletions(-) diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts index 5b615c4b18916..516c262429299 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts @@ -40,8 +40,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); expect(configuration.logColumns[2]).to.have.key('messageColumn'); @@ -58,10 +56,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, - fields: { - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, logColumns: [ { messageColumn: { @@ -83,8 +77,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); - expect(configuration.fields.timestamp).to.be('TIMESTAMP'); - expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); @@ -111,8 +103,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); @@ -142,10 +132,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, - fields: { - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, logColumns: [ { messageColumn: { @@ -166,8 +152,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); - expect(configuration.fields.timestamp).to.be('TIMESTAMP'); - expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); }); @@ -189,8 +173,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); diff --git a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts b/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts index 66c40e2e6e92d..f2e632e59a02b 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts @@ -53,11 +53,6 @@ export default function ({ getService }: FtrProviderContext) { metricsExplorerDefaultView: 'default', anomalyThreshold: 70, fields: { - container: 'container.id', - host: 'host.name', - pod: 'kubernetes.od.uid', - tiebreaker: '_doc', - timestamp: '@timestamp', message: ['message'], }, logColumns: [ diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts b/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts index 90b815d4d0530..7816e9d494e6b 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts @@ -37,11 +37,7 @@ export default function ({ getService }: FtrProviderContext) { start: moment().subtract(25, 'minutes').valueOf(), end: moment().valueOf(), }; - const searchBody = getElasticsearchMetricQuery( - getSearchParams(aggType), - '@timestamp', - timeframe - ); + const searchBody = getElasticsearchMetricQuery(getSearchParams(aggType), timeframe); const { body: result } = await client.search({ index, body: searchBody, @@ -60,7 +56,6 @@ export default function ({ getService }: FtrProviderContext) { }; const searchBody = getElasticsearchMetricQuery( getSearchParams('avg'), - '@timestamp', timeframe, undefined, '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' @@ -83,7 +78,6 @@ export default function ({ getService }: FtrProviderContext) { }; const searchBody = getElasticsearchMetricQuery( getSearchParams(aggType), - '@timestamp', timeframe, 'agent.id' ); @@ -103,7 +97,6 @@ export default function ({ getService }: FtrProviderContext) { }; const searchBody = getElasticsearchMetricQuery( getSearchParams('avg'), - '@timestamp', timeframe, 'agent.id', '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' diff --git a/x-pack/test/api_integration/apis/metrics_ui/sources.ts b/x-pack/test/api_integration/apis/metrics_ui/sources.ts index 8c43a05f5eeb6..e9ea8f725073f 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/sources.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/sources.ts @@ -66,11 +66,6 @@ export default function ({ getService }: FtrProviderContext) { expect(configuration?.name).to.be('UPDATED_NAME'); expect(configuration?.description).to.be('UPDATED_DESCRIPTION'); expect(configuration?.metricAlias).to.be('metricbeat-**'); - expect(configuration?.fields.host).to.be('host.name'); - expect(configuration?.fields.pod).to.be('kubernetes.pod.uid'); - expect(configuration?.fields.tiebreaker).to.be('_doc'); - expect(configuration?.fields.timestamp).to.be('@timestamp'); - expect(configuration?.fields.container).to.be('container.id'); expect(configuration?.anomalyThreshold).to.be(50); expect(status?.metricIndicesExist).to.be(true); }); @@ -104,40 +99,6 @@ export default function ({ getService }: FtrProviderContext) { expect(status?.metricIndicesExist).to.be(true); }); - it('applies a single nested field update to an existing source', async () => { - const creationResponse = await patchRequest({ - name: 'NAME', - fields: { - host: 'HOST', - }, - }); - - const initialVersion = creationResponse?.source.version; - const createdAt = creationResponse?.source.updatedAt; - - expect(initialVersion).to.be.a('string'); - expect(createdAt).to.be.greaterThan(0); - - const updateResponse = await patchRequest({ - fields: { - container: 'UPDATED_CONTAINER', - }, - }); - - const version = updateResponse?.source.version; - const updatedAt = updateResponse?.source.updatedAt; - const configuration = updateResponse?.source.configuration; - - expect(version).to.be.a('string'); - expect(version).to.not.be(initialVersion); - expect(updatedAt).to.be.greaterThan(createdAt || 0); - expect(configuration?.fields.container).to.be('UPDATED_CONTAINER'); - expect(configuration?.fields.host).to.be('HOST'); - expect(configuration?.fields.pod).to.be('kubernetes.pod.uid'); - expect(configuration?.fields.tiebreaker).to.be('_doc'); - expect(configuration?.fields.timestamp).to.be('@timestamp'); - }); - it('validates anomalyThreshold is between range 1-100', async () => { // create config with bad request await supertest From 0a2c206fbd7cf53a4bd50738d861e17e79ec112a Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Thu, 21 Oct 2021 16:27:48 -0500 Subject: [PATCH 05/21] Fix jest --- .../pages/link_to/link_to_logs.test.tsx | 14 +++---- .../helpers/create_tsvb_link.test.ts | 6 +-- .../infra/server/lib/sources/sources.test.ts | 40 +------------------ ...orm_request_to_metrics_api_request.test.ts | 2 +- 4 files changed, 12 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx index f9c80edd2c199..cfcf8db771b78 100644 --- a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx @@ -151,7 +151,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'HOST_FIELD: HOST_NAME')"` + `"(language:kuery,query:'host.name: HOST_NAME')"` ); expect(searchParams.get('logPosition')).toEqual(null); }); @@ -172,7 +172,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'(HOST_FIELD: HOST_NAME) and (FILTER_FIELD:FILTER_VALUE)')"` + `"(language:kuery,query:'(host.name: HOST_NAME) and (FILTER_FIELD:FILTER_VALUE)')"` ); expect(searchParams.get('logPosition')).toMatchInlineSnapshot( `"(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)"` @@ -193,7 +193,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('OTHER_SOURCE'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'HOST_FIELD: HOST_NAME')"` + `"(language:kuery,query:'host.name: HOST_NAME')"` ); expect(searchParams.get('logPosition')).toEqual(null); }); @@ -229,7 +229,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'CONTAINER_FIELD: CONTAINER_ID')"` + `"(language:kuery,query:'container.id: CONTAINER_ID')"` ); expect(searchParams.get('logPosition')).toEqual(null); }); @@ -250,7 +250,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'(CONTAINER_FIELD: CONTAINER_ID) and (FILTER_FIELD:FILTER_VALUE)')"` + `"(language:kuery,query:'(container.id: CONTAINER_ID) and (FILTER_FIELD:FILTER_VALUE)')"` ); expect(searchParams.get('logPosition')).toMatchInlineSnapshot( `"(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)"` @@ -287,7 +287,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'POD_FIELD: POD_UID')"` + `"(language:kuery,query:'kubernetes.pod.uid: POD_UID')"` ); expect(searchParams.get('logPosition')).toEqual(null); }); @@ -306,7 +306,7 @@ describe('LinkToLogsPage component', () => { const searchParams = new URLSearchParams(history.location.search); expect(searchParams.get('sourceId')).toEqual('default'); expect(searchParams.get('logFilter')).toMatchInlineSnapshot( - `"(language:kuery,query:'(POD_FIELD: POD_UID) and (FILTER_FIELD:FILTER_VALUE)')"` + `"(language:kuery,query:'(kubernetes.pod.uid: POD_UID) and (FILTER_FIELD:FILTER_VALUE)')"` ); expect(searchParams.get('logPosition')).toMatchInlineSnapshot( `"(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)"` diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.test.ts b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.test.ts index a9e65bc30a3c6..472e86200cba3 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.test.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.test.ts @@ -79,7 +79,7 @@ describe('createTSVBLink()', () => { app: 'visualize', hash: '/create', search: { - _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'my-beats-*',filter:(language:kuery,query:'host.name : \"example-01\"'),id:test-id,index_pattern:'my-beats-*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:time,type:timeseries),title:example-01,type:metrics))", + _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'my-beats-*',filter:(language:kuery,query:'host.name : \"example-01\"'),id:test-id,index_pattern:'my-beats-*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:'@timestamp',type:timeseries),title:example-01,type:metrics))", _g: '(refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))', type: 'metrics', }, @@ -97,7 +97,7 @@ describe('createTSVBLink()', () => { app: 'visualize', hash: '/create', search: { - _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'my-beats-*',filter:(language:kuery,query:'system.network.name:lo* and host.name : \"example-01\"'),id:test-id,index_pattern:'my-beats-*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:time,type:timeseries),title:example-01,type:metrics))", + _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'my-beats-*',filter:(language:kuery,query:'system.network.name:lo* and host.name : \"example-01\"'),id:test-id,index_pattern:'my-beats-*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:'@timestamp',type:timeseries),title:example-01,type:metrics))", _g: '(refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))', type: 'metrics', }, @@ -161,7 +161,7 @@ describe('createTSVBLink()', () => { app: 'visualize', hash: '/create', search: { - _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'metric*',filter:(language:kuery,query:'host.name : \"example-01\"'),id:test-id,index_pattern:'metric*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:time,type:timeseries),title:example-01,type:metrics))", + _a: "(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'metric*',filter:(language:kuery,query:'host.name : \"example-01\"'),id:test-id,index_pattern:'metric*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:'@timestamp',type:timeseries),title:example-01,type:metrics))", _g: '(refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))', type: 'metrics', }, diff --git a/x-pack/plugins/infra/server/lib/sources/sources.test.ts b/x-pack/plugins/infra/server/lib/sources/sources.test.ts index 904f51d12673f..396d2c22a100f 100644 --- a/x-pack/plugins/infra/server/lib/sources/sources.test.ts +++ b/x-pack/plugins/infra/server/lib/sources/sources.test.ts @@ -24,13 +24,6 @@ describe('the InfraSources lib', () => { attributes: { metricAlias: 'METRIC_ALIAS', logIndices: { type: 'index_pattern', indexPatternId: 'log_index_pattern_0' }, - fields: { - container: 'CONTAINER', - host: 'HOST', - pod: 'POD', - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, }, references: [ { @@ -50,13 +43,6 @@ describe('the InfraSources lib', () => { configuration: { metricAlias: 'METRIC_ALIAS', logIndices: { type: 'index_pattern', indexPatternId: 'LOG_INDEX_PATTERN' }, - fields: { - container: 'CONTAINER', - host: 'HOST', - pod: 'POD', - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, }, }); }); @@ -67,12 +53,6 @@ describe('the InfraSources lib', () => { default: { metricAlias: 'METRIC_ALIAS', logIndices: { type: 'index_pattern', indexPatternId: 'LOG_ALIAS' }, - fields: { - host: 'HOST', - pod: 'POD', - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, }, }), }); @@ -82,11 +62,7 @@ describe('the InfraSources lib', () => { version: 'foo', type: infraSourceConfigurationSavedObjectName, updated_at: '2000-01-01T00:00:00.000Z', - attributes: { - fields: { - container: 'CONTAINER', - }, - }, + attributes: {}, references: [], }); @@ -99,13 +75,6 @@ describe('the InfraSources lib', () => { configuration: { metricAlias: 'METRIC_ALIAS', logIndices: { type: 'index_pattern', indexPatternId: 'LOG_ALIAS' }, - fields: { - container: 'CONTAINER', - host: 'HOST', - pod: 'POD', - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, }, }); }); @@ -133,13 +102,6 @@ describe('the InfraSources lib', () => { configuration: { metricAlias: expect.any(String), logIndices: expect.any(Object), - fields: { - container: expect.any(String), - host: expect.any(String), - pod: expect.any(String), - tiebreaker: expect.any(String), - timestamp: expect.any(String), - }, }, }); }); diff --git a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts index db65cc75592e6..aac5f9e145022 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/lib/transform_request_to_metrics_api_request.test.ts @@ -75,7 +75,7 @@ const snapshotRequest: SnapshotRequest = { const metricsApiRequest = { indexPattern: 'metrics-*,metricbeat-*', - timerange: { field: '@timestamp', from: 1605705900000, to: 1605706200000, interval: '60s' }, + timerange: { from: 1605705900000, to: 1605706200000, interval: '60s' }, metrics: [ { id: 'cpu', From c0f907f0a136706d531a89dc849dbf48e2efd7a2 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Thu, 21 Oct 2021 16:30:10 -0500 Subject: [PATCH 06/21] Fix functional test --- x-pack/test/api_integration/apis/metrics_ui/http_source.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/x-pack/test/api_integration/apis/metrics_ui/http_source.ts b/x-pack/test/api_integration/apis/metrics_ui/http_source.ts index 65a350c523ee3..f0eba78f90a02 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/http_source.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/http_source.ts @@ -42,13 +42,6 @@ export default function ({ getService }: FtrProviderContext) { return resp.then((data) => { expect(data).to.have.property('source'); expect(data?.source.configuration.metricAlias).to.equal('metrics-*,metricbeat-*'); - expect(data?.source.configuration.fields).to.eql({ - container: 'container.id', - host: 'host.name', - pod: 'kubernetes.pod.uid', - tiebreaker: '_doc', - timestamp: '@timestamp', - }); expect(data?.source).to.have.property('status'); expect(data?.source.status?.metricIndicesExist).to.equal(true); }); From 015793ca8b646427a454cd1647d71e6f6e117100 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 26 Oct 2021 16:12:45 -0500 Subject: [PATCH 07/21] Remove extraneous timeField args --- .../inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts | 2 +- .../common/inventory_models/shared/metrics/tsvb/aws_overview.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index cb4dd3ad4e8b8..3efebb8694fe8 100644 --- 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 @@ -8,7 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsDiskioOps: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ +export const awsDiskioOps: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsDiskioOps', requires: ['aws.ec2'], index_pattern: indexPattern, 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 index 16df717f400be..fdea10d6c472c 100644 --- 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 @@ -8,7 +8,7 @@ import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsOverview: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ +export const awsOverview: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ id: 'awsOverview', requires: ['aws.ec2'], index_pattern: indexPattern, From 7a6554553ad44d6fb67ab0e6fd87c2e193fd6939 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 26 Oct 2021 16:39:52 -0500 Subject: [PATCH 08/21] Typecheck fix --- .../server/services/log_entries/log_entry_search_strategy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts index d2231ec7643e8..4ee9db404ad9d 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts @@ -79,7 +79,6 @@ export const logEntrySearchStrategyProvider = ({ resolvedSourceConfiguration$.pipe( map( ({ indices, runtimeMappings }): IEsSearchRequest => ({ - // @ts-expect-error `Field` is not assignable to `SearchRequest.docvalue_fields` params: createGetLogEntryQuery(indices, params.logEntryId, runtimeMappings), }) ) From 2c8addfa09f268b4b66609ebe0fff4607530bad0 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:03:58 -0500 Subject: [PATCH 09/21] Consolidate log file changes to ResolvedLogSourceConfiguration --- .../common/log_analysis/job_parameters.ts | 1 + .../resolved_log_source_configuration.ts | 7 +++++++ .../logs/log_analysis/api/validate_datasets.ts | 6 ++++-- .../logs/log_analysis/api/validate_indices.ts | 2 +- .../logs/log_analysis/log_analysis_module.tsx | 5 +++-- .../log_analysis_module_configuration.ts | 1 + .../log_analysis/log_analysis_module_types.ts | 5 ++++- .../log_analysis/log_analysis_setup_state.ts | 6 ++++-- .../log_entry_categories/module_descriptor.ts | 18 +++++++++++------- .../use_log_entry_categories_module.tsx | 7 +++++-- .../log_entry_rate/module_descriptor.ts | 18 +++++++++++------- .../use_log_entry_rate_module.tsx | 7 +++++-- 12 files changed, 57 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/infra/common/log_analysis/job_parameters.ts b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts index 6e964e3a94f65..b8fa429195ff3 100644 --- a/x-pack/plugins/infra/common/log_analysis/job_parameters.ts +++ b/x-pack/plugins/infra/common/log_analysis/job_parameters.ts @@ -36,6 +36,7 @@ export type DatasetFilter = rt.TypeOf; export const jobSourceConfigurationRT = rt.partial({ indexPattern: rt.string, + timestampField: rt.string, bucketSpan: rt.number, datasetFilter: datasetFilterRT, }); diff --git a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts index d05cddf4b78b8..ece3baf4977d6 100644 --- a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts +++ b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts @@ -8,6 +8,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { DataView, DataViewsContract } from '../../../../../src/plugins/data_views/common'; import { ObjectEntries } from '../utility_types'; +import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../constants'; import { ResolveLogSourceConfigurationError } from './errors'; import { LogSourceColumnConfiguration, @@ -18,6 +19,8 @@ export interface ResolvedLogSourceConfiguration { name: string; description: string; indices: string; + timestampField: string; + tiebreakerField: string; messageField: string[]; fields: DataView['fields']; runtimeMappings: estypes.MappingRuntimeFields; @@ -59,6 +62,8 @@ const resolveLegacyReference = async ( return { indices: sourceConfiguration.logIndices.indexName, + timestampField: TIMESTAMP_FIELD, + tiebreakerField: TIEBREAKER_FIELD, messageField: sourceConfiguration.fields.message, fields, runtimeMappings: {}, @@ -87,6 +92,8 @@ const resolveKibanaIndexPatternReference = async ( return { indices: indexPattern.title, + timestampField: TIMESTAMP_FIELD, + tiebreakerField: TIEBREAKER_FIELD, messageField: ['message'], fields: indexPattern.fields, runtimeMappings: resolveRuntimeMappings(indexPattern), diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts index e6ddc792f3236..9de6e574ecb5b 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { estypes } from '@elastic/elasticsearch'; import type { HttpHandler } from 'src/core/public'; import { LOG_ANALYSIS_VALIDATE_DATASETS_PATH, @@ -16,13 +16,14 @@ import { decodeOrThrow } from '../../../../../common/runtime_types'; interface RequestArgs { indices: string[]; + timestampField: string; startTime: number; endTime: number; runtimeMappings: estypes.MappingRuntimeFields; } export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: HttpHandler) => { - const { indices, startTime, endTime, runtimeMappings } = requestArgs; + const { indices, timestampField, startTime, endTime, runtimeMappings } = requestArgs; const response = await fetch(LOG_ANALYSIS_VALIDATE_DATASETS_PATH, { method: 'POST', body: JSON.stringify( @@ -31,6 +32,7 @@ export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: H endTime, indices, startTime, + timestampField, runtimeMappings, }, }) diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts index 8a9f960b54afa..a211fecc807fa 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts @@ -6,7 +6,7 @@ */ import type { HttpHandler } from 'src/core/public'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { estypes } from '@elastic/elasticsearch'; import { LOG_ANALYSIS_VALIDATE_INDICES_PATH, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx index 15b7eea0487af..d844b7439710c 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx @@ -21,7 +21,7 @@ export const useLogAnalysisModule = ({ moduleDescriptor: ModuleDescriptor; }) => { const { services } = useKibanaContextForPlugin(); - const { spaceId, sourceId, runtimeMappings } = sourceConfiguration; + const { spaceId, sourceId, timestampField, runtimeMappings } = sourceConfiguration; const [moduleStatus, dispatchModuleStatus] = useModuleStatus(moduleDescriptor.jobTypes); const trackMetric = useUiTracker({ app: 'infra_logs' }); @@ -66,6 +66,7 @@ export const useLogAnalysisModule = ({ indices: selectedIndices, sourceId, spaceId, + timestampField, runtimeMappings, }, services.http.fetch @@ -113,7 +114,7 @@ export const useLogAnalysisModule = ({ } }, }, - [moduleDescriptor.setUpModule, spaceId, sourceId] + [moduleDescriptor.setUpModule, spaceId, sourceId, timestampField] ); const [cleanUpModuleRequest, cleanUpModule] = useTrackedPromise( diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts index b77e195cf050e..057580679210a 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_configuration.ts @@ -52,6 +52,7 @@ export const isJobConfigurationOutdated = new Set(jobConfiguration.indexPattern.split(',')), new Set(currentSourceConfiguration.indices) ) && + jobConfiguration.timestampField === currentSourceConfiguration.timestampField && equal(datafeedRuntimeMappings, currentSourceConfiguration.runtimeMappings) ); }; diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts index 544f5f223247d..4ae99b95cfff8 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts @@ -6,7 +6,7 @@ */ import type { HttpHandler } from 'src/core/public'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { estypes } from '@elastic/elasticsearch'; import { ValidateLogEntryDatasetsResponsePayload, ValidationIndicesResponsePayload, @@ -46,11 +46,13 @@ export interface ModuleDescriptor { ) => Promise; validateSetupIndices: ( indices: string[], + timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => Promise; validateSetupDatasets: ( indices: string[], + timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, @@ -62,5 +64,6 @@ export interface ModuleSourceConfiguration { indices: string[]; sourceId: string; spaceId: string; + timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; } diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts index 39bb9b2948590..fad6fd56f6251 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts @@ -161,6 +161,7 @@ export const useAnalysisSetupState = ({ createPromise: async () => { return await validateSetupIndices( sourceConfiguration.indices, + sourceConfiguration.timestampField, sourceConfiguration.runtimeMappings, services.http.fetch ); @@ -172,7 +173,7 @@ export const useAnalysisSetupState = ({ setValidatedIndices([]); }, }, - [sourceConfiguration.indices] + [sourceConfiguration.indices, sourceConfiguration.timestampField] ); const [validateDatasetsRequest, validateDatasets] = useTrackedPromise( @@ -185,6 +186,7 @@ export const useAnalysisSetupState = ({ return await validateSetupDatasets( validIndexNames, + sourceConfiguration.timestampField, startTime ?? 0, endTime ?? Date.now(), sourceConfiguration.runtimeMappings, @@ -195,7 +197,7 @@ export const useAnalysisSetupState = ({ updateIndicesWithAvailableDatasets(datasets); }, }, - [validIndexNames, startTime, endTime] + [validIndexNames, sourceConfiguration.timestampField, startTime, endTime] ); const setUp = useCallback(() => { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts index e58926440cc23..6823ed173a740 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts @@ -5,10 +5,9 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { estypes } from '@elastic/elasticsearch'; import { i18n } from '@kbn/i18n'; import type { HttpHandler } from 'src/core/public'; -import { TIMESTAMP_FIELD } from '../../../../../../common/constants'; import { bucketSpan, categoriesMessageField, @@ -64,7 +63,7 @@ const setUpModule = async ( start: number | undefined, end: number | undefined, datasetFilter: DatasetFilter, - { spaceId, sourceId, indices, runtimeMappings }: ModuleSourceConfiguration, + { spaceId, sourceId, indices, timestampField, runtimeMappings }: ModuleSourceConfiguration, fetch: HttpHandler ) => { const indexNamePattern = indices.join(','); @@ -75,12 +74,12 @@ const setUpModule = async ( bucket_span: `${bucketSpan}ms`, }, data_description: { - time_field: TIMESTAMP_FIELD, + time_field: timestampField, }, custom_settings: { logs_source_config: { indexPattern: indexNamePattern, - timestampField: TIMESTAMP_FIELD, + timestampField, bucketSpan, datasetFilter, }, @@ -137,6 +136,7 @@ const cleanUpModule = async (spaceId: string, sourceId: string, fetch: HttpHandl const validateSetupIndices = async ( indices: string[], + timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { @@ -145,7 +145,7 @@ const validateSetupIndices = async ( indices, fields: [ { - name: TIMESTAMP_FIELD, + name: timestampField, validTypes: ['date'], }, { @@ -165,12 +165,16 @@ const validateSetupIndices = async ( const validateSetupDatasets = async ( indices: string[], + timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { - return await callValidateDatasetsAPI({ indices, startTime, endTime, runtimeMappings }, fetch); + return await callValidateDatasetsAPI( + { indices, timestampField, startTime, endTime, runtimeMappings }, + fetch + ); }; export const logEntryCategoriesModule: ModuleDescriptor = { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx index 3fa36c2f60681..99d4ab4becee5 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx @@ -6,7 +6,7 @@ */ import createContainer from 'constate'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { estypes } from '@elastic/elasticsearch'; import { useMemo } from 'react'; import { useLogAnalysisModule } from '../../log_analysis_module'; import { useLogAnalysisModuleConfiguration } from '../../log_analysis_module_configuration'; @@ -19,11 +19,13 @@ export const useLogEntryCategoriesModule = ({ indexPattern, sourceId, spaceId, + timestampField, runtimeMappings, }: { indexPattern: string; sourceId: string; spaceId: string; + timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( @@ -31,9 +33,10 @@ export const useLogEntryCategoriesModule = ({ indices: indexPattern.split(','), sourceId, spaceId, + timestampField, runtimeMappings, }), - [indexPattern, sourceId, spaceId, runtimeMappings] + [indexPattern, sourceId, spaceId, timestampField, runtimeMappings] ); const logAnalysisModule = useLogAnalysisModule({ diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts index 4e700852361b9..c4c939d0ebb9d 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { estypes } from '@elastic/elasticsearch'; import type { HttpHandler } from 'src/core/public'; import { bucketSpan, @@ -16,7 +16,6 @@ import { logEntryRateJobTypes, partitionField, } from '../../../../../../common/log_analysis'; -import { TIMESTAMP_FIELD } from '../../../../../../common/constants'; import { ModuleDescriptor, ModuleSourceConfiguration } from '../../log_analysis_module_types'; import { cleanUpJobsAndDatafeeds } from '../../log_analysis_cleanup'; import { callJobsSummaryAPI } from '../../api/ml_get_jobs_summary_api'; @@ -63,7 +62,7 @@ const setUpModule = async ( start: number | undefined, end: number | undefined, datasetFilter: DatasetFilter, - { spaceId, sourceId, indices, runtimeMappings }: ModuleSourceConfiguration, + { spaceId, sourceId, indices, timestampField, runtimeMappings }: ModuleSourceConfiguration, fetch: HttpHandler ) => { const indexNamePattern = indices.join(','); @@ -74,12 +73,12 @@ const setUpModule = async ( bucket_span: `${bucketSpan}ms`, }, data_description: { - time_field: TIMESTAMP_FIELD, + time_field: timestampField, }, custom_settings: { logs_source_config: { indexPattern: indexNamePattern, - timestampField: TIMESTAMP_FIELD, + timestampField, bucketSpan, }, }, @@ -129,6 +128,7 @@ const cleanUpModule = async (spaceId: string, sourceId: string, fetch: HttpHandl const validateSetupIndices = async ( indices: string[], + timestampField: string, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { @@ -137,7 +137,7 @@ const validateSetupIndices = async ( indices, fields: [ { - name: TIMESTAMP_FIELD, + name: timestampField, validTypes: ['date'], }, { @@ -153,12 +153,16 @@ const validateSetupIndices = async ( const validateSetupDatasets = async ( indices: string[], + timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, fetch: HttpHandler ) => { - return await callValidateDatasetsAPI({ indices, startTime, endTime, runtimeMappings }, fetch); + return await callValidateDatasetsAPI( + { indices, timestampField, startTime, endTime, runtimeMappings }, + fetch + ); }; export const logEntryRateModule: ModuleDescriptor = { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx index 6dd8d1acbab14..f3e8f7e777597 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { estypes } from '@elastic/elasticsearch'; import createContainer from 'constate'; import { useMemo } from 'react'; import { ModuleSourceConfiguration } from '../../log_analysis_module_types'; @@ -18,11 +18,13 @@ export const useLogEntryRateModule = ({ indexPattern, sourceId, spaceId, + timestampField, runtimeMappings, }: { indexPattern: string; sourceId: string; spaceId: string; + timestampField: string; runtimeMappings: estypes.MappingRuntimeFields; }) => { const sourceConfiguration: ModuleSourceConfiguration = useMemo( @@ -30,9 +32,10 @@ export const useLogEntryRateModule = ({ indices: indexPattern.split(','), sourceId, spaceId, + timestampField, runtimeMappings, }), - [indexPattern, sourceId, spaceId, runtimeMappings] + [indexPattern, sourceId, spaceId, timestampField, runtimeMappings] ); const logAnalysisModule = useLogAnalysisModule({ From 38c6a1bcf7993c6d2d5793c816f3e84b7a193c2a Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:08:47 -0500 Subject: [PATCH 10/21] Fix merge --- .../containers/logs/log_analysis/api/validate_datasets.ts | 2 +- .../containers/logs/log_analysis/api/validate_indices.ts | 2 +- .../logs/log_analysis/log_analysis_module_types.ts | 2 +- .../modules/log_entry_categories/module_descriptor.ts | 2 +- .../log_entry_categories/use_log_entry_categories_module.tsx | 2 +- .../log_analysis/modules/log_entry_rate/module_descriptor.ts | 2 +- .../modules/log_entry_rate/use_log_entry_rate_module.tsx | 2 +- .../public/containers/logs/log_source/log_source.mock.ts | 5 +++++ 8 files changed, 12 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts index 9de6e574ecb5b..94bb3d8e66cbf 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { HttpHandler } from 'src/core/public'; import { LOG_ANALYSIS_VALIDATE_DATASETS_PATH, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts index a211fecc807fa..8a9f960b54afa 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts @@ -6,7 +6,7 @@ */ import type { HttpHandler } from 'src/core/public'; -import { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { LOG_ANALYSIS_VALIDATE_INDICES_PATH, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts index 4ae99b95cfff8..4ff8c0c3c08e0 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts @@ -6,7 +6,7 @@ */ import type { HttpHandler } from 'src/core/public'; -import { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { ValidateLogEntryDatasetsResponsePayload, ValidationIndicesResponsePayload, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts index 6823ed173a740..9ef41042302a1 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/module_descriptor.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { i18n } from '@kbn/i18n'; import type { HttpHandler } from 'src/core/public'; import { diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx index 99d4ab4becee5..433a24cffd937 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_module.tsx @@ -6,7 +6,7 @@ */ import createContainer from 'constate'; -import { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { useMemo } from 'react'; import { useLogAnalysisModule } from '../../log_analysis_module'; import { useLogAnalysisModuleConfiguration } from '../../log_analysis_module_configuration'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts index c4c939d0ebb9d..214faaf9a3012 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/module_descriptor.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { HttpHandler } from 'src/core/public'; import { bucketSpan, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx index f3e8f7e777597..46587969ca2ab 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_rate/use_log_entry_rate_module.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { estypes } from '@elastic/elasticsearch'; +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import createContainer from 'constate'; import { useMemo } from 'react'; import { ModuleSourceConfiguration } from '../../log_analysis_module_types'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts index 204fae7dc0f2b..6021c728d32af 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts @@ -73,6 +73,11 @@ export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfi }, logColumns: [], fields: { + container: 'CONTAINER_FIELD', + host: 'HOST_FIELD', + pod: 'POD_FIELD', + tiebreaker: 'TIEBREAKER_FIELD', + timestamp: 'TIMESTAMP_FIELD', message: ['MESSAGE_FIELD'], }, name: sourceId, From bddc9cae14d7a7e03f6f8e87e0c4d626723a6dfc Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:31:22 -0500 Subject: [PATCH 11/21] Revert additional logs files --- .../log_threshold_chart_preview.ts | 17 ++++---- .../log_threshold_executor.test.ts | 27 +++++++++--- .../log_threshold/log_threshold_executor.ts | 43 +++++++++++++------ .../lib/alerting/log_threshold/mocks/index.ts | 1 + .../log_entries_domain/log_entries_domain.ts | 2 + .../queries/log_entry_datasets.ts | 4 +- .../lib/log_analysis/log_entry_anomalies.ts | 11 ++++- .../log_entry_categories_analysis.ts | 11 ++++- .../queries/log_entry_category_examples.ts | 7 +-- .../queries/log_entry_examples.ts | 7 +-- .../log_entries_search_strategy.test.ts | 5 +++ .../log_entries_search_strategy.ts | 4 +- .../log_entry_search_strategy.test.ts | 5 +++ .../log_entries/log_entry_search_strategy.ts | 15 ++++++- .../log_entries/queries/log_entries.ts | 7 +-- .../services/log_entries/queries/log_entry.ts | 5 ++- .../apis/metrics_ui/log_sources.ts | 18 ++++++++ 17 files changed, 142 insertions(+), 47 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts index 52c7cc6223a25..7bf2cb5ea3394 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts @@ -13,7 +13,6 @@ import { Series, Point, } from '../../../../common/http_api/log_alerts'; -import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { getGroupedESQuery, getUngroupedESQuery, @@ -38,7 +37,7 @@ export async function getChartPreviewData( alertParams: GetLogAlertsChartPreviewDataAlertParamsSubset, buckets: number ) { - const { indices, runtimeMappings } = resolvedLogSourceConfiguration; + const { indices, timestampField, runtimeMappings } = resolvedLogSourceConfiguration; const { groupBy, timeSize, timeUnit } = alertParams; const isGrouped = groupBy && groupBy.length > 0 ? true : false; @@ -48,11 +47,11 @@ export async function getChartPreviewData( timeSize: timeSize * buckets, }; - const { rangeFilter } = buildFiltersFromCriteria(expandedAlertParams); + const { rangeFilter } = buildFiltersFromCriteria(expandedAlertParams, timestampField); const query = isGrouped - ? getGroupedESQuery(expandedAlertParams, indices, runtimeMappings) - : getUngroupedESQuery(expandedAlertParams, indices, runtimeMappings); + ? getGroupedESQuery(expandedAlertParams, timestampField, indices, runtimeMappings) + : getUngroupedESQuery(expandedAlertParams, timestampField, indices, runtimeMappings); if (!query) { throw new Error('ES query could not be built from the provided alert params'); @@ -62,6 +61,7 @@ export async function getChartPreviewData( query, rangeFilter, `${timeSize}${timeUnit}`, + timestampField, isGrouped ); @@ -79,18 +79,19 @@ const addHistogramAggregationToQuery = ( query: any, rangeFilter: any, interval: string, + timestampField: string, isGrouped: boolean ) => { const histogramAggregation = { histogramBuckets: { date_histogram: { - field: TIMESTAMP_FIELD, + field: timestampField, fixed_interval: interval, // Utilise extended bounds to make sure we get a full set of buckets even if there are empty buckets // at the start and / or end of the range. extended_bounds: { - min: rangeFilter.range[TIMESTAMP_FIELD].gte, - max: rangeFilter.range[TIMESTAMP_FIELD].lte, + min: rangeFilter.range[timestampField].gte, + max: rangeFilter.range[timestampField].lte, }, }, }, diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts index d5338f1e3ec6d..e5d8bab948581 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.test.ts @@ -169,7 +169,7 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: positiveCriteria, }; - const filters = buildFiltersFromCriteria(alertParams); + const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); expect(filters.mustFilters).toEqual(expectedPositiveFilterClauses); }); @@ -178,14 +178,14 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: negativeCriteria, }; - const filters = buildFiltersFromCriteria(alertParams); + const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); expect(filters.mustNotFilters).toEqual(expectedNegativeFilterClauses); }); test('Handles time range', () => { const alertParams: AlertParams = { ...baseAlertParams, criteria: [] }; - const filters = buildFiltersFromCriteria(alertParams); + const filters = buildFiltersFromCriteria(alertParams, TIMESTAMP_FIELD); expect(typeof filters.rangeFilter.range[TIMESTAMP_FIELD].gte).toBe('number'); expect(typeof filters.rangeFilter.range[TIMESTAMP_FIELD].lte).toBe('number'); expect(filters.rangeFilter.range[TIMESTAMP_FIELD].format).toBe('epoch_millis'); @@ -203,7 +203,12 @@ describe('Log threshold executor', () => { ...baseAlertParams, criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getUngroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); + const query = getUngroupedESQuery( + alertParams, + TIMESTAMP_FIELD, + FILEBEAT_INDEX, + runtimeMappings + ); expect(query).toEqual({ index: 'filebeat-*', allow_no_indices: true, @@ -248,7 +253,12 @@ describe('Log threshold executor', () => { groupBy: ['host.name'], criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getGroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); + const query = getGroupedESQuery( + alertParams, + TIMESTAMP_FIELD, + FILEBEAT_INDEX, + runtimeMappings + ); expect(query).toEqual({ index: 'filebeat-*', @@ -313,7 +323,12 @@ describe('Log threshold executor', () => { criteria: [...positiveCriteria, ...negativeCriteria], }; - const query = getGroupedESQuery(alertParams, FILEBEAT_INDEX, runtimeMappings); + const query = getGroupedESQuery( + alertParams, + TIMESTAMP_FIELD, + FILEBEAT_INDEX, + runtimeMappings + ); expect(query).toEqual({ index: 'filebeat-*', diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index 315cfe3e7825d..6d2b074c45bb0 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -41,7 +41,6 @@ import { UngroupedSearchQueryResponse, UngroupedSearchQueryResponseRT, } from '../../../../common/alerting/logs/log_threshold/types'; -import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { resolveLogSourceConfiguration } from '../../../../common/log_sources'; import { decodeOrThrow } from '../../../../common/runtime_types'; import { getIntervalInSeconds } from '../../../utils/get_interval_in_seconds'; @@ -108,7 +107,7 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => }); const sourceConfiguration = await sources.getSourceConfiguration(savedObjectsClient, 'default'); - const { indices, runtimeMappings } = await resolveLogSourceConfiguration( + const { indices, timestampField, runtimeMappings } = await resolveLogSourceConfiguration( sourceConfiguration.configuration, await libs.framework.getIndexPatternsService( savedObjectsClient, @@ -122,6 +121,7 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => if (!isRatioAlertParams(validatedParams)) { await executeAlert( validatedParams, + timestampField, indices, runtimeMappings, scopedClusterClient.asCurrentUser, @@ -130,6 +130,7 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => } else { await executeRatioAlert( validatedParams, + timestampField, indices, runtimeMappings, scopedClusterClient.asCurrentUser, @@ -143,12 +144,13 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => async function executeAlert( alertParams: CountAlertParams, + timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields, esClient: ElasticsearchClient, alertInstanceFactory: LogThresholdAlertInstanceFactory ) { - const query = getESQuery(alertParams, indexPattern, runtimeMappings); + const query = getESQuery(alertParams, timestampField, indexPattern, runtimeMappings); if (!query) { throw new Error('ES query could not be built from the provided alert params'); @@ -173,6 +175,7 @@ async function executeAlert( async function executeRatioAlert( alertParams: RatioAlertParams, + timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields, esClient: ElasticsearchClient, @@ -189,8 +192,13 @@ async function executeRatioAlert( criteria: getDenominator(alertParams.criteria), }; - const numeratorQuery = getESQuery(numeratorParams, indexPattern, runtimeMappings); - const denominatorQuery = getESQuery(denominatorParams, indexPattern, runtimeMappings); + const numeratorQuery = getESQuery(numeratorParams, timestampField, indexPattern, runtimeMappings); + const denominatorQuery = getESQuery( + denominatorParams, + timestampField, + indexPattern, + runtimeMappings + ); if (!numeratorQuery || !denominatorQuery) { throw new Error('ES query could not be built from the provided ratio alert params'); @@ -221,12 +229,13 @@ async function executeRatioAlert( const getESQuery = ( alertParams: Omit & { criteria: CountCriteria }, + timestampField: string, indexPattern: string, runtimeMappings: estypes.MappingRuntimeFields ) => { return hasGroupBy(alertParams) - ? getGroupedESQuery(alertParams, indexPattern, runtimeMappings) - : getUngroupedESQuery(alertParams, indexPattern, runtimeMappings); + ? getGroupedESQuery(alertParams, timestampField, indexPattern, runtimeMappings) + : getUngroupedESQuery(alertParams, timestampField, indexPattern, runtimeMappings); }; export const processUngroupedResults = ( @@ -448,7 +457,8 @@ export const updateAlertInstance: AlertInstanceUpdater = (alertInstance, state, }; export const buildFiltersFromCriteria = ( - params: Pick & { criteria: CountCriteria } + params: Pick & { criteria: CountCriteria }, + timestampField: string ) => { const { timeSize, timeUnit, criteria } = params; const interval = `${timeSize}${timeUnit}`; @@ -472,7 +482,7 @@ export const buildFiltersFromCriteria = ( const rangeFilter = { range: { - [TIMESTAMP_FIELD]: { + [timestampField]: { gte: from, lte: to, format: 'epoch_millis', @@ -486,7 +496,7 @@ export const buildFiltersFromCriteria = ( // and match / not match the criteria. const groupedRangeFilter = { range: { - [TIMESTAMP_FIELD]: { + [timestampField]: { gte: from - intervalAsMs, lte: to + intervalAsMs, format: 'epoch_millis', @@ -505,6 +515,7 @@ export const getGroupedESQuery = ( value?: AlertParams['count']['value']; }; }, + timestampField: string, index: string, runtimeMappings: estypes.MappingRuntimeFields ): estypes.SearchRequest | undefined => { @@ -525,8 +536,10 @@ export const getGroupedESQuery = ( return; } - const { rangeFilter, groupedRangeFilter, mustFilters, mustNotFilters } = - buildFiltersFromCriteria(params); + const { rangeFilter, groupedRangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria( + params, + timestampField + ); if (isOptimizableGroupedThreshold(comparator, value)) { const aggregations = { @@ -607,10 +620,14 @@ export const getGroupedESQuery = ( export const getUngroupedESQuery = ( params: Pick & { criteria: CountCriteria }, + timestampField: string, index: string, runtimeMappings: estypes.MappingRuntimeFields ): object => { - const { rangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria(params); + const { rangeFilter, mustFilters, mustNotFilters } = buildFiltersFromCriteria( + params, + timestampField + ); const body: estypes.SearchRequest['body'] = { // Ensure we accurately track the hit count for the ungrouped case, otherwise we can only ensure accuracy up to 10,000. diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts index f02dac2139097..296a540b4a920 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts @@ -17,6 +17,7 @@ export const libsMock = { type: 'index_pattern', indexPatternId: 'some-id', }, + fields: { timestamp: '@timestamp' }, }, }); }, diff --git a/x-pack/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 index 4963d78486a3d..e7b1624206515 100644 --- a/x-pack/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 @@ -272,6 +272,7 @@ export class InfraLogEntriesDomain { public async getLogEntryDatasets( requestContext: InfraPluginRequestHandlerContext, + timestampField: string, indexName: string, startTime: number, endTime: number, @@ -286,6 +287,7 @@ export class InfraLogEntriesDomain { 'search', createLogEntryDatasetsQuery( indexName, + timestampField, startTime, endTime, runtimeMappings, diff --git a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts index e9b65c28082f7..4386b6ccef9c1 100644 --- a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts +++ b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/queries/log_entry_datasets.ts @@ -8,11 +8,11 @@ import * as rt from 'io-ts'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { TIMESTAMP_FIELD } from '../../../../../common/constants'; import { commonSearchSuccessResponseFieldsRT } from '../../../../utils/elasticsearch_runtime_types'; export const createLogEntryDatasetsQuery = ( indexName: string, + timestampField: string, startTime: number, endTime: number, runtimeMappings: estypes.MappingRuntimeFields, @@ -26,7 +26,7 @@ export const createLogEntryDatasetsQuery = ( filter: [ { range: { - [TIMESTAMP_FIELD]: { + [timestampField]: { gte: startTime, lte: endTime, }, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts index 0b270d2f71db7..aca0483037912 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts @@ -346,9 +346,10 @@ export async function getLogEntryExamples( const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings); const indices = customSettings?.logs_source_config?.indexPattern; - const { runtimeMappings } = resolvedSourceConfiguration; + const timestampField = customSettings?.logs_source_config?.timestampField; + const { tiebreakerField, runtimeMappings } = resolvedSourceConfiguration; - if (indices == null) { + if (indices == null || timestampField == null) { throw new InsufficientLogAnalysisMlJobConfigurationError( `Failed to find index configuration for ml job ${jobId}` ); @@ -362,6 +363,8 @@ export async function getLogEntryExamples( sourceId, indices, runtimeMappings, + timestampField, + tiebreakerField, startTime, endTime, dataset, @@ -385,6 +388,8 @@ export async function fetchLogEntryExamples( sourceId: string, indices: string, runtimeMappings: estypes.MappingRuntimeFields, + timestampField: string, + tiebreakerField: string, startTime: number, endTime: number, dataset: string, @@ -430,6 +435,8 @@ export async function fetchLogEntryExamples( createLogEntryExamplesQuery( indices, runtimeMappings, + timestampField, + tiebreakerField, startTime, endTime, dataset, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts index c4f0a830da14c..d1d136c741876 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts @@ -165,9 +165,10 @@ export async function getLogEntryCategoryExamples( const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings); const indices = customSettings?.logs_source_config?.indexPattern; - const { runtimeMappings } = resolvedSourceConfiguration; + const timestampField = customSettings?.logs_source_config?.timestampField; + const { tiebreakerField, runtimeMappings } = resolvedSourceConfiguration; - if (indices == null) { + if (indices == null || timestampField == null) { throw new InsufficientLogAnalysisMlJobConfigurationError( `Failed to find index configuration for ml job ${logEntryCategoriesCountJobId}` ); @@ -190,6 +191,8 @@ export async function getLogEntryCategoryExamples( context, indices, runtimeMappings, + timestampField, + tiebreakerField, startTime, endTime, category._source.terms, @@ -401,6 +404,8 @@ async function fetchLogEntryCategoryExamples( requestContext: { core: { elasticsearch: { client: { asCurrentUser: ElasticsearchClient } } } }, indices: string, runtimeMappings: estypes.MappingRuntimeFields, + timestampField: string, + tiebreakerField: string, startTime: number, endTime: number, categoryQuery: string, @@ -416,6 +421,8 @@ async function fetchLogEntryCategoryExamples( createLogEntryCategoryExamplesQuery( indices, runtimeMappings, + timestampField, + tiebreakerField, startTime, endTime, categoryQuery, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts index 275144eb4c3d4..dd68de4e49d34 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_category_examples.ts @@ -7,13 +7,14 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import * as rt from 'io-ts'; -import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { defaultRequestParameters } from './common'; export const createLogEntryCategoryExamplesQuery = ( indices: string, runtimeMappings: estypes.MappingRuntimeFields, + timestampField: string, + tiebreakerField: string, startTime: number, endTime: number, categoryQuery: string, @@ -26,7 +27,7 @@ export const createLogEntryCategoryExamplesQuery = ( filter: [ { range: { - [TIMESTAMP_FIELD]: { + [timestampField]: { gte: startTime, lte: endTime, }, @@ -44,7 +45,7 @@ export const createLogEntryCategoryExamplesQuery = ( }, }, runtime_mappings: runtimeMappings, - sort: [{ [TIMESTAMP_FIELD]: 'asc' }, { [TIEBREAKER_FIELD]: 'asc' }], + sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }], _source: false, fields: ['event.dataset', 'message', 'container.id', 'host.name', 'log.file.path'], }, diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts index e49da71968d1e..d6099404daa80 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts @@ -7,7 +7,6 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import * as rt from 'io-ts'; -import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { partitionField } from '../../../../common/log_analysis'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; import { defaultRequestParameters } from './common'; @@ -15,6 +14,8 @@ import { defaultRequestParameters } from './common'; export const createLogEntryExamplesQuery = ( indices: string, runtimeMappings: estypes.MappingRuntimeFields, + timestampField: string, + tiebreakerField: string, startTime: number, endTime: number, dataset: string, @@ -28,7 +29,7 @@ export const createLogEntryExamplesQuery = ( filter: [ { range: { - [TIMESTAMP_FIELD]: { + [timestampField]: { gte: startTime, lte: endTime, }, @@ -71,7 +72,7 @@ export const createLogEntryExamplesQuery = ( }, }, runtime_mappings: runtimeMappings, - sort: [{ [TIMESTAMP_FIELD]: 'asc' }, { [TIEBREAKER_FIELD]: 'asc' }], + sort: [{ [timestampField]: 'asc' }, { [tiebreakerField]: 'asc' }], _source: false, fields: ['event.dataset', 'message'], }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts index e48c990d7822f..b0d2eeb987861 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts @@ -289,7 +289,12 @@ const createSourceConfigurationMock = (): InfraSource => ({ }, ], fields: { + pod: 'POD_FIELD', + host: 'HOST_FIELD', + container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], + timestamp: 'TIMESTAMP_FIELD', + tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts index 9b42a31308fde..b401b68d0e3d3 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts @@ -109,7 +109,7 @@ export const logEntriesSearchStrategyProvider = ({ forkJoin([resolvedSourceConfiguration$, messageFormattingRules$]).pipe( map( ([ - { indices, columns, runtimeMappings }, + { indices, timestampField, tiebreakerField, columns, runtimeMappings }, messageFormattingRules, ]): IEsSearchRequest => { return { @@ -119,6 +119,8 @@ export const logEntriesSearchStrategyProvider = ({ params.endTimestamp, pickRequestCursor(params), params.size + 1, + timestampField, + tiebreakerField, getRequiredFields(params.columns ?? columns, messageFormattingRules), runtimeMappings, params.query, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts index 685f11cb00a86..1f03878ba6feb 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts @@ -244,7 +244,12 @@ const createSourceConfigurationMock = (): InfraSource => ({ metricsExplorerDefaultView: 'DEFAULT_VIEW', logColumns: [], fields: { + pod: 'POD_FIELD', + host: 'HOST_FIELD', + container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], + timestamp: 'TIMESTAMP_FIELD', + tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts index 4ee9db404ad9d..565318578f990 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts @@ -78,8 +78,19 @@ export const logEntrySearchStrategyProvider = ({ concatMap(({ params }) => resolvedSourceConfiguration$.pipe( map( - ({ indices, runtimeMappings }): IEsSearchRequest => ({ - params: createGetLogEntryQuery(indices, params.logEntryId, runtimeMappings), + ({ + indices, + timestampField, + tiebreakerField, + runtimeMappings, + }): IEsSearchRequest => ({ + params: createGetLogEntryQuery( + indices, + params.logEntryId, + timestampField, + tiebreakerField, + runtimeMappings + ), }) ) ) diff --git a/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts b/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts index 5041625d49a1a..6ca6d5ecd0191 100644 --- a/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts +++ b/x-pack/plugins/infra/server/services/log_entries/queries/log_entries.ts @@ -7,7 +7,6 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import * as rt from 'io-ts'; -import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { LogEntryAfterCursor, logEntryAfterCursorRT, @@ -27,6 +26,8 @@ export const createGetLogEntriesQuery = ( endTimestamp: number, cursor: LogEntryBeforeCursor | LogEntryAfterCursor | null | undefined, size: number, + timestampField: string, + tiebreakerField: string, fields: string[], runtimeMappings?: estypes.MappingRuntimeFields, query?: JsonObject, @@ -47,14 +48,14 @@ export const createGetLogEntriesQuery = ( filter: [ ...(query ? [query] : []), ...(highlightQuery ? [highlightQuery] : []), - ...createTimeRangeFilterClauses(startTimestamp, endTimestamp, TIMESTAMP_FIELD), + ...createTimeRangeFilterClauses(startTimestamp, endTimestamp, timestampField), ], }, }, fields, runtime_mappings: runtimeMappings, _source: false, - ...createSortClause(sortDirection, TIMESTAMP_FIELD, TIEBREAKER_FIELD), + ...createSortClause(sortDirection, timestampField, tiebreakerField), ...createSearchAfterClause(cursor), ...createHighlightClause(highlightQuery, fields), }, diff --git a/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts b/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts index 3061aa19e7cbf..856f8b1af9770 100644 --- a/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts +++ b/x-pack/plugins/infra/server/services/log_entries/queries/log_entry.ts @@ -7,7 +7,6 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import * as rt from 'io-ts'; -import { TIMESTAMP_FIELD, TIEBREAKER_FIELD } from '../../../../common/constants'; import { jsonArrayRT } from '../../../../common/typed_json'; import { commonHitFieldsRT, @@ -17,6 +16,8 @@ import { export const createGetLogEntryQuery = ( logEntryIndex: string, logEntryId: string, + timestampField: string, + tiebreakerField: string, runtimeMappings?: estypes.MappingRuntimeFields ): estypes.AsyncSearchSubmitRequest => ({ index: logEntryIndex, @@ -32,7 +33,7 @@ export const createGetLogEntryQuery = ( }, fields: ['*'], runtime_mappings: runtimeMappings, - sort: [{ [TIMESTAMP_FIELD]: 'desc' }, { [TIEBREAKER_FIELD]: 'desc' }], + sort: [{ [timestampField]: 'desc' }, { [tiebreakerField]: 'desc' }], _source: false, }, }); diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts index 516c262429299..5b615c4b18916 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts @@ -40,6 +40,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); + expect(configuration.fields.timestamp).to.be('@timestamp'); + expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); expect(configuration.logColumns[2]).to.have.key('messageColumn'); @@ -56,6 +58,10 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, + fields: { + tiebreaker: 'TIEBREAKER', + timestamp: 'TIMESTAMP', + }, logColumns: [ { messageColumn: { @@ -77,6 +83,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); + expect(configuration.fields.timestamp).to.be('TIMESTAMP'); + expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); @@ -103,6 +111,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); + expect(configuration.fields.timestamp).to.be('@timestamp'); + expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); @@ -132,6 +142,10 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, + fields: { + tiebreaker: 'TIEBREAKER', + timestamp: 'TIMESTAMP', + }, logColumns: [ { messageColumn: { @@ -152,6 +166,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); + expect(configuration.fields.timestamp).to.be('TIMESTAMP'); + expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); }); @@ -173,6 +189,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); + expect(configuration.fields.timestamp).to.be('@timestamp'); + expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); From f91a05e2a3627b25e884f958eeb3e69ac42245a6 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:36:59 -0500 Subject: [PATCH 12/21] Revert inventory models --- .../metrics/tsvb/container_cpu_kernel.ts | 4 ++-- .../metrics/tsvb/container_cpu_usage.ts | 4 ++-- .../metrics/tsvb/container_disk_io_bytes.ts | 4 ++-- .../metrics/tsvb/container_diskio_ops.ts | 4 ++-- .../metrics/tsvb/container_memory.ts | 4 ++-- .../metrics/tsvb/container_network_traffic.ts | 4 ++-- .../metrics/tsvb/container_overview.ts | 4 ++-- .../inventory_models/create_tsvb_model.ts | 5 ++-- .../host/metrics/tsvb/host_cpu_usage.ts | 9 +++++--- .../host/metrics/tsvb/host_docker_info.ts | 4 ++-- .../host/metrics/tsvb/host_docker_overview.ts | 4 ++-- .../metrics/tsvb/host_docker_top_5_by_cpu.ts | 4 ++-- .../tsvb/host_docker_top_5_by_memory.ts | 4 ++-- .../host/metrics/tsvb/host_filesystem.ts | 4 ++-- .../host/metrics/tsvb/host_k8s_cpu_cap.ts | 9 +++++--- .../host/metrics/tsvb/host_k8s_disk_cap.ts | 4 ++-- .../host/metrics/tsvb/host_k8s_memory_cap.ts | 4 ++-- .../host/metrics/tsvb/host_k8s_overview.ts | 4 ++-- .../host/metrics/tsvb/host_k8s_pod_cap.ts | 9 +++++--- .../host/metrics/tsvb/host_load.ts | 9 +++++--- .../host/metrics/tsvb/host_memory_usage.ts | 4 ++-- .../host/metrics/tsvb/host_network_traffic.ts | 4 ++-- .../host/metrics/tsvb/host_system_overview.ts | 4 ++-- .../infra/common/inventory_models/index.ts | 23 ++++++++++++------- .../pod/metrics/tsvb/pod_cpu_usage.ts | 9 +++++--- .../pod/metrics/tsvb/pod_log_usage.ts | 9 +++++--- .../pod/metrics/tsvb/pod_memory_usage.ts | 4 ++-- .../pod/metrics/tsvb/pod_network_traffic.ts | 4 ++-- .../pod/metrics/tsvb/pod_overview.ts | 9 +++++--- .../metrics/tsvb/aws_cpu_utilization.ts | 8 ++++--- .../shared/metrics/tsvb/aws_diskio_bytes.ts | 8 ++++--- .../shared/metrics/tsvb/aws_diskio_ops.ts | 5 ++-- .../shared/metrics/tsvb/aws_network_bytes.ts | 8 ++++--- .../metrics/tsvb/aws_network_packets.ts | 8 ++++--- .../shared/metrics/tsvb/aws_overview.ts | 5 ++-- .../metrics/tsvb/nginx_active_connections.ts | 4 ++-- .../shared/metrics/tsvb/nginx_hits.ts | 9 +++++--- .../shared/metrics/tsvb/nginx_request_rate.ts | 4 ++-- .../tsvb/nginx_requests_per_connection.ts | 4 ++-- .../infra/common/inventory_models/types.ts | 1 + .../metrics/kibana_metrics_adapter.ts | 3 ++- 41 files changed, 138 insertions(+), 100 deletions(-) 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 index 5a4a02d296598..f469a9e86ad49 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuKernel: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerCpuKernel: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 20718b4436f0c..f4efc7de43663 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerCpuUsage: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerCpuUsage: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 8d895a5b2db26..3ba2b11740b6e 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOBytes: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerDiskIOBytes: TSVBMetricModelCreator = ( requires: ['docker.disk'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 9603157594833..772c0d6c0a33e 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerDiskIOOps: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerDiskIOOps: TSVBMetricModelCreator = ( requires: ['docker.disk'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 52d6a2bf7d587..e0572692d60fc 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerMemory: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerMemory: TSVBMetricModelCreator = ( requires: ['docker.memory'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index a5054a1c88570..d957d51a41648 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerNetworkTraffic: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerNetworkTraffic: TSVBMetricModelCreator = ( requires: ['docker.network'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index a9c2cae3a7cd8..c2d234be2eed7 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const containerOverview: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const containerOverview: TSVBMetricModelCreator = ( requires: ['docker'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index fbddb47e2175b..5c9b3beb31c7c 100644 --- a/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts +++ b/x-pack/plugins/infra/common/inventory_models/create_tsvb_model.ts @@ -5,7 +5,6 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../constants'; import { TSVBMetricModelCreator, TSVBMetricModel, TSVBSeries, InventoryMetric } from './types'; export const createTSVBModel = @@ -16,13 +15,13 @@ export const createTSVBModel = interval = '>=300s', dropLastBucket = true ): TSVBMetricModelCreator => - (indexPattern): TSVBMetricModel => ({ + (timeField, indexPattern): TSVBMetricModel => ({ id, requires, drop_last_bucket: dropLastBucket, index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series, }); 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 index 5c4fc8bc8c4cf..bcafeb4ebc4cf 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostCpuUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const hostCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'hostCpuUsage', requires: ['system.cpu'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 67f0b95a98a72..4cc2b574362d7 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerInfo: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostDockerInfo: TSVBMetricModelCreator = ( requires: ['docker.info'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index e4ebbf177d7c7..df56a21dbf5b7 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerOverview: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostDockerOverview: TSVBMetricModelCreator = ( requires: ['docker.info'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'top_n', series: [ { 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 index 52fc0e9bd07fb..fd9eb97419736 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( requires: ['docker.cpu'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 4547cb3a68981..cad828671d232 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( requires: ['docker.memory'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 20e149a040407..ce284345410fc 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostFilesystem: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostFilesystem: TSVBMetricModelCreator = ( requires: ['system.filesystem'], filter: 'system.filesystem.device_name:\\/*', index_pattern: indexPattern, - time_field: TIMESTAMP_FIELD, + time_field: timeField, interval, type: 'timeseries', series: [ 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 index 2586adba21f66..d33e4cdeb34cd 100644 --- 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 @@ -5,16 +5,19 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sCpuCap: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index a11267f7f4f02..e9e512a136631 100644 --- 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 @@ -5,9 +5,9 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sDiskCap: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostK8sDiskCap: TSVBMetricModelCreator = ( requires: ['kubernetes.node'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 9c73a9696c5d5..ccc227ef1854e 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sMemoryCap: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -17,7 +17,7 @@ export const hostK8sMemoryCap: TSVBMetricModelCreator = ( requires: ['kubernetes.node'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index ab0dbc453f251..2da74d50dff1b 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostK8sOverview: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostK8sOverview: TSVBMetricModelCreator = ( requires: ['kubernetes'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'top_n', series: [ { 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 index fddc1ed1cdae3..85cb798eaf9b9 100644 --- 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 @@ -5,16 +5,19 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sPodCap: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ 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 index aa12bc79e78e7..bef170c743e6c 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostLoad: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const hostLoad: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'hostLoad', requires: ['system.cpu'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 25872e5761f84..bda81dea4bd28 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostMemoryUsage: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostMemoryUsage: TSVBMetricModelCreator = ( requires: ['system.memory'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 509caed21f063..ec8c0937ce0ea 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostNetworkTraffic: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostNetworkTraffic: TSVBMetricModelCreator = ( requires: ['system.network'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 102d069ce1075..eef480e12aab0 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const hostSystemOverview: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const hostSystemOverview: TSVBMetricModelCreator = ( requires: ['system.cpu', 'system.memory', 'system.load', 'system.network'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'top_n', series: [ { diff --git a/x-pack/plugins/infra/common/inventory_models/index.ts b/x-pack/plugins/infra/common/inventory_models/index.ts index 81f89be8cd6a6..6350e76ca7f29 100644 --- a/x-pack/plugins/infra/common/inventory_models/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/index.ts @@ -6,7 +6,6 @@ */ import { i18n } from '@kbn/i18n'; -import { POD_FIELD, HOST_FIELD, CONTAINER_FIELD } from '../constants'; import { host } from './host'; import { pod } from './pod'; import { awsEC2 } from './aws_ec2'; @@ -31,23 +30,31 @@ export const findInventoryModel = (type: InventoryItemType) => { return model; }; +interface InventoryFields { + host: string; + pod: string; + container: string; + timestamp: string; + tiebreaker: string; +} + const LEGACY_TYPES = ['host', 'pod', 'container']; -export const getFieldByType = (type: InventoryItemType) => { +const getFieldByType = (type: InventoryItemType, fields: InventoryFields) => { switch (type) { case 'pod': - return POD_FIELD; + return fields.pod; case 'host': - return HOST_FIELD; + return fields.host; case 'container': - return CONTAINER_FIELD; + return fields.container; } }; -export const findInventoryFields = (type: InventoryItemType) => { +export const findInventoryFields = (type: InventoryItemType, fields?: InventoryFields) => { const inventoryModel = findInventoryModel(type); - if (LEGACY_TYPES.includes(type)) { - const id = getFieldByType(type) || inventoryModel.fields.id; + if (fields && LEGACY_TYPES.includes(type)) { + const id = getFieldByType(type, fields) || inventoryModel.fields.id; return { ...inventoryModel.fields, id, 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 index 07adfc667c925..a7574fc68813f 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podCpuUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const podCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'podCpuUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index b659d19712db5..0e2a588463160 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podLogUsage: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const podLogUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'podLogUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index ff4af90b1494e..9c774e1b18ed0 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podMemoryUsage: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const podMemoryUsage: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 898918d37f980..f9b8737f54a91 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const podNetworkTraffic: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const podNetworkTraffic: TSVBMetricModelCreator = ( requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index d446aa1a62338..0fe94c7f53dab 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podOverview: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const podOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'podOverview', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index a407c0c27256c..51b9a4cfc7b3f 100644 --- 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 @@ -5,17 +5,19 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsCpuUtilization: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 08ba43e5dac1e..5224545c006b7 100644 --- 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 @@ -5,17 +5,19 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsDiskioBytes: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 3efebb8694fe8..c362a6d88c27a 100644 --- 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 @@ -5,17 +5,16 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsDiskioOps: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 2aadca4909c3c..b142feb95450c 100644 --- 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 @@ -5,19 +5,21 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; // see discussion in: https://github.com/elastic/kibana/issues/42687 -export const awsNetworkBytes: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 9cb94ee889df1..9d39582b66864 100644 --- 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 @@ -5,17 +5,19 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsNetworkPackets: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index fdea10d6c472c..3fe12d62d3352 100644 --- 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 @@ -5,17 +5,16 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsOverview: TSVBMetricModelCreator = (indexPattern): TSVBMetricModel => ({ +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: TIMESTAMP_FIELD, + time_field: timeField, type: 'top_n', series: [ { 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 index 32f612d79aaf4..23b9c274b4335 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxActiveConnections: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const nginxActiveConnections: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 883f13ba3cced..3b467bbe52fcd 100644 --- 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 @@ -5,15 +5,18 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const nginxHits: TSVBMetricModelCreator = (indexPattern, interval): TSVBMetricModel => ({ +export const nginxHits: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ id: 'nginxHits', requires: ['nginx.access'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 660c201cdd411..9fbf0c38ba3b8 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestRate: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const nginxRequestRate: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { 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 index 249b0dbd3ac5e..f825dbe7b7543 100644 --- 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 @@ -5,10 +5,10 @@ * 2.0. */ -import { TIMESTAMP_FIELD } from '../../../../constants'; import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( + timeField, indexPattern, interval ): TSVBMetricModel => ({ @@ -16,7 +16,7 @@ export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, - time_field: TIMESTAMP_FIELD, + time_field: timeField, type: 'timeseries', series: [ { diff --git a/x-pack/plugins/infra/common/inventory_models/types.ts b/x-pack/plugins/infra/common/inventory_models/types.ts index 7ca0b69a25be9..35fd7a13a4084 100644 --- a/x-pack/plugins/infra/common/inventory_models/types.ts +++ b/x-pack/plugins/infra/common/inventory_models/types.ts @@ -220,6 +220,7 @@ export const TSVBMetricModelRT = rt.intersection([ export type TSVBMetricModel = rt.TypeOf; export type TSVBMetricModelCreator = ( + timeField: string, indexPattern: string | string[], interval: string ) => TSVBMetricModel; diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index 812012726d68e..e05a5b647ad2b 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { flatten, get } from 'lodash'; import { KibanaRequest } from 'src/core/server'; +import { TIMESTAMP_FIELD } from '../../../../common/constants'; import { NodeDetailsMetricData } from '../../../../common/http_api/node_details_api'; import { KibanaFramework } from '../framework/kibana_framework_adapter'; import { InfraMetricsAdapter, InfraMetricsRequestOptions } from './adapter_types'; @@ -122,7 +123,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { max: options.timerange.to, }; - const model = createTSVBModel(indexPattern, options.timerange.interval); + const model = createTSVBModel(TIMESTAMP_FIELD, indexPattern, options.timerange.interval); const client = ( opts: CallWithRequestParams From bd2f062aa85b3e7aa554d4537c38baa1d556d76d Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:43:23 -0500 Subject: [PATCH 13/21] Revert log_analysis api --- .../infra/common/http_api/log_analysis/validation/datasets.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts index 19f71800ab1b6..ff4ee4fd328da 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts @@ -16,6 +16,7 @@ export const LOG_ANALYSIS_VALIDATE_DATASETS_PATH = export const validateLogEntryDatasetsRequestPayloadRT = rt.type({ data: rt.type({ indices: rt.array(rt.string), + timestampField: rt.string, startTime: rt.number, endTime: rt.number, runtimeMappings: rt.UnknownRecord, From 951160eba0a0c493885aad5a7c1c1680123bf606 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 11:51:38 -0500 Subject: [PATCH 14/21] Fix timefield reference in process list --- .../plugins/infra/common/http_api/host_details/process_list.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/infra/common/http_api/host_details/process_list.ts b/x-pack/plugins/infra/common/http_api/host_details/process_list.ts index 3764a50a0a01a..395b1527379a9 100644 --- a/x-pack/plugins/infra/common/http_api/host_details/process_list.ts +++ b/x-pack/plugins/infra/common/http_api/host_details/process_list.ts @@ -14,7 +14,6 @@ const AggValueRT = rt.type({ export const ProcessListAPIRequestRT = rt.type({ hostTerm: rt.record(rt.string, rt.string), - timefield: rt.string, indexPattern: rt.string, to: rt.number, sortBy: rt.type({ From 077f9c1f137d55dd8127f462e0da22c549af25e6 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 13:24:04 -0500 Subject: [PATCH 15/21] Restore logs page files, fix typecheck on mock --- .../public/pages/logs/log_entry_categories/page_providers.tsx | 1 + .../infra/public/pages/logs/log_entry_rate/page_providers.tsx | 2 ++ .../infra/server/lib/alerting/log_threshold/mocks/index.ts | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx index 1e2f885a936fb..1eed4b6af65e8 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_providers.tsx @@ -40,6 +40,7 @@ export const LogEntryCategoriesPageProviders: React.FunctionComponent = ({ child indexPattern={resolvedSourceConfiguration.indices} sourceId={sourceId} spaceId={space.id} + timestampField={resolvedSourceConfiguration.timestampField} runtimeMappings={resolvedSourceConfiguration.runtimeMappings} > {children} diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx index 5526873da14c9..043ed2501c973 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_providers.tsx @@ -43,12 +43,14 @@ export const LogEntryRatePageProviders: React.FunctionComponent = ({ children }) indexPattern={resolvedSourceConfiguration.indices} sourceId={sourceId} spaceId={space.id} + timestampField={resolvedSourceConfiguration.timestampField} runtimeMappings={resolvedSourceConfiguration.runtimeMappings} > {children} diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts index 296a540b4a920..f02dac2139097 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/mocks/index.ts @@ -17,7 +17,6 @@ export const libsMock = { type: 'index_pattern', indexPatternId: 'some-id', }, - fields: { timestamp: '@timestamp' }, }, }); }, From ed5825a4f09edf355f4fd3dd302ceff613566af2 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 13:28:17 -0500 Subject: [PATCH 16/21] Fix functional test --- .../apis/metrics_ui/log_sources.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts index 5b615c4b18916..516c262429299 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_sources.ts @@ -40,8 +40,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); expect(configuration.logColumns[2]).to.have.key('messageColumn'); @@ -58,10 +56,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, - fields: { - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, logColumns: [ { messageColumn: { @@ -83,8 +77,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); - expect(configuration.fields.timestamp).to.be('TIMESTAMP'); - expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); @@ -111,8 +103,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); @@ -142,10 +132,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }, - fields: { - tiebreaker: 'TIEBREAKER', - timestamp: 'TIMESTAMP', - }, logColumns: [ { messageColumn: { @@ -166,8 +152,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_pattern', indexPatternId: 'kip-id', }); - expect(configuration.fields.timestamp).to.be('TIMESTAMP'); - expect(configuration.fields.tiebreaker).to.be('TIEBREAKER'); expect(configuration.logColumns).to.have.length(1); expect(configuration.logColumns[0]).to.have.key('messageColumn'); }); @@ -189,8 +173,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'index_name', indexName: 'logs-*,filebeat-*,kibana_sample_data_logs*', }); - expect(configuration.fields.timestamp).to.be('@timestamp'); - expect(configuration.fields.tiebreaker).to.be('_doc'); expect(configuration.logColumns).to.have.length(3); expect(configuration.logColumns[0]).to.have.key('timestampColumn'); expect(configuration.logColumns[1]).to.have.key('fieldColumn'); From c3d5af729c7918e50d28e86773a72ffe3382b436 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 13:52:22 -0500 Subject: [PATCH 17/21] Restore inventory models index --- .../infra/common/inventory_models/index.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/infra/common/inventory_models/index.ts b/x-pack/plugins/infra/common/inventory_models/index.ts index 6350e76ca7f29..81f89be8cd6a6 100644 --- a/x-pack/plugins/infra/common/inventory_models/index.ts +++ b/x-pack/plugins/infra/common/inventory_models/index.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { POD_FIELD, HOST_FIELD, CONTAINER_FIELD } from '../constants'; import { host } from './host'; import { pod } from './pod'; import { awsEC2 } from './aws_ec2'; @@ -30,31 +31,23 @@ export const findInventoryModel = (type: InventoryItemType) => { return model; }; -interface InventoryFields { - host: string; - pod: string; - container: string; - timestamp: string; - tiebreaker: string; -} - const LEGACY_TYPES = ['host', 'pod', 'container']; -const getFieldByType = (type: InventoryItemType, fields: InventoryFields) => { +export const getFieldByType = (type: InventoryItemType) => { switch (type) { case 'pod': - return fields.pod; + return POD_FIELD; case 'host': - return fields.host; + return HOST_FIELD; case 'container': - return fields.container; + return CONTAINER_FIELD; } }; -export const findInventoryFields = (type: InventoryItemType, fields?: InventoryFields) => { +export const findInventoryFields = (type: InventoryItemType) => { const inventoryModel = findInventoryModel(type); - if (fields && LEGACY_TYPES.includes(type)) { - const id = getFieldByType(type, fields) || inventoryModel.fields.id; + if (LEGACY_TYPES.includes(type)) { + const id = getFieldByType(type) || inventoryModel.fields.id; return { ...inventoryModel.fields, id, From 245ef337162badad2a65a7597cb3cfa0480337ad Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 14:17:34 -0500 Subject: [PATCH 18/21] Fix typecheck on getFilteredMetrics --- .../pages/metrics/metric_detail/lib/get_filtered_metrics.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts b/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts index 956c85cf2e673..d1ba4502f37c3 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts +++ b/x-pack/plugins/infra/public/pages/metrics/metric_detail/lib/get_filtered_metrics.ts @@ -8,6 +8,7 @@ import { InfraMetadataFeature } from '../../../../../common/http_api/metadata_api'; import { InventoryMetric } from '../../../../../common/inventory_models/types'; import { metrics } from '../../../../../common/inventory_models/metrics'; +import { TIMESTAMP_FIELD } from '../../../../../common/constants'; export const getFilteredMetrics = ( requiredMetrics: InventoryMetric[], @@ -20,7 +21,7 @@ export const getFilteredMetrics = ( const metricModelCreator = metrics.tsvb[metric]; // We just need to get a dummy version of the model so we can filter // using the `requires` attribute. - const metricModel = metricModelCreator('test', '>=1m'); + const metricModel = metricModelCreator(TIMESTAMP_FIELD, 'test', '>=1m'); return metricMetadata.some((m) => m && metricModel.requires.includes(m)); }); }; From 8e8350adf5630ff78bfca841a94180149031868e Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 15:20:37 -0500 Subject: [PATCH 19/21] Look CI if you don't tell me all the type errors at once I can't fix them all --- .../public/containers/logs/log_source/log_source.mock.ts | 5 ----- .../infra/server/routes/log_analysis/validation/datasets.ts | 3 ++- .../services/log_entries/log_entries_search_strategy.test.ts | 5 ----- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts index 6021c728d32af..204fae7dc0f2b 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.ts @@ -73,11 +73,6 @@ export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfi }, logColumns: [], fields: { - container: 'CONTAINER_FIELD', - host: 'HOST_FIELD', - pod: 'POD_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', - timestamp: 'TIMESTAMP_FIELD', message: ['MESSAGE_FIELD'], }, name: sourceId, diff --git a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts index 0f5c5b4cc6195..4237ee2ae9abc 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts @@ -32,13 +32,14 @@ export const initValidateLogAnalysisDatasetsRoute = ({ framework.router.handleLegacyErrors(async (requestContext, request, response) => { try { const { - data: { indices, startTime, endTime, runtimeMappings }, + data: { indices, timestampField, startTime, endTime, runtimeMappings }, } = request.body; const datasets = await Promise.all( indices.map(async (indexName) => { const indexDatasets = await logEntries.getLogEntryDatasets( requestContext, + timestampField, indexName, startTime, endTime, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts index b0d2eeb987861..e48c990d7822f 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts @@ -289,12 +289,7 @@ const createSourceConfigurationMock = (): InfraSource => ({ }, ], fields: { - pod: 'POD_FIELD', - host: 'HOST_FIELD', - container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], - timestamp: 'TIMESTAMP_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, From 2b01e7f322e39b11b4c0e06d9c2d13ff412f392f Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 27 Oct 2021 15:39:32 -0500 Subject: [PATCH 20/21] Maybe this is the last typecheck fix who knows --- .../services/log_entries/log_entry_search_strategy.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts index 1f03878ba6feb..685f11cb00a86 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts @@ -244,12 +244,7 @@ const createSourceConfigurationMock = (): InfraSource => ({ metricsExplorerDefaultView: 'DEFAULT_VIEW', logColumns: [], fields: { - pod: 'POD_FIELD', - host: 'HOST_FIELD', - container: 'CONTAINER_FIELD', message: ['MESSAGE_FIELD'], - timestamp: 'TIMESTAMP_FIELD', - tiebreaker: 'TIEBREAKER_FIELD', }, anomalyThreshold: 20, }, From f362f84192ac06c817f12d7a4baf1bbfe9cd0eed Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Thu, 4 Nov 2021 10:09:32 -0500 Subject: [PATCH 21/21] Restore reading timestamp field from data view --- .../common/log_sources/resolved_log_source_configuration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts index ece3baf4977d6..d3459b30a060e 100644 --- a/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts +++ b/x-pack/plugins/infra/common/log_sources/resolved_log_source_configuration.ts @@ -92,7 +92,7 @@ const resolveKibanaIndexPatternReference = async ( return { indices: indexPattern.title, - timestampField: TIMESTAMP_FIELD, + timestampField: indexPattern.timeFieldName ?? TIMESTAMP_FIELD, tiebreakerField: TIEBREAKER_FIELD, messageField: ['message'], fields: indexPattern.fields,