From f7be89d6f584a7fab1f1c3c5e780b50c5bcafd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Fri, 13 Dec 2024 18:04:26 +0000 Subject: [PATCH] Remove dependency on the observability plugin --- .../get_data_stream_details/index.ts | 9 +++---- ...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 | 1 - 6 files changed, 36 insertions(+), 13 deletions(-) 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..125d0e0582e84 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 @@ -8,17 +8,16 @@ import { badRequest } from '@hapi/boom'; import type { ElasticsearchClient, IScopedClusterClient } from '@kbn/core/server'; import { - findInventoryFields, InventoryItemType, + findInventoryFields, 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'; 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 9ea862acf800b..e96d844d03d2c 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json +++ b/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json @@ -23,7 +23,6 @@ "@kbn/field-formats-plugin", "@kbn/field-types", "@kbn/io-ts-utils", - "@kbn/observability-plugin", "@kbn/es-types", "@kbn/deeplinks-observability", "@kbn/router-utils",