Skip to content

Commit

Permalink
[ML] Removing use of re2 library (elastic#186104)
Browse files Browse the repository at this point in the history
We no longer need to use `re2` over the standard regex library.

(cherry picked from commit ed70d4c)

# 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
  • Loading branch information
jgowdyelastic committed Jul 15, 2024
1 parent 8197581 commit 1d9dc61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -52,4 +51,4 @@ function findLogJobSpaceFactory() {
}
return result[1] ?? null;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -59,4 +58,4 @@ function findMetricsJobSpaceFactory() {
}
return result[1] ?? null;
};
}
}
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 {
KibanaRequest,
SavedObjectsClientContract,
Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -413,4 +412,4 @@ function createSavedObjectFilter(filterObject: JobObjectFilter) {
})
.join(' AND ');
return { filter, searchFields };
}
}

0 comments on commit 1d9dc61

Please sign in to comment.