From b613ee70bdc59681427ecacdfd1cf4124d059bdf Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 13 Jun 2024 06:43:40 +0100 Subject: [PATCH] [ML] Removing use of re2 library (#186104) We no longer need to use `re2` over the standard regex library. (cherry picked from commit ed70d4c6ffb77324f9c6e74e26ed559303ae6c3f) --- .../saved_objects/initialization/space_overrides/logs.ts | 3 +-- .../saved_objects/initialization/space_overrides/metrics.ts | 3 +-- x-pack/plugins/ml/server/saved_objects/service.ts | 5 ++--- 3 files changed, 4 insertions(+), 7 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 8c1a548d58727..5e4f64b5d555d 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 type { IScopedClusterClient } from '@kbn/core/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; const GROUP = 'logs-ui'; @@ -42,7 +41,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); 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 3169be12ad7e8..cbe55fa76db55 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 type { IScopedClusterClient } from '@kbn/core/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; const GROUP = 'metrics'; @@ -49,7 +48,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); diff --git a/x-pack/plugins/ml/server/saved_objects/service.ts b/x-pack/plugins/ml/server/saved_objects/service.ts index 64925dabeb892..eed08b2a74d63 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 { memoize } from 'lodash'; import type { KibanaRequest, @@ -329,7 +328,7 @@ export function mlSavedObjectServiceFactory( 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)); }); } @@ -641,7 +640,7 @@ export function mlSavedObjectServiceFactory( if (id.match('\\*') === null) { return modelIds.includes(id); } - const regex = new RE2(id.replace('*', '.*')); + const regex = new RegExp(id.replace('*', '.*')); return modelIds.some((jId) => typeof jId === 'string' && regex.exec(jId)); }); }