From 1d9dc61fc6f240426fe6043f71179800c68ea1b5 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 13 Jun 2024 06:43:40 +0100 Subject: [PATCH 1/2] [ML] Removing use of re2 library (#186104) We no longer need to use `re2` over the standard regex library. (cherry picked from commit ed70d4c6ffb77324f9c6e74e26ed559303ae6c3f) # Conflicts: # x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts # x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts # x-pack/plugins/ml/server/saved_objects/service.ts --- .../saved_objects/initialization/space_overrides/logs.ts | 5 ++--- .../saved_objects/initialization/space_overrides/metrics.ts | 5 ++--- x-pack/plugins/ml/server/saved_objects/service.ts | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts index 40285742af2b9..c0b891b2de3f3 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts @@ -6,7 +6,6 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; import { Job } from '../../../../common/types/anomaly_detection_jobs'; @@ -43,7 +42,7 @@ export async function logJobsSpaces({ } function findLogJobSpaceFactory() { - const reg = new RE2(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); + const reg = new RegExp(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); return (jobId: string) => { const result = reg.exec(jobId); @@ -52,4 +51,4 @@ function findLogJobSpaceFactory() { } return result[1] ?? null; }; -} +} \ No newline at end of file diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts index 125b3e32b1efb..8bb85b3f15a63 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts @@ -6,7 +6,6 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; import { Job } from '../../../../common/types/anomaly_detection_jobs'; @@ -50,7 +49,7 @@ export async function metricsJobsSpaces({ } function findMetricsJobSpaceFactory() { - const reg = new RE2(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); + const reg = new RegExp(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); return (jobId: string) => { const result = reg.exec(jobId); @@ -59,4 +58,4 @@ function findMetricsJobSpaceFactory() { } return result[1] ?? null; }; -} +} \ No newline at end of file diff --git a/x-pack/plugins/ml/server/saved_objects/service.ts b/x-pack/plugins/ml/server/saved_objects/service.ts index ff8856457ca4f..03c1f6ae7aa15 100644 --- a/x-pack/plugins/ml/server/saved_objects/service.ts +++ b/x-pack/plugins/ml/server/saved_objects/service.ts @@ -5,7 +5,6 @@ * 2.0. */ -import RE2 from 're2'; import { KibanaRequest, SavedObjectsClientContract, @@ -281,7 +280,7 @@ export function jobSavedObjectServiceFactory( if (id.match('\\*') === null) { return jobIds.includes(id); } - const regex = new RE2(id.replace('*', '.*')); + const regex = new RegExp(id.replace('*', '.*')); return jobIds.some((jId) => typeof jId === 'string' && regex.exec(jId)); }); } @@ -413,4 +412,4 @@ function createSavedObjectFilter(filterObject: JobObjectFilter) { }) .join(' AND '); return { filter, searchFields }; -} +} \ No newline at end of file From ea3dcfc37a3eaf5a12ca0f1512c5e0cab640c565 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 15 Jul 2024 21:31:47 +0100 Subject: [PATCH 2/2] fix(NA): eslint --- .../server/saved_objects/initialization/space_overrides/logs.ts | 2 +- .../saved_objects/initialization/space_overrides/metrics.ts | 2 +- x-pack/plugins/ml/server/saved_objects/service.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts index c0b891b2de3f3..0103d8eb5d0ab 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts @@ -51,4 +51,4 @@ function findLogJobSpaceFactory() { } return result[1] ?? null; }; -} \ No newline at end of file +} diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts index 8bb85b3f15a63..1d2173ecd29f7 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts @@ -58,4 +58,4 @@ function findMetricsJobSpaceFactory() { } return result[1] ?? null; }; -} \ No newline at end of file +} diff --git a/x-pack/plugins/ml/server/saved_objects/service.ts b/x-pack/plugins/ml/server/saved_objects/service.ts index 03c1f6ae7aa15..6907842b262a9 100644 --- a/x-pack/plugins/ml/server/saved_objects/service.ts +++ b/x-pack/plugins/ml/server/saved_objects/service.ts @@ -412,4 +412,4 @@ function createSavedObjectFilter(filterObject: JobObjectFilter) { }) .join(' AND '); return { filter, searchFields }; -} \ No newline at end of file +}