Skip to content

Commit

Permalink
[ML] Removing use of re2 library (#186104)
Browse files Browse the repository at this point in the history
We no longer need to use `re2` over the standard regex library.
  • Loading branch information
jgowdyelastic authored Jun 13, 2024
1 parent 4557dc1 commit ed70d4c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { IScopedClusterClient } from '@kbn/core/server';
import RE2 from 're2';
import { mlLog } from '../../../lib/log';

const GROUP = 'logs-ui';
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { IScopedClusterClient } from '@kbn/core/server';
import RE2 from 're2';
import { mlLog } from '../../../lib/log';

const GROUP = 'metrics';
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/ml/server/saved_objects/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import RE2 from 're2';
import { memoize } from 'lodash';
import type {
KibanaRequest,
Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -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));
});
}
Expand Down

0 comments on commit ed70d4c

Please sign in to comment.