Skip to content

Commit

Permalink
chore(NA): remove usage of re2 and replace it with a non native module (
Browse files Browse the repository at this point in the history
elastic#188134)

This PR removes the usage of the native module version of `re2` and
replaces it with a js port called `re2js`.
It also ends our usage of native node modules in production and it
removes the task from the build as well. Further steps will be taken
along our strategy to avoid future usages of native node modules in prod
environments.
  • Loading branch information
mistic authored Jul 15, 2024
1 parent b3dcc54 commit 3c338a8
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 391 deletions.
1 change: 0 additions & 1 deletion .buildkite/scripts/common/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ fi

export GECKODRIVER_CDNURL="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache$CI_PROXY_CACHE_SUFFIX"
export CHROMEDRIVER_CDNURL="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache$CI_PROXY_CACHE_SUFFIX"
export RE2_DOWNLOAD_MIRROR="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache$CI_PROXY_CACHE_SUFFIX"
export CYPRESS_DOWNLOAD_MIRROR="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache$CI_PROXY_CACHE_SUFFIX/cypress"

export NODE_OPTIONS="--max-old-space-size=4096"
Expand Down
1 change: 0 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ yarn_install(
"GECKODRIVER_CDNURL": "https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache",
"CHROMEDRIVER_CDNURL": "https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache",
"CHROMEDRIVER_CDNBINARIESURL": "https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache",
"RE2_DOWNLOAD_MIRROR": "https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/node-re2",
"CYPRESS_DOWNLOAD_MIRROR": "https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/cypress",
}
)
4 changes: 0 additions & 4 deletions kbn_pm/src/lib/bazel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ export async function installYarnDeps(log, opts = undefined) {
await runBazel(log, ['run', '@nodejs//:yarn'], {
offline: opts?.offline,
quiet: opts?.quiet,
env: {
RE2_DOWNLOAD_MIRROR:
'https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/node-re2',
},
});

log.success('yarn deps installed');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@
"query-string": "^6.13.2",
"rbush": "^3.0.1",
"re-resizable": "^6.9.9",
"re2": "1.20.9",
"re2js": "0.4.1",
"react": "^17.0.2",
"react-ace": "^7.0.5",
"react-diff-view": "^3.2.0",
Expand Down
8 changes: 8 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@
"matchBaseBranches": ["main"],
"labels": ["Team: Cloud Security", "release_note:skip", "backport:skip"],
"enabled": true
},
{
"groupName": "re2js",
"matchDepNames": ["re2js"],
"reviewers": ["team:visualizations", "dej611"],
"matchBaseBranches": ["main"],
"labels": ["release_note:skip", "backport:all-open", "Team:Visualizations"],
"enabled": true
}
]
}
39 changes: 0 additions & 39 deletions scripts/download_re2.sh

This file was deleted.

1 change: 0 additions & 1 deletion src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
*/
if (options.createPlatformFolders) {
await run(Tasks.CreateArchivesSources);
await run(Tasks.PatchNativeModules);
await run(Tasks.InstallChromium);
await run(Tasks.CopyBinScripts);
await run(Tasks.CleanNodeBuilds);
Expand Down
1 change: 0 additions & 1 deletion src/dev/build/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export * from './nodejs';
export * from './notice_file_task';
export * from './os_packages';
export * from './package_json';
export * from './patch_native_modules_task';
export * from './assert_file_time';
export * from './assert_no_uuid';
export * from './assert_path_length';
Expand Down
4 changes: 0 additions & 4 deletions src/dev/build/tasks/install_dependencies_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export const InstallDependencies: Task = {
],
{
cwd: build.resolvePath(),
env: {
RE2_DOWNLOAD_MIRROR:
'https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/node-re2',
},
}
);
},
Expand Down
146 changes: 0 additions & 146 deletions src/dev/build/tasks/patch_native_modules_task.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { i18n } from '@kbn/i18n';
import alter from '../lib/alter';
import Chainable from '../lib/classes/chainable';
import { RE2JS } from 're2js';

export default new Chainable('label', {
args: [
Expand Down Expand Up @@ -40,10 +41,9 @@ export default new Chainable('label', {
const config = args.byName;
return alter(args, function (eachSeries) {
if (config.regex) {
// not using a standard `import` so that if there's an issue with the re2 native module
// that it doesn't prevent Kibana from starting up and we only have an issue using Timelion labels
const RE2 = require('re2');
eachSeries.label = eachSeries.label.replace(new RE2(config.regex), config.label);
eachSeries.label = RE2JS.compile(config.regex)
.matcher(eachSeries.label)
.replaceAll(config.label);
} else if (config.label) {
eachSeries.label = config.label;
}
Expand Down
Loading

0 comments on commit 3c338a8

Please sign in to comment.