Skip to content

Commit

Permalink
[7.17] [ML] Removing use of re2 library (elastic#186104) (elastic#188372
Browse files Browse the repository at this point in the history
)

# Backport

This will backport the following commits from `main` to `7.17`:
- [[ML] Removing use of re2 library
(elastic#186104)](elastic#186104)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"James
Gowdy","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-06-13T05:43:40Z","message":"[ML]
Removing use of re2 library (elastic#186104)\n\nWe no longer need to use `re2`
over the standard regex
library.","sha":"ed70d4c6ffb77324f9c6e74e26ed559303ae6c3f","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","backport:skip","v8.15.0"],"number":186104,"url":"https://github.com/elastic/kibana/pull/186104","mergeCommit":{"message":"[ML]
Removing use of re2 library (elastic#186104)\n\nWe no longer need to use `re2`
over the standard regex
library.","sha":"ed70d4c6ffb77324f9c6e74e26ed559303ae6c3f"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.15.0","labelRegex":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/186104","number":186104,"mergeCommit":{"message":"[ML]
Removing use of re2 library (elastic#186104)\n\nWe no longer need to use `re2`
over the standard regex
library.","sha":"ed70d4c6ffb77324f9c6e74e26ed559303ae6c3f"}}]}]
BACKPORT-->

---------

Co-authored-by: James Gowdy <[email protected]>
  • Loading branch information
2 people authored and adelisle committed Aug 5, 2024
1 parent 0d56cf3 commit 8813efb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 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 Down
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 Down
3 changes: 1 addition & 2 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

0 comments on commit 8813efb

Please sign in to comment.