From 3a4fe6f0524da0393317ba6bb294383fec278981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Wed, 18 Dec 2024 21:13:15 +0100 Subject: [PATCH] [Dataset Quality] Reclassify modules as "platform/shared" (#204052) ## :memo: Summary This reclassifies the plugins `@kbn/data-quality-plugin` and `@kbn/dataset-quality-plugin` as `platform/shared`, because they're not specific observability despite the code ownership. - partly addresses: https://github.com/elastic/observability-dev/issues/4059 ## :female_detective: Review notes - One small utility hook was copied from `@kbn/observability-shared-plugin` to remove a forbidden dependency. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine --- x-pack/plugins/data_quality/kibana.jsonc | 11 ++++--- .../dataset_quality/kibana.jsonc | 7 ++-- .../dataset_quality/filters/filters.tsx | 27 +++------------- .../dataset_quality/public/types.ts | 15 ++++----- .../public/utils/use_quick_time_ranges.tsx | 27 ++++++++++++++++ .../get_data_stream_details/index.ts | 32 ++++++++++--------- ...et_dataset_aggregated_paginated_results.ts | 4 +-- .../data_streams/get_degraded_fields/index.ts | 4 +-- .../get_non_aggregatable_data_streams.ts | 4 +-- .../dataset_quality/server/utils/queries.ts | 27 +++++++++++++++- .../dataset_quality/tsconfig.json | 4 --- 11 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 x-pack/plugins/observability_solution/dataset_quality/public/utils/use_quick_time_ranges.tsx diff --git a/x-pack/plugins/data_quality/kibana.jsonc b/x-pack/plugins/data_quality/kibana.jsonc index dc54e20f40bd7..973e2c44435b0 100644 --- a/x-pack/plugins/data_quality/kibana.jsonc +++ b/x-pack/plugins/data_quality/kibana.jsonc @@ -2,19 +2,22 @@ "type": "plugin", "id": "@kbn/data-quality-plugin", "owner": "@elastic/obs-ux-logs-team", - "group": "observability", - "visibility": "private", + "group": "platform", + "visibility": "shared", "plugin": { "id": "dataQuality", "server": true, "browser": true, - "configPath": ["xpack", "data_quality"], + "configPath": [ + "xpack", + "data_quality" + ], "requiredPlugins": [ "datasetQuality", "management", "features", "share", - ], + ], "optionalPlugins": [], "requiredBundles": [ "kibanaReact", diff --git a/x-pack/plugins/observability_solution/dataset_quality/kibana.jsonc b/x-pack/plugins/observability_solution/dataset_quality/kibana.jsonc index 0e688533897e1..471c25ec49522 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/kibana.jsonc +++ b/x-pack/plugins/observability_solution/dataset_quality/kibana.jsonc @@ -4,8 +4,8 @@ "owner": [ "@elastic/obs-ux-logs-team" ], - "group": "observability", - "visibility": "private", + "group": "platform", + "visibility": "shared", "description": "This plugin introduces the concept of data set quality, where users can easily get an overview on the data sets they have.", "plugin": { "id": "datasetQuality", @@ -22,7 +22,6 @@ "controls", "embeddable", "share", - "observabilityShared", "fleet", "fieldFormats", "dataViews", @@ -42,4 +41,4 @@ "common" ] } -} \ No newline at end of file +} diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/filters/filters.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/filters/filters.tsx index cb4769534563b..70f5f9b9d7862 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/filters/filters.tsx +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/filters/filters.tsx @@ -5,14 +5,11 @@ * 2.0. */ -import { EuiFilterGroup, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { EuiSuperDatePicker } from '@elastic/eui'; -import { UI_SETTINGS } from '@kbn/data-service'; -import { TimePickerQuickRange } from '@kbn/observability-shared-plugin/public/hooks/use_quick_time_ranges'; -import React, { useMemo } from 'react'; +import { EuiFilterGroup, EuiFlexGroup, EuiFlexItem, EuiSuperDatePicker } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import React from 'react'; import { useDatasetQualityFilters } from '../../../hooks/use_dataset_quality_filters'; -import { useKibanaContextForPlugin } from '../../../utils/use_kibana'; +import { useQuickTimeRanges } from '../../../utils/use_quick_time_ranges'; import { FilterBar } from './filter_bar'; import { IntegrationsSelector } from './integrations_selector'; import { NamespacesSelector } from './namespaces_selector'; @@ -59,23 +56,7 @@ export default function Filters() { onQueryChange, } = useDatasetQualityFilters(); - const { - services: { uiSettings }, - } = useKibanaContextForPlugin(); - - const timePickerQuickRanges = uiSettings.get( - UI_SETTINGS.TIMEPICKER_QUICK_RANGES - ); - - const commonlyUsedRanges = useMemo( - () => - timePickerQuickRanges.map(({ from, to, display }) => ({ - start: from, - end: to, - label: display, - })), - [timePickerQuickRanges] - ); + const commonlyUsedRanges = useQuickTimeRanges(); return ( diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/types.ts b/x-pack/plugins/observability_solution/dataset_quality/public/types.ts index 9b97ce12a194f..dbc2279c2532c 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/types.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/public/types.ts @@ -5,18 +5,16 @@ * 2.0. */ -import type { ComponentType } from 'react'; -import type { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; -import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; -import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; -import type { LensPublicStart } from '@kbn/lens-plugin/public'; -import type { ObservabilitySharedPluginSetup } from '@kbn/observability-shared-plugin/public'; +import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public'; - +import type { LensPublicStart } from '@kbn/lens-plugin/public'; +import type { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; +import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; +import type { ComponentType } from 'react'; import type { DatasetQualityProps } from './components/dataset_quality'; -import { DatasetQualityDetailsProps } from './components/dataset_quality_details'; +import type { DatasetQualityDetailsProps } from './components/dataset_quality_details'; import type { CreateDatasetQualityController } from './controller/dataset_quality'; import type { CreateDatasetQualityDetailsController } from './controller/dataset_quality_details'; @@ -37,7 +35,6 @@ export interface DatasetQualityStartDeps { unifiedSearch: UnifiedSearchPublicPluginStart; lens: LensPublicStart; dataViews: DataViewsPublicPluginStart; - observabilityShared: ObservabilitySharedPluginSetup; fieldsMetadata: FieldsMetadataPublicStart; } diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/utils/use_quick_time_ranges.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/utils/use_quick_time_ranges.tsx new file mode 100644 index 0000000000000..81ed31065095b --- /dev/null +++ b/x-pack/plugins/observability_solution/dataset_quality/public/utils/use_quick_time_ranges.tsx @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useUiSetting } from '@kbn/kibana-react-plugin/public'; +import { UI_SETTINGS } from '@kbn/data-plugin/common'; + +export interface TimePickerQuickRange { + from: string; + to: string; + display: string; +} + +export function useQuickTimeRanges() { + const timePickerQuickRanges = useUiSetting( + UI_SETTINGS.TIMEPICKER_QUICK_RANGES + ); + + return timePickerQuickRanges.map(({ from, to, display }) => ({ + start: from, + end: to, + label: display, + })); +} diff --git a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_data_stream_details/index.ts b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_data_stream_details/index.ts index 0ca2ae94214e8..aae738f0b01c2 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_data_stream_details/index.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_data_stream_details/index.ts @@ -7,18 +7,12 @@ import { badRequest } from '@hapi/boom'; import type { ElasticsearchClient, IScopedClusterClient } from '@kbn/core/server'; -import { - findInventoryFields, - InventoryItemType, - inventoryModels, -} from '@kbn/metrics-data-access-plugin/common'; -import { rangeQuery } from '@kbn/observability-plugin/server'; - +import { DataStreamDetails } from '../../../../common/api_types'; import { MAX_HOSTS_METRIC_VALUE } from '../../../../common/constants'; import { _IGNORED } from '../../../../common/es_fields'; -import { DataStreamDetails } from '../../../../common/api_types'; -import { createDatasetQualityESClient } from '../../../utils'; import { datasetQualityPrivileges } from '../../../services'; +import { createDatasetQualityESClient } from '../../../utils'; +import { rangeQuery } from '../../../utils/queries'; import { getDataStreams } from '../get_data_streams'; import { getDataStreamsMeteringStats } from '../get_data_streams_metering_stats'; @@ -101,13 +95,21 @@ const serviceNamesAgg: TermAggregation = { ['service.name']: { terms: { field: 'service.name', size: MAX_HOSTS } }, }; +const entityFields = [ + 'host.name', + 'container.id', + 'kubernetes.pod.uid', + 'cloud.instance.id', + 'aws.s3.bucket.name', + 'aws.rds.db_instance.arn', + 'aws.sqs.queue.name', +]; + // Gather host terms like 'host', 'pod', 'container' -const hostsAgg: TermAggregation = inventoryModels - .map((model) => findInventoryFields(model.id as InventoryItemType)) - .reduce( - (acc, fields) => ({ ...acc, [fields.id]: { terms: { field: fields.id, size: MAX_HOSTS } } }), - {} as TermAggregation - ); +const hostsAgg: TermAggregation = entityFields.reduce( + (acc, idField) => ({ ...acc, [idField]: { terms: { field: idField, size: MAX_HOSTS } } }), + {} as TermAggregation +); async function getDataStreamSummaryStats( esClient: ElasticsearchClient, diff --git a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_dataset_aggregated_paginated_results.ts b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_dataset_aggregated_paginated_results.ts index 062dcd2f16cf7..fe9af4dda94a1 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_dataset_aggregated_paginated_results.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_dataset_aggregated_paginated_results.ts @@ -5,11 +5,11 @@ * 2.0. */ -import type { ElasticsearchClient } from '@kbn/core/server'; -import { rangeQuery } from '@kbn/observability-plugin/server'; import { QueryDslBoolQuery } from '@elastic/elasticsearch/lib/api/types'; +import type { ElasticsearchClient } from '@kbn/core/server'; import { DataStreamDocsStat } from '../../../common/api_types'; import { createDatasetQualityESClient } from '../../utils'; +import { rangeQuery } from '../../utils/queries'; interface Dataset { type: string; diff --git a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_degraded_fields/index.ts b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_degraded_fields/index.ts index 0bb0b6a695fef..d76ca8be7a541 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_degraded_fields/index.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_degraded_fields/index.ts @@ -6,11 +6,11 @@ */ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { rangeQuery, existsQuery } from '@kbn/observability-plugin/server'; import { DegradedFieldResponse } from '../../../../common/api_types'; import { MAX_DEGRADED_FIELDS } from '../../../../common/constants'; +import { INDEX, TIMESTAMP, _IGNORED } from '../../../../common/es_fields'; import { createDatasetQualityESClient } from '../../../utils'; -import { _IGNORED, INDEX, TIMESTAMP } from '../../../../common/es_fields'; +import { existsQuery, rangeQuery } from '../../../utils/queries'; import { getFieldIntervalInSeconds } from './get_interval'; export async function getDegradedFields({ diff --git a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_non_aggregatable_data_streams.ts b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_non_aggregatable_data_streams.ts index 6137bc5426f86..93f5c6a573b75 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_non_aggregatable_data_streams.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/server/routes/data_streams/get_non_aggregatable_data_streams.ts @@ -6,11 +6,11 @@ */ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { rangeQuery } from '@kbn/observability-plugin/server/utils/queries'; -import { extractIndexNameFromBackingIndex } from '../../../common/utils'; import { _IGNORED } from '../../../common/es_fields'; import { DataStreamType } from '../../../common/types'; +import { extractIndexNameFromBackingIndex } from '../../../common/utils'; import { createDatasetQualityESClient } from '../../utils'; +import { rangeQuery } from '../../utils/queries'; export async function getNonAggregatableDataStreams({ esClient, diff --git a/x-pack/plugins/observability_solution/dataset_quality/server/utils/queries.ts b/x-pack/plugins/observability_solution/dataset_quality/server/utils/queries.ts index 26e13d99bc61a..7d77d3f0325aa 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/server/utils/queries.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/server/utils/queries.ts @@ -5,7 +5,10 @@ * 2.0. */ import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; -import { isUndefinedOrNull } from '@kbn/observability-plugin/server/utils/queries'; + +export function isUndefinedOrNull(value: any): value is undefined | null { + return value === undefined || value === null; +} export function wildcardQuery( field: T, @@ -17,3 +20,25 @@ export function wildcardQuery( return [{ wildcard: { [field]: `*${value}*` } }]; } + +export function rangeQuery( + start?: number, + end?: number, + field = '@timestamp' +): QueryDslQueryContainer[] { + return [ + { + range: { + [field]: { + gte: start, + lte: end, + format: 'epoch_millis', + }, + }, + }, + ]; +} + +export function existsQuery(field: string): QueryDslQueryContainer[] { + return [{ exists: { field } }]; +} diff --git a/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json b/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json index 9c515d8112088..b50a65aa83c4b 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json +++ b/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json @@ -23,14 +23,11 @@ "@kbn/field-formats-plugin", "@kbn/field-types", "@kbn/io-ts-utils", - "@kbn/observability-plugin", "@kbn/es-types", "@kbn/deeplinks-observability", "@kbn/router-utils", "@kbn/xstate-utils", "@kbn/shared-ux-utility", - "@kbn/data-service", - "@kbn/observability-shared-plugin", "@kbn/data-plugin", "@kbn/unified-search-plugin", "@kbn/timerange", @@ -45,7 +42,6 @@ "@kbn/deeplinks-analytics", "@kbn/core-elasticsearch-server", "@kbn/ui-actions-plugin", - "@kbn/metrics-data-access-plugin", "@kbn/calculate-auto", "@kbn/discover-plugin", "@kbn/shared-ux-prompt-no-data-views-types",