From 4be6268b732a2dda007fb3c694b830003241cdea Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 12 Apr 2021 09:44:12 +0200 Subject: [PATCH] [Exploratory view] Use index patterns for formatting (#96280) (#96721) --- .../index_patterns/index_pattern.stub.ts | 6 + ...iscover_field_details_footer.test.tsx.snap | 1 + x-pack/plugins/lens/public/index.ts | 2 +- x-pack/plugins/lens/public/mocks.tsx | 2 +- .../{ => apm}/service_latency_config.ts | 10 +- .../{ => apm}/service_throughput_config.ts | 10 +- .../{ => constants}/constants.ts | 19 +-- .../elasticsearch_fieldnames.ts | 0 .../configurations/constants/index.ts | 8 ++ .../{ => constants}/url_constants.ts | 0 .../configurations/default_configs.ts | 20 +-- .../configurations/lens_attributes.test.ts | 15 +-- .../{ => logs}/logs_frequency_config.ts | 4 +- .../{ => metrics}/cpu_usage_config.ts | 8 +- .../{ => metrics}/memory_usage_config.ts | 8 +- .../{ => metrics}/network_activity_config.ts | 8 +- .../configurations/rum/field_formats.ts | 74 +++++++++++ .../{ => rum}/kpi_trends_config.ts | 8 +- .../{ => rum}/performance_dist_config.ts | 10 +- .../synthetics/field_formats.ts | 22 ++++ .../monitor_duration_config.ts | 8 +- .../{ => synthetics}/monitor_pings_config.ts | 4 +- .../{data => test_data}/sample_attribute.ts | 2 +- .../test_index_pattern.json | 0 .../exploratory_view/configurations/utils.ts | 4 +- .../exploratory_view.test.tsx | 2 +- .../exploratory_view/exploratory_view.tsx | 2 +- .../shared/exploratory_view/header/header.tsx | 2 +- .../hooks/use_default_index_pattern.tsx | 2 +- .../hooks/use_init_exploratory_view.ts | 13 +- .../hooks/use_lens_attributes.ts | 2 +- .../hooks/use_series_filters.ts | 2 +- ...e_url_strorage.tsx => use_url_storage.tsx} | 2 +- .../shared/exploratory_view/index.tsx | 2 +- .../shared/exploratory_view/rtl_helpers.tsx | 6 +- .../columns/data_types_col.test.tsx | 2 +- .../series_builder/columns/data_types_col.tsx | 2 +- .../columns/report_breakdowns.test.tsx | 4 +- .../columns/report_breakdowns.tsx | 2 +- .../columns/report_definition_col.test.tsx | 4 +- .../columns/report_definition_col.tsx | 3 +- .../columns/report_filters.test.tsx | 2 +- .../series_builder/columns/report_filters.tsx | 2 +- .../columns/report_types_col.tsx | 2 +- .../series_builder/custom_report_field.tsx | 2 +- .../series_builder/series_builder.tsx | 2 +- .../series_date_picker/index.tsx | 2 +- .../series_editor/columns/breakdowns.test.tsx | 4 +- .../series_editor/columns/breakdowns.tsx | 2 +- .../series_editor/columns/chart_types.tsx | 2 +- .../columns/filter_expanded.test.tsx | 2 +- .../series_editor/columns/filter_expanded.tsx | 2 +- .../columns/filter_value_btn.test.tsx | 2 +- .../columns/filter_value_btn.tsx | 2 +- .../columns/metric_selection.tsx | 6 +- .../series_editor/columns/remove_series.tsx | 2 +- .../series_editor/columns/series_filter.tsx | 4 +- .../series_editor/selected_filters.test.tsx | 4 +- .../series_editor/selected_filters.tsx | 2 +- .../series_editor/series_editor.tsx | 2 +- .../shared/exploratory_view/types.ts | 19 +++ .../observability_index_patterns.test.ts | 95 ++++++++++++++ .../utils/observability_index_patterns.ts | 124 ++++++++++++++++++ .../field_value_selection.tsx | 1 + 64 files changed, 469 insertions(+), 123 deletions(-) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => apm}/service_latency_config.ts (82%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => apm}/service_throughput_config.ts (82%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => constants}/constants.ts (80%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{data => constants}/elasticsearch_fieldnames.ts (100%) create mode 100644 x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/index.ts rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => constants}/url_constants.ts (100%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => logs}/logs_frequency_config.ts (90%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => metrics}/cpu_usage_config.ts (82%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => metrics}/memory_usage_config.ts (82%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => metrics}/network_activity_config.ts (81%) create mode 100644 x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/field_formats.ts rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => rum}/kpi_trends_config.ts (90%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => rum}/performance_dist_config.ts (90%) create mode 100644 x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/field_formats.ts rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => synthetics}/monitor_duration_config.ts (83%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{ => synthetics}/monitor_pings_config.ts (92%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{data => test_data}/sample_attribute.ts (98%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/{data => test_data}/test_index_pattern.json (100%) rename x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/{use_url_strorage.tsx => use_url_storage.tsx} (97%) create mode 100644 x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.test.ts create mode 100644 x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.ts diff --git a/src/plugins/data/public/index_patterns/index_pattern.stub.ts b/src/plugins/data/public/index_patterns/index_pattern.stub.ts index fa33f00a49879..36569cafd6611 100644 --- a/src/plugins/data/public/index_patterns/index_pattern.stub.ts +++ b/src/plugins/data/public/index_patterns/index_pattern.stub.ts @@ -9,6 +9,7 @@ import sinon from 'sinon'; import { CoreSetup } from 'src/core/public'; +import { SerializedFieldFormat } from 'src/plugins/expressions/public'; import { IFieldType, FieldSpec } from '../../common/index_patterns'; import { IndexPattern, indexPatterns, KBN_FIELD_TYPES, fieldList } from '../'; import { getFieldFormatsRegistry } from '../test_utils'; @@ -51,6 +52,7 @@ export class StubIndexPattern { _reindexFields: Function; stubSetFieldFormat: Function; fields?: FieldSpec[]; + setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; constructor( pattern: string, @@ -74,6 +76,10 @@ export class StubIndexPattern { this.metaFields = ['_id', '_type', '_source']; this.fieldFormatMap = {}; + this.setFieldFormat = (fieldName: string, format: SerializedFieldFormat) => { + this.fieldFormatMap[fieldName] = format; + }; + this.getComputedFields = IndexPattern.prototype.getComputedFields.bind(this); this.flattenHit = indexPatterns.flattenHitWrapper( (this as unknown) as IndexPattern, diff --git a/src/plugins/discover/public/application/components/sidebar/__snapshots__/discover_field_details_footer.test.tsx.snap b/src/plugins/discover/public/application/components/sidebar/__snapshots__/discover_field_details_footer.test.tsx.snap index f3c8990388024..f976b961d8520 100644 --- a/src/plugins/discover/public/application/components/sidebar/__snapshots__/discover_field_details_footer.test.tsx.snap +++ b/src/plugins/discover/public/application/components/sidebar/__snapshots__/discover_field_details_footer.test.tsx.snap @@ -543,6 +543,7 @@ exports[`discover sidebar field details footer renders properly 1`] = ` "_source", ], "popularizeField": [Function], + "setFieldFormat": [Function], "stubSetFieldFormat": [Function], "timeFieldName": "time", "title": "logstash-*", diff --git a/x-pack/plugins/lens/public/index.ts b/x-pack/plugins/lens/public/index.ts index 9b53e59f96792..cedb648215c0e 100644 --- a/x-pack/plugins/lens/public/index.ts +++ b/x-pack/plugins/lens/public/index.ts @@ -21,7 +21,7 @@ export type { YAxisMode, XYCurveType, } from './xy_visualization/types'; -export type { DataType } from './types'; +export type { DataType, OperationMetadata } from './types'; export type { PieVisualizationState, PieLayerState, diff --git a/x-pack/plugins/lens/public/mocks.tsx b/x-pack/plugins/lens/public/mocks.tsx index 743846d81213c..c1f885d167659 100644 --- a/x-pack/plugins/lens/public/mocks.tsx +++ b/x-pack/plugins/lens/public/mocks.tsx @@ -18,7 +18,7 @@ const createStartContract = (): Start => { }), canUseEditor: jest.fn(() => true), navigateToPrefilledEditor: jest.fn(), - getXyVisTypes: jest.fn().mockReturnValue(new Promise(() => visualizationTypes)), + getXyVisTypes: jest.fn().mockReturnValue(new Promise((resolve) => resolve(visualizationTypes))), }; return startContract; }; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_latency_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_latency_config.ts similarity index 82% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_latency_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_latency_config.ts index a31679c61a4ab..3fcf98f712bef 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_latency_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_latency_config.ts @@ -5,10 +5,10 @@ * 2.0. */ -import { ConfigProps, DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { buildPhraseFilter } from './utils'; -import { OperationType } from '../../../../../../lens/public'; +import { ConfigProps, DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { buildPhraseFilter } from '../utils'; +import { OperationType } from '../../../../../../../lens/public'; export function getServiceLatencyLensConfig({ seriesId, indexPattern }: ConfigProps): DataSeries { return { @@ -20,7 +20,7 @@ export function getServiceLatencyLensConfig({ seriesId, indexPattern }: ConfigPr sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'transaction.duration.us', label: 'Latency', }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_throughput_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_throughput_config.ts similarity index 82% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_throughput_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_throughput_config.ts index 32cae2167ddf0..c0f3d6dc9b010 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/service_throughput_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/apm/service_throughput_config.ts @@ -5,10 +5,10 @@ * 2.0. */ -import { ConfigProps, DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { buildPhraseFilter } from './utils'; -import { OperationType } from '../../../../../../lens/public'; +import { ConfigProps, DataSeries } from '../../types'; +import { FieldLabels } from '../constants/constants'; +import { buildPhraseFilter } from '../utils'; +import { OperationType } from '../../../../../../../lens/public'; export function getServiceThroughputLensConfig({ seriesId, @@ -23,7 +23,7 @@ export function getServiceThroughputLensConfig({ sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'transaction.duration.us', label: 'Throughput', }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/constants.ts similarity index 80% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/constants.ts index aa3ac2fa64317..ed849c1eb47b3 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/constants.ts @@ -5,14 +5,8 @@ * 2.0. */ -import { AppDataType, ReportViewTypeId } from '../types'; -import { - CLS_FIELD, - FCP_FIELD, - FID_FIELD, - LCP_FIELD, - TBT_FIELD, -} from './data/elasticsearch_fieldnames'; +import { AppDataType, ReportViewTypeId } from '../../types'; +import { CLS_FIELD, FCP_FIELD, FID_FIELD, LCP_FIELD, TBT_FIELD } from './elasticsearch_fieldnames'; export const FieldLabels: Record = { 'user_agent.name': 'Browser family', @@ -24,10 +18,10 @@ export const FieldLabels: Record = { 'service.name': 'Service Name', 'service.environment': 'Environment', - [LCP_FIELD]: 'Largest contentful paint', - [FCP_FIELD]: 'First contentful paint', - [TBT_FIELD]: 'Total blocking time', - [FID_FIELD]: 'First input delay', + [LCP_FIELD]: 'Largest contentful paint (Seconds)', + [FCP_FIELD]: 'First contentful paint (Seconds)', + [TBT_FIELD]: 'Total blocking time (Seconds)', + [FID_FIELD]: 'First input delay (Seconds)', [CLS_FIELD]: 'Cumulative layout shift', 'monitor.id': 'Monitor Id', @@ -38,6 +32,7 @@ export const FieldLabels: Record = { 'monitor.name': 'Monitor name', 'monitor.type': 'Monitor Type', 'url.port': 'Port', + 'url.full': 'Url', tags: 'Tags', // custom diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/elasticsearch_fieldnames.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/elasticsearch_fieldnames.ts similarity index 100% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/elasticsearch_fieldnames.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/elasticsearch_fieldnames.ts diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/index.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/index.ts new file mode 100644 index 0000000000000..63661f0d5a996 --- /dev/null +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export * from './constants'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/url_constants.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/url_constants.ts similarity index 100% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/url_constants.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/constants/url_constants.ts diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/default_configs.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/default_configs.ts index 85d48ef638d44..2c5b4ebea0ab3 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/default_configs.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/default_configs.ts @@ -6,16 +6,16 @@ */ import { ReportViewTypes } from '../types'; -import { getPerformanceDistLensConfig } from './performance_dist_config'; -import { getMonitorDurationConfig } from './monitor_duration_config'; -import { getServiceLatencyLensConfig } from './service_latency_config'; -import { getMonitorPingsConfig } from './monitor_pings_config'; -import { getServiceThroughputLensConfig } from './service_throughput_config'; -import { getKPITrendsLensConfig } from './kpi_trends_config'; -import { getCPUUsageLensConfig } from './cpu_usage_config'; -import { getMemoryUsageLensConfig } from './memory_usage_config'; -import { getNetworkActivityLensConfig } from './network_activity_config'; -import { getLogsFrequencyLensConfig } from './logs_frequency_config'; +import { getPerformanceDistLensConfig } from './rum/performance_dist_config'; +import { getMonitorDurationConfig } from './synthetics/monitor_duration_config'; +import { getServiceLatencyLensConfig } from './apm/service_latency_config'; +import { getMonitorPingsConfig } from './synthetics/monitor_pings_config'; +import { getServiceThroughputLensConfig } from './apm/service_throughput_config'; +import { getKPITrendsLensConfig } from './rum/kpi_trends_config'; +import { getCPUUsageLensConfig } from './metrics/cpu_usage_config'; +import { getMemoryUsageLensConfig } from './metrics/memory_usage_config'; +import { getNetworkActivityLensConfig } from './metrics/network_activity_config'; +import { getLogsFrequencyLensConfig } from './logs/logs_frequency_config'; import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns'; interface Props { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts index dcfaed938cc0f..139f3ab0d82ed 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/lens_attributes.test.ts @@ -8,9 +8,8 @@ import { LensAttributes } from './lens_attributes'; import { mockIndexPattern } from '../rtl_helpers'; import { getDefaultConfigs } from './default_configs'; -import { sampleAttribute } from './data/sample_attribute'; -import { LCP_FIELD, SERVICE_NAME } from './data/elasticsearch_fieldnames'; -import { USER_AGENT_NAME } from './data/elasticsearch_fieldnames'; +import { sampleAttribute } from './test_data/sample_attribute'; +import { LCP_FIELD, SERVICE_NAME, USER_AGENT_NAME } from './constants/elasticsearch_fieldnames'; describe('Lens Attribute', () => { const reportViewConfig = getDefaultConfigs({ @@ -93,7 +92,7 @@ describe('Lens Attribute', () => { expect(lnsAttr.getNumberColumn('transaction.duration.us')).toEqual({ dataType: 'number', isBucketed: true, - label: 'Page load time', + label: 'Page load time (Seconds)', operationType: 'range', params: { maxBars: 'auto', @@ -129,7 +128,7 @@ describe('Lens Attribute', () => { expect(lnsAttr.getXAxis()).toEqual({ dataType: 'number', isBucketed: true, - label: 'Page load time', + label: 'Page load time (Seconds)', operationType: 'range', params: { maxBars: 'auto', @@ -154,7 +153,7 @@ describe('Lens Attribute', () => { 'x-axis-column': { dataType: 'number', isBucketed: true, - label: 'Page load time', + label: 'Page load time (Seconds)', operationType: 'range', params: { maxBars: 'auto', @@ -318,7 +317,7 @@ describe('Lens Attribute', () => { 'x-axis-column': { dataType: 'number', isBucketed: true, - label: 'Page load time', + label: 'Page load time (Seconds)', operationType: 'range', params: { maxBars: 'auto', @@ -363,7 +362,7 @@ describe('Lens Attribute', () => { 'x-axis-column': { dataType: 'number', isBucketed: true, - label: 'Page load time', + label: 'Page load time (Seconds)', operationType: 'range', params: { maxBars: 'auto', diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs_frequency_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs/logs_frequency_config.ts similarity index 90% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs_frequency_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs/logs_frequency_config.ts index 68e5e697d2f9d..8a27d7ddd428b 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs_frequency_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/logs/logs_frequency_config.ts @@ -5,8 +5,8 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; interface Props { seriesId: string; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/cpu_usage_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/cpu_usage_config.ts similarity index 82% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/cpu_usage_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/cpu_usage_config.ts index 5a4fb2aa3a6a5..6214975d8f1dd 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/cpu_usage_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/cpu_usage_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { OperationType } from '../../../../../../lens/public'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { OperationType } from '../../../../../../../lens/public'; interface Props { seriesId: string; @@ -23,7 +23,7 @@ export function getCPUUsageLensConfig({ seriesId }: Props): DataSeries { sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'system.cpu.user.pct', label: 'CPU Usage %', }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/memory_usage_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/memory_usage_config.ts similarity index 82% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/memory_usage_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/memory_usage_config.ts index 579372ed86fa7..6f46c175f7882 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/memory_usage_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/memory_usage_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { OperationType } from '../../../../../../lens/public'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { OperationType } from '../../../../../../../lens/public'; interface Props { seriesId: string; @@ -23,7 +23,7 @@ export function getMemoryUsageLensConfig({ seriesId }: Props): DataSeries { sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'system.memory.used.pct', label: 'Memory Usage %', }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/network_activity_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/network_activity_config.ts similarity index 81% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/network_activity_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/network_activity_config.ts index 63cdd0ec8bd60..1bc9fed9c3f80 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/network_activity_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/metrics/network_activity_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { OperationType } from '../../../../../../lens/public'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { OperationType } from '../../../../../../../lens/public'; interface Props { seriesId: string; @@ -23,7 +23,7 @@ export function getNetworkActivityLensConfig({ seriesId }: Props): DataSeries { sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'system.memory.used.pct', }, hasMetricType: true, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/field_formats.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/field_formats.ts new file mode 100644 index 0000000000000..f1fc5f310b8ef --- /dev/null +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/field_formats.ts @@ -0,0 +1,74 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FieldFormat } from '../../types'; +import { + FCP_FIELD, + FID_FIELD, + LCP_FIELD, + TBT_FIELD, + TRANSACTION_DURATION, +} from '../constants/elasticsearch_fieldnames'; + +export const rumFieldFormats: FieldFormat[] = [ + { + field: TRANSACTION_DURATION, + format: { + id: 'duration', + params: { + inputFormat: 'microseconds', + outputFormat: 'asSeconds', + showSuffix: true, + outputPrecision: 1, + }, + }, + }, + { + field: FCP_FIELD, + format: { + id: 'duration', + params: { + inputFormat: 'milliseconds', + outputFormat: 'asSeconds', + showSuffix: true, + }, + }, + }, + { + field: LCP_FIELD, + format: { + id: 'duration', + params: { + inputFormat: 'milliseconds', + outputFormat: 'asSeconds', + showSuffix: true, + }, + }, + }, + { + field: TBT_FIELD, + format: { + id: 'duration', + params: { + inputFormat: 'milliseconds', + outputFormat: 'asSeconds', + showSuffix: true, + }, + }, + }, + { + field: FID_FIELD, + format: { + id: 'duration', + params: { + inputFormat: 'milliseconds', + outputFormat: 'asSeconds', + showSuffix: true, + }, + }, + }, +]; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/kpi_trends_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/kpi_trends_config.ts similarity index 90% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/kpi_trends_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/kpi_trends_config.ts index a967a8824bca7..a1a3acd51f89c 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/kpi_trends_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/kpi_trends_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { ConfigProps, DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { buildPhraseFilter } from './utils'; +import { ConfigProps, DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { buildPhraseFilter } from '../utils'; import { CLIENT_GEO_COUNTRY_NAME, PROCESSOR_EVENT, @@ -18,7 +18,7 @@ import { USER_AGENT_NAME, USER_AGENT_OS, USER_AGENT_VERSION, -} from './data/elasticsearch_fieldnames'; +} from '../constants/elasticsearch_fieldnames'; export function getKPITrendsLensConfig({ seriesId, indexPattern }: ConfigProps): DataSeries { return { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/performance_dist_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/performance_dist_config.ts similarity index 90% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/performance_dist_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/performance_dist_config.ts index 41617304c9f3d..7005dea29d60d 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/performance_dist_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/rum/performance_dist_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { ConfigProps, DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { buildPhraseFilter } from './utils'; +import { ConfigProps, DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; +import { buildPhraseFilter } from '../utils'; import { CLIENT_GEO_COUNTRY_NAME, CLS_FIELD, @@ -24,7 +24,7 @@ import { USER_AGENT_NAME, USER_AGENT_OS, USER_AGENT_VERSION, -} from './data/elasticsearch_fieldnames'; +} from '../constants/elasticsearch_fieldnames'; export function getPerformanceDistLensConfig({ seriesId, indexPattern }: ConfigProps): DataSeries { return { @@ -80,7 +80,7 @@ export function getPerformanceDistLensConfig({ seriesId, indexPattern }: ConfigP labels: { ...FieldLabels, [SERVICE_NAME]: 'Web Application', - [TRANSACTION_DURATION]: 'Page load time', + [TRANSACTION_DURATION]: 'Page load time (Seconds)', }, }; } diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/field_formats.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/field_formats.ts new file mode 100644 index 0000000000000..4f036f0b9be65 --- /dev/null +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/field_formats.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FieldFormat } from '../../types'; + +export const syntheticsFieldFormats: FieldFormat[] = [ + { + field: 'monitor.duration.us', + format: { + id: 'duration', + params: { + inputFormat: 'microseconds', + outputFormat: 'asMilliseconds', + outputPrecision: 0, + }, + }, + }, +]; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_duration_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_duration_config.ts similarity index 83% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_duration_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_duration_config.ts index aa9b8b94c6d86..f0ec3f0c31bef 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_duration_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_duration_config.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; -import { OperationType } from '../../../../../../lens/public'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants/constants'; +import { OperationType } from '../../../../../../../lens/public'; interface Props { seriesId: string; @@ -23,7 +23,7 @@ export function getMonitorDurationConfig({ seriesId }: Props): DataSeries { sourceField: '@timestamp', }, yAxisColumn: { - operationType: 'avg' as OperationType, + operationType: 'average' as OperationType, sourceField: 'monitor.duration.us', label: 'Monitor duration (ms)', }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_pings_config.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_pings_config.ts similarity index 92% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_pings_config.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_pings_config.ts index 72968626e934b..40c9f5750fb4d 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/monitor_pings_config.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/synthetics/monitor_pings_config.ts @@ -5,8 +5,8 @@ * 2.0. */ -import { DataSeries } from '../types'; -import { FieldLabels } from './constants'; +import { DataSeries } from '../../types'; +import { FieldLabels } from '../constants'; interface Props { seriesId: string; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/sample_attribute.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts similarity index 98% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/sample_attribute.ts rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts index 9b299e7d70bcc..ffce81207472f 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/sample_attribute.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/sample_attribute.ts @@ -21,7 +21,7 @@ export const sampleAttribute = { columns: { 'x-axis-column': { sourceField: 'transaction.duration.us', - label: 'Page load time', + label: 'Page load time (Seconds)', dataType: 'number', operationType: 'range', isBucketed: true, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/test_index_pattern.json b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/test_index_pattern.json similarity index 100% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/data/test_index_pattern.json rename to x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/test_data/test_index_pattern.json diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts index 38b8ce81b2acd..c885673134786 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/configurations/utils.ts @@ -5,11 +5,11 @@ * 2.0. */ import rison, { RisonValue } from 'rison-node'; -import type { AllSeries, AllShortSeries } from '../hooks/use_url_strorage'; +import type { AllSeries, AllShortSeries } from '../hooks/use_url_storage'; import type { SeriesUrl } from '../types'; import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns'; import { esFilters } from '../../../../../../../../src/plugins/data/public'; -import { URL_KEYS } from './url_constants'; +import { URL_KEYS } from './constants/url_constants'; export function convertToShortUrl(series: SeriesUrl) { const { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.test.tsx index b90d5115bc41e..257eb3a739f0f 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.test.tsx @@ -10,7 +10,7 @@ import { fireEvent, screen, waitFor } from '@testing-library/dom'; import { render, mockUrlStorage, mockCore } from './rtl_helpers'; import { ExploratoryView } from './exploratory_view'; import { getStubIndexPattern } from '../../../../../../../src/plugins/data/public/test_utils'; -import * as obsvInd from '../../../utils/observability_index_patterns'; +import * as obsvInd from './utils/observability_index_patterns'; describe('ExploratoryView', () => { beforeEach(() => { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.tsx index b3ad107bbe0e2..0e7bc80e8659c 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/exploratory_view.tsx @@ -12,7 +12,7 @@ import { useKibana } from '../../../../../../../src/plugins/kibana_react/public' import { ObservabilityPublicPluginsStart } from '../../../plugin'; import { ExploratoryViewHeader } from './header/header'; import { SeriesEditor } from './series_editor/series_editor'; -import { useUrlStorage } from './hooks/use_url_strorage'; +import { useUrlStorage } from './hooks/use_url_storage'; import { useLensAttributes } from './hooks/use_lens_attributes'; import { EmptyView } from './components/empty_view'; import { useIndexPatternContext } from './hooks/use_default_index_pattern'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/header/header.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/header/header.tsx index bda3566c76602..17f06436c8535 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/header/header.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/header/header.tsx @@ -12,7 +12,7 @@ import { TypedLensByValueInput } from '../../../../../../lens/public'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { ObservabilityPublicPluginsStart } from '../../../../plugin'; import { DataViewLabels } from '../configurations/constants'; -import { useUrlStorage } from '../hooks/use_url_strorage'; +import { useUrlStorage } from '../hooks/use_url_storage'; interface Props { seriesId: string; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_default_index_pattern.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_default_index_pattern.tsx index 04cbb4a4ddb18..7ead7d5e3cfad 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_default_index_pattern.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_default_index_pattern.tsx @@ -10,7 +10,7 @@ import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; import { AppDataType } from '../types'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { ObservabilityPublicPluginsStart } from '../../../../plugin'; -import { ObservabilityIndexPatterns } from '../../../../utils/observability_index_patterns'; +import { ObservabilityIndexPatterns } from '../utils/observability_index_patterns'; export interface IIndexPatternContext { indexPattern: IndexPattern; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_init_exploratory_view.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_init_exploratory_view.ts index 9f462790e8d37..76fd64ef86736 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_init_exploratory_view.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_init_exploratory_view.ts @@ -8,12 +8,9 @@ import { useFetcher } from '../../../..'; import { IKbnUrlStateStorage } from '../../../../../../../../src/plugins/kibana_utils/public'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { ObservabilityPublicPluginsStart } from '../../../../plugin'; -import { AllShortSeries } from './use_url_strorage'; +import { AllShortSeries } from './use_url_storage'; import { ReportToDataTypeMap } from '../configurations/constants'; -import { - DataType, - ObservabilityIndexPatterns, -} from '../../../../utils/observability_index_patterns'; +import { DataType, ObservabilityIndexPatterns } from '../utils/observability_index_patterns'; export const useInitExploratoryView = (storage: IKbnUrlStateStorage) => { const { @@ -30,7 +27,7 @@ export const useInitExploratoryView = (storage: IKbnUrlStateStorage) => { const firstSeries = allSeries[firstSeriesId]; - const { data: indexPattern } = useFetcher(() => { + const { data: indexPattern, error } = useFetcher(() => { const obsvIndexP = new ObservabilityIndexPatterns(data); let reportType: DataType = 'apm'; if (firstSeries?.rt) { @@ -40,5 +37,9 @@ export const useInitExploratoryView = (storage: IKbnUrlStateStorage) => { return obsvIndexP.getIndexPattern(reportType); }, [firstSeries?.rt, data]); + if (error) { + throw error; + } + return indexPattern; }; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_lens_attributes.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_lens_attributes.ts index 1c735009f66f9..274542380c137 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_lens_attributes.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_lens_attributes.ts @@ -8,7 +8,7 @@ import { useMemo } from 'react'; import { TypedLensByValueInput } from '../../../../../../lens/public'; import { LensAttributes } from '../configurations/lens_attributes'; -import { useUrlStorage } from './use_url_strorage'; +import { useUrlStorage } from './use_url_storage'; import { getDefaultConfigs } from '../configurations/default_configs'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_series_filters.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_series_filters.ts index 35247180c2ee5..34f0a7c1a7f86 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_series_filters.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_series_filters.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { useUrlStorage } from './use_url_strorage'; +import { useUrlStorage } from './use_url_storage'; import { UrlFilter } from '../types'; export interface UpdateFilter { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_strorage.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_storage.tsx similarity index 97% rename from x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_strorage.tsx rename to x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_storage.tsx index d38429703b709..6256b3b134f8c 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_strorage.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_url_storage.tsx @@ -10,7 +10,7 @@ import { IKbnUrlStateStorage } from '../../../../../../../../src/plugins/kibana_ import type { AppDataType, ReportViewTypeId, SeriesUrl, UrlFilter } from '../types'; import { convertToShortUrl } from '../configurations/utils'; import { OperationType, SeriesType } from '../../../../../../lens/public'; -import { URL_KEYS } from '../configurations/url_constants'; +import { URL_KEYS } from '../configurations/constants/url_constants'; export const UrlStorageContext = createContext(null); diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/index.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/index.tsx index dc47a0f075fe6..f903c4d7d44fb 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/index.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/index.tsx @@ -18,7 +18,7 @@ import { createKbnUrlStateStorage, withNotifyOnErrors, } from '../../../../../../../src/plugins/kibana_utils/public/'; -import { UrlStorageContextProvider } from './hooks/use_url_strorage'; +import { UrlStorageContextProvider } from './hooks/use_url_storage'; import { useInitExploratoryView } from './hooks/use_init_exploratory_view'; import { WithHeaderLayout } from '../../app/layout/with_header'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/rtl_helpers.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/rtl_helpers.tsx index 112bfcc3ccb58..b826409dd9e3a 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/rtl_helpers.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/rtl_helpers.tsx @@ -23,20 +23,20 @@ import { ObservabilityPublicPluginsStart } from '../../../plugin'; import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common'; import { lensPluginMock } from '../../../../../lens/public/mocks'; import { IndexPatternContextProvider } from './hooks/use_default_index_pattern'; -import { AllSeries, UrlStorageContextProvider } from './hooks/use_url_strorage'; +import { AllSeries, UrlStorageContextProvider } from './hooks/use_url_storage'; import { withNotifyOnErrors, createKbnUrlStateStorage, } from '../../../../../../../src/plugins/kibana_utils/public'; import * as fetcherHook from '../../../hooks/use_fetcher'; -import * as useUrlHook from './hooks/use_url_strorage'; +import * as useUrlHook from './hooks/use_url_storage'; import * as useSeriesFilterHook from './hooks/use_series_filters'; import * as useHasDataHook from '../../../hooks/use_has_data'; import * as useValuesListHook from '../../../hooks/use_values_list'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getStubIndexPattern } from '../../../../../../../src/plugins/data/public/index_patterns/index_pattern.stub'; -import indexPatternData from './configurations/data/test_index_pattern.json'; +import indexPatternData from './configurations/test_data/test_index_pattern.json'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { setIndexPatterns } from '../../../../../../../src/plugins/data/public/services'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.test.tsx index d33d8515d3bee..039cdfc9b73f5 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { fireEvent, screen } from '@testing-library/react'; import { mockUrlStorage, render } from '../../rtl_helpers'; import { dataTypes, DataTypesCol } from './data_types_col'; -import { NEW_SERIES_KEY } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY } from '../../hooks/use_url_storage'; describe('DataTypesCol', function () { it('should render properly', function () { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.tsx index 7ea44e66a721a..b6464bbe3c6ed 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/data_types_col.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { AppDataType } from '../../types'; import { useIndexPatternContext } from '../../hooks/use_default_index_pattern'; -import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_storage'; export const dataTypes: Array<{ id: AppDataType; label: string }> = [ { id: 'synthetics', label: 'Synthetic Monitoring' }, diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.test.tsx index dba660fff9c36..553aff57ad491 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.test.tsx @@ -10,9 +10,9 @@ import { fireEvent, screen } from '@testing-library/react'; import { render } from '../../../../../utils/test_helper'; import { getDefaultConfigs } from '../../configurations/default_configs'; import { mockIndexPattern, mockUrlStorage } from '../../rtl_helpers'; -import { NEW_SERIES_KEY } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY } from '../../hooks/use_url_storage'; import { ReportBreakdowns } from './report_breakdowns'; -import { USER_AGENT_OS } from '../../configurations/data/elasticsearch_fieldnames'; +import { USER_AGENT_OS } from '../../configurations/constants/elasticsearch_fieldnames'; describe('Series Builder ReportBreakdowns', function () { const dataViewSeries = getDefaultConfigs({ diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.tsx index 7667cea417a52..619e2ec4fe9b0 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_breakdowns.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { Breakdowns } from '../../series_editor/columns/breakdowns'; -import { NEW_SERIES_KEY } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY } from '../../hooks/use_url_storage'; import { DataSeries } from '../../types'; export function ReportBreakdowns({ dataViewSeries }: { dataViewSeries: DataSeries }) { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.test.tsx index 2fda581154166..104a8fcefb49f 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.test.tsx @@ -9,9 +9,9 @@ import React from 'react'; import { fireEvent, screen } from '@testing-library/react'; import { getDefaultConfigs } from '../../configurations/default_configs'; import { mockIndexPattern, mockUrlStorage, mockUseValuesList, render } from '../../rtl_helpers'; -import { NEW_SERIES_KEY } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY } from '../../hooks/use_url_storage'; import { ReportDefinitionCol } from './report_definition_col'; -import { SERVICE_NAME } from '../../configurations/data/elasticsearch_fieldnames'; +import { SERVICE_NAME } from '../../configurations/constants/elasticsearch_fieldnames'; describe('Series Builder ReportDefinitionCol', function () { const dataViewSeries = getDefaultConfigs({ diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.tsx index ce11c869de0ab..b907efb57d5c2 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/columns/report_definition_col.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { EuiBadge, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { useIndexPatternContext } from '../../hooks/use_default_index_pattern'; -import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_storage'; import { CustomReportField } from '../custom_report_field'; import FieldValueSuggestions from '../../../field_value_suggestions'; import { DataSeries } from '../../types'; @@ -67,6 +67,7 @@ export function ReportDefinitionCol({ dataViewSeries }: { dataViewSeries: DataSe {rtd?.[field] && ( ; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/custom_report_field.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/custom_report_field.tsx index 6039fd4cba280..4d5033eca241b 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/custom_report_field.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/custom_report_field.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { EuiSuperSelect } from '@elastic/eui'; -import { useUrlStorage } from '../hooks/use_url_strorage'; +import { useUrlStorage } from '../hooks/use_url_storage'; import { ReportDefinition } from '../types'; interface Props { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/series_builder.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/series_builder.tsx index 983c18af031d0..053f301529635 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/series_builder.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_builder/series_builder.tsx @@ -16,7 +16,7 @@ import { ReportTypesCol } from './columns/report_types_col'; import { ReportDefinitionCol } from './columns/report_definition_col'; import { ReportFilters } from './columns/report_filters'; import { ReportBreakdowns } from './columns/report_breakdowns'; -import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_storage'; import { useIndexPatternContext } from '../hooks/use_default_index_pattern'; import { getDefaultConfigs } from '../configurations/default_configs'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_date_picker/index.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_date_picker/index.tsx index 71e3317ad6db8..922d33ffd39ac 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_date_picker/index.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_date_picker/index.tsx @@ -8,7 +8,7 @@ import { EuiSuperDatePicker } from '@elastic/eui'; import React, { useEffect } from 'react'; import { useHasData } from '../../../../hooks/use_has_data'; -import { useUrlStorage } from '../hooks/use_url_strorage'; +import { useUrlStorage } from '../hooks/use_url_storage'; import { useQuickTimeRanges } from '../../../../hooks/use_quick_time_ranges'; export interface TimePickerTime { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.test.tsx index 654a93a08a7c8..0824f13e6b3fe 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.test.tsx @@ -9,9 +9,9 @@ import React from 'react'; import { fireEvent, screen } from '@testing-library/react'; import { Breakdowns } from './breakdowns'; import { mockIndexPattern, mockUrlStorage, render } from '../../rtl_helpers'; -import { NEW_SERIES_KEY } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY } from '../../hooks/use_url_storage'; import { getDefaultConfigs } from '../../configurations/default_configs'; -import { USER_AGENT_OS } from '../../configurations/data/elasticsearch_fieldnames'; +import { USER_AGENT_OS } from '../../configurations/constants/elasticsearch_fieldnames'; describe('Breakdowns', function () { const dataViewSeries = getDefaultConfigs({ diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.tsx index 0d34d7245725a..5561779daa8c4 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/breakdowns.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { EuiSuperSelect } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FieldLabels } from '../../configurations/constants'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; interface Props { seriesId: string; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/chart_types.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/chart_types.tsx index 017655053eef2..f83630cff414a 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/chart_types.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/chart_types.tsx @@ -19,7 +19,7 @@ import styled from 'styled-components'; import { useKibana } from '../../../../../../../../../src/plugins/kibana_react/public'; import { ObservabilityPublicPluginsStart } from '../../../../../plugin'; import { useFetcher } from '../../../../..'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; import { SeriesType } from '../../../../../../../lens/public'; export function SeriesChartTypes({ diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.test.tsx index edd5546f13940..530b8dee3a4d2 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { fireEvent, screen } from '@testing-library/react'; import { FilterExpanded } from './filter_expanded'; import { mockUrlStorage, mockUseValuesList, render } from '../../rtl_helpers'; -import { USER_AGENT_NAME } from '../../configurations/data/elasticsearch_fieldnames'; +import { USER_AGENT_NAME } from '../../configurations/constants/elasticsearch_fieldnames'; describe('FilterExpanded', function () { it('should render properly', async function () { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.tsx index 280912dd0902f..3e6d7890f4c81 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_expanded.tsx @@ -14,7 +14,7 @@ import { EuiFilterGroup, } from '@elastic/eui'; import { useIndexPatternContext } from '../../hooks/use_default_index_pattern'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; import { UrlFilter } from '../../types'; import { FilterValueButton } from './filter_value_btn'; import { useValuesList } from '../../../../../hooks/use_values_list'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.test.tsx index 7f76c9ea999ee..befbb3b74d6d7 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.test.tsx @@ -12,7 +12,7 @@ import { mockUrlStorage, mockUseSeriesFilter, mockUseValuesList, render } from ' import { USER_AGENT_NAME, USER_AGENT_VERSION, -} from '../../configurations/data/elasticsearch_fieldnames'; +} from '../../configurations/constants/elasticsearch_fieldnames'; describe('FilterValueButton', function () { it('should render properly', async function () { diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.tsx index 42cdfd595e66b..efccb351c2619 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/filter_value_btn.tsx @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import React, { useMemo } from 'react'; import { EuiFilterButton, hexToRgb } from '@elastic/eui'; import { useIndexPatternContext } from '../../hooks/use_default_index_pattern'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; import { useSeriesFilters } from '../../hooks/use_series_filters'; import { euiStyled } from '../../../../../../../../../src/plugins/kibana_react/common'; import FieldValueSuggestions from '../../../field_value_suggestions'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/metric_selection.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/metric_selection.tsx index e01e371b5eeeb..fa4202d2c30ad 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/metric_selection.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/metric_selection.tsx @@ -8,12 +8,12 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiButton, EuiButtonGroup, EuiPopover } from '@elastic/eui'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; import { OperationType } from '../../../../../../../lens/public'; const toggleButtons = [ { - id: `avg`, + id: `average`, label: i18n.translate('xpack.observability.expView.metricsSelect.average', { defaultMessage: 'Average', }), @@ -49,7 +49,7 @@ export function MetricSelection({ const [isOpen, setIsOpen] = useState(false); - const [toggleIdSelected, setToggleIdSelected] = useState(series?.metric ?? 'avg'); + const [toggleIdSelected, setToggleIdSelected] = useState(series?.metric ?? 'average'); const onChange = (optionId: OperationType) => { setToggleIdSelected(optionId); diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/remove_series.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/remove_series.tsx index 67aebed943326..aaaa02c7c5697 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/remove_series.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/remove_series.tsx @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; import { EuiButtonIcon } from '@elastic/eui'; import { DataSeries } from '../../types'; -import { useUrlStorage } from '../../hooks/use_url_strorage'; +import { useUrlStorage } from '../../hooks/use_url_storage'; interface Props { series: DataSeries; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_filter.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_filter.tsx index 24b65d2adb38e..c9bb44cfd8cca 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_filter.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/columns/series_filter.tsx @@ -17,9 +17,9 @@ import { } from '@elastic/eui'; import { FilterExpanded } from './filter_expanded'; import { DataSeries } from '../../types'; -import { FieldLabels } from '../../configurations/constants'; +import { FieldLabels } from '../../configurations/constants/constants'; import { SelectedFilters } from '../selected_filters'; -import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../../hooks/use_url_storage'; interface Props { seriesId: string; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.test.tsx index 5770a7e209f06..a38b50d610c75 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.test.tsx @@ -10,8 +10,8 @@ import { screen, waitFor } from '@testing-library/react'; import { mockIndexPattern, mockUrlStorage, render } from '../rtl_helpers'; import { SelectedFilters } from './selected_filters'; import { getDefaultConfigs } from '../configurations/default_configs'; -import { NEW_SERIES_KEY } from '../hooks/use_url_strorage'; -import { USER_AGENT_NAME } from '../configurations/data/elasticsearch_fieldnames'; +import { NEW_SERIES_KEY } from '../hooks/use_url_storage'; +import { USER_AGENT_NAME } from '../configurations/constants/elasticsearch_fieldnames'; describe('SelectedFilters', function () { const dataViewSeries = getDefaultConfigs({ diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.tsx index be8b1feb4d723..34e69f688eaaf 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/selected_filters.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_storage'; import { FilterLabel } from '../components/filter_label'; import { DataSeries, UrlFilter } from '../types'; import { useIndexPatternContext } from '../hooks/use_default_index_pattern'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/series_editor.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/series_editor.tsx index 2d423c9aee3fc..2d8bd12904fbd 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/series_editor.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/series_editor.tsx @@ -13,7 +13,7 @@ import { ActionsCol } from './columns/actions_col'; import { Breakdowns } from './columns/breakdowns'; import { DataSeries } from '../types'; import { SeriesBuilder } from '../series_builder/series_builder'; -import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_strorage'; +import { NEW_SERIES_KEY, useUrlStorage } from '../hooks/use_url_storage'; import { getDefaultConfigs } from '../configurations/default_configs'; import { DatePickerCol } from './columns/date_picker_col'; import { RemoveSeries } from './columns/remove_series'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts index 444e0ddaecb4a..d673fc4d6f6ee 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts @@ -87,3 +87,22 @@ export interface ConfigProps { } export type AppDataType = 'synthetics' | 'rum' | 'logs' | 'metrics' | 'apm'; + +type FormatType = 'duration' | 'number'; +type InputFormat = 'microseconds' | 'milliseconds' | 'seconds'; +type OutputFormat = 'asSeconds' | 'asMilliseconds' | 'humanize'; + +export interface FieldFormatParams { + inputFormat: InputFormat; + outputFormat: OutputFormat; + outputPrecision?: number; + showSuffix?: boolean; +} + +export interface FieldFormat { + field: string; + format: { + id: FormatType; + params: FieldFormatParams; + }; +} diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.test.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.test.ts new file mode 100644 index 0000000000000..b6f544db2a319 --- /dev/null +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.test.ts @@ -0,0 +1,95 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { indexPatternList, ObservabilityIndexPatterns } from './observability_index_patterns'; +import { mockCore, mockIndexPattern } from '../rtl_helpers'; +import { SavedObjectNotFound } from '../../../../../../../../src/plugins/kibana_utils/public'; + +const fieldFormats = { + 'transaction.duration.us': { + id: 'duration', + params: { + inputFormat: 'microseconds', + outputFormat: 'asSeconds', + outputPrecision: 1, + showSuffix: true, + }, + }, + 'transaction.experience.fid': { + id: 'duration', + params: { inputFormat: 'milliseconds', outputFormat: 'asSeconds', showSuffix: true }, + }, + 'transaction.experience.tbt': { + id: 'duration', + params: { inputFormat: 'milliseconds', outputFormat: 'asSeconds', showSuffix: true }, + }, + 'transaction.marks.agent.firstContentfulPaint': { + id: 'duration', + params: { inputFormat: 'milliseconds', outputFormat: 'asSeconds', showSuffix: true }, + }, + 'transaction.marks.agent.largestContentfulPaint': { + id: 'duration', + params: { inputFormat: 'milliseconds', outputFormat: 'asSeconds', showSuffix: true }, + }, +}; + +describe('ObservabilityIndexPatterns', function () { + const { data } = mockCore(); + data!.indexPatterns.get = jest.fn().mockReturnValue({ title: 'index-*' }); + data!.indexPatterns.createAndSave = jest.fn().mockReturnValue({ id: indexPatternList.rum }); + data!.indexPatterns.updateSavedObject = jest.fn(); + + it('should return index pattern for app', async function () { + const obsv = new ObservabilityIndexPatterns(data!); + + const indexP = await obsv.getIndexPattern('rum'); + + expect(indexP).toEqual({ title: 'index-*' }); + + expect(data?.indexPatterns.get).toHaveBeenCalledWith(indexPatternList.rum); + expect(data?.indexPatterns.get).toHaveBeenCalledTimes(1); + }); + + it('should creates missing index pattern', async function () { + data!.indexPatterns.get = jest.fn().mockImplementation(() => { + throw new SavedObjectNotFound('index_pattern'); + }); + + const obsv = new ObservabilityIndexPatterns(data!); + + const indexP = await obsv.getIndexPattern('rum'); + + expect(indexP).toEqual({ id: indexPatternList.rum }); + + expect(data?.indexPatterns.createAndSave).toHaveBeenCalledWith({ + fieldFormats, + id: 'rum_static_index_pattern_id', + timeFieldName: '@timestamp', + title: '(rum-data-view)*,apm-*', + }); + expect(data?.indexPatterns.createAndSave).toHaveBeenCalledTimes(1); + }); + + it('should return getFieldFormats', function () { + const obsv = new ObservabilityIndexPatterns(data!); + + expect(obsv.getFieldFormats('rum')).toEqual(fieldFormats); + }); + + it('should validate field formats', async function () { + mockIndexPattern.getFormatterForField = jest.fn().mockReturnValue({ params: () => {} }); + + const obsv = new ObservabilityIndexPatterns(data!); + + await obsv.validateFieldFormats('rum', mockIndexPattern); + + expect(data?.indexPatterns.updateSavedObject).toHaveBeenCalledTimes(1); + expect(data?.indexPatterns.updateSavedObject).toHaveBeenCalledWith( + expect.objectContaining({ fieldFormatMap: fieldFormats }) + ); + }); +}); diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.ts new file mode 100644 index 0000000000000..e0a2941b24d3c --- /dev/null +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/utils/observability_index_patterns.ts @@ -0,0 +1,124 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { SavedObjectNotFound } from '../../../../../../../../src/plugins/kibana_utils/public'; +import { + DataPublicPluginStart, + IndexPattern, + FieldFormat as IFieldFormat, + IndexPatternSpec, +} from '../../../../../../../../src/plugins/data/public'; +import { rumFieldFormats } from '../configurations/rum/field_formats'; +import { syntheticsFieldFormats } from '../configurations/synthetics/field_formats'; +import { FieldFormat, FieldFormatParams } from '../types'; + +const appFieldFormats: Record = { + rum: rumFieldFormats, + apm: null, + logs: null, + metrics: null, + synthetics: syntheticsFieldFormats, +}; + +function getFieldFormatsForApp(app: DataType) { + return appFieldFormats[app]; +} + +export type DataType = 'synthetics' | 'apm' | 'logs' | 'metrics' | 'rum'; + +export const indexPatternList: Record = { + synthetics: 'synthetics_static_index_pattern_id', + apm: 'apm_static_index_pattern_id', + rum: 'rum_static_index_pattern_id', + logs: 'logs_static_index_pattern_id', + metrics: 'metrics_static_index_pattern_id', +}; + +const appToPatternMap: Record = { + synthetics: '(synthetics-data-view)*,heartbeat-*,synthetics-*', + apm: 'apm-*', + rum: '(rum-data-view)*,apm-*', + logs: 'logs-*,filebeat-*', + metrics: 'metrics-*,metricbeat-*', +}; + +export function isParamsSame(param1: IFieldFormat['_params'], param2: FieldFormatParams) { + return ( + param1?.inputFormat === param2?.inputFormat && + param1?.outputFormat === param2?.outputFormat && + param1?.showSuffix === param2?.showSuffix && + param2?.outputPrecision === param1?.outputPrecision + ); +} + +export class ObservabilityIndexPatterns { + data?: DataPublicPluginStart; + + constructor(data: DataPublicPluginStart) { + this.data = data; + } + + async createIndexPattern(app: DataType) { + if (!this.data) { + throw new Error('data is not defined'); + } + + const pattern = appToPatternMap[app]; + + return await this.data.indexPatterns.createAndSave({ + title: pattern, + id: indexPatternList[app], + timeFieldName: '@timestamp', + fieldFormats: this.getFieldFormats(app), + }); + } + // we want to make sure field formats remain same + async validateFieldFormats(app: DataType, indexPattern: IndexPattern) { + const defaultFieldFormats = getFieldFormatsForApp(app); + if (defaultFieldFormats && defaultFieldFormats.length > 0) { + let isParamsDifferent = false; + defaultFieldFormats.forEach(({ field, format }) => { + const fieldFormat = indexPattern.getFormatterForField(indexPattern.getFieldByName(field)!); + const params = fieldFormat.params(); + if (!isParamsSame(params, format.params)) { + indexPattern.setFieldFormat(field, format); + isParamsDifferent = true; + } + }); + if (isParamsDifferent) { + await this.data?.indexPatterns.updateSavedObject(indexPattern); + } + } + } + + getFieldFormats(app: DataType) { + const fieldFormatMap: IndexPatternSpec['fieldFormats'] = {}; + + (appFieldFormats?.[app] ?? []).forEach(({ field, format }) => { + fieldFormatMap[field] = format; + }); + + return fieldFormatMap; + } + + async getIndexPattern(app: DataType): Promise { + if (!this.data) { + throw new Error('data is not defined'); + } + try { + const indexPattern = await this.data?.indexPatterns.get(indexPatternList[app]); + + // this is intentional a non blocking call, so no await clause + this.validateFieldFormats(app, indexPattern); + return indexPattern; + } catch (e: unknown) { + if (e instanceof SavedObjectNotFound) { + return await this.createIndexPattern(app || 'apm'); + } + } + } +} diff --git a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/field_value_selection.tsx b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/field_value_selection.tsx index a44aab2da85be..d14039ba173ac 100644 --- a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/field_value_selection.tsx +++ b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/field_value_selection.tsx @@ -76,6 +76,7 @@ export function FieldValueSelection({