diff --git a/Cargo.lock b/Cargo.lock index cc3f00006e189e..7d11e144a63db4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1754,15 +1754,6 @@ dependencies = [ "serde", ] -[[package]] -name = "built" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b99c4cdc7b2c2364182331055623bdf45254fcb679fea565c40c3c11c101889a" -dependencies = [ - "cargo-lock", -] - [[package]] name = "bumpalo" version = "3.11.1" @@ -1879,18 +1870,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" -[[package]] -name = "cargo-lock" -version = "9.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" -dependencies = [ - "semver 1.0.18", - "serde", - "toml 0.7.6", - "url", -] - [[package]] name = "cargo_toml" version = "0.15.3" @@ -9980,7 +9959,6 @@ dependencies = [ name = "vector-vrl-web-playground" version = "0.1.0" dependencies = [ - "built", "cargo_toml", "enrichment", "getrandom 0.2.10", diff --git a/lib/vector-vrl/web-playground/Cargo.toml b/lib/vector-vrl/web-playground/Cargo.toml index a00a3b54d3419e..9bf8aa8e68baae 100644 --- a/lib/vector-vrl/web-playground/Cargo.toml +++ b/lib/vector-vrl/web-playground/Cargo.toml @@ -17,7 +17,6 @@ gloo-utils = { version = "0.2", features = ["serde"] } getrandom = { version = "0.2", features = ["js"] } vector-vrl-functions = { path = "../functions" } enrichment = { path = "../../enrichment" } -built = { version = "0.6.1" } [build-dependencies] cargo_toml = "0.15.3" diff --git a/lib/vector-vrl/web-playground/build.rs b/lib/vector-vrl/web-playground/build.rs index b6997634f20a56..0ae318ef149484 100644 --- a/lib/vector-vrl/web-playground/build.rs +++ b/lib/vector-vrl/web-playground/build.rs @@ -24,11 +24,10 @@ fn write_build_constants(manifest: &Manifest, dest_path: &Path) -> io::Result<() "// AUTOGENERATED CONSTANTS. SEE BUILD.RS AT REPOSITORY ROOT. DO NOT MODIFY.\n".as_ref(), )?; - let vector_version_const = format!( - "pub const {}: &str = \"{}\"", - "VECTOR_VERSION", - manifest.package().version() - ); + let create_const_statement = + |name, value| format!("pub const {}: &str = \"{}\";\n", name, value); + // TODO: For releases, we should use the manifest.package().version(). + let vector_version_const = create_const_statement("VECTOR_VERSION", "master"); output_file .write_all(vector_version_const.as_bytes()) .expect("Failed to write Vector version constant"); @@ -40,18 +39,18 @@ fn write_build_constants(manifest: &Manifest, dest_path: &Path) -> io::Result<() .detail() .unwrap() .version + .clone() .unwrap(); - let vrl_version_const = format!("pub const {}: &str = \"{}\"", "VRL_VERSION", vrl_version); + let vrl_version_const = create_const_statement("VRL_VERSION", vrl_version); output_file - .write_all(vector_version_const.as_bytes()) + .write_all(vrl_version_const.as_bytes()) .expect("Failed to write Vector version constant"); Ok(()) } fn main() { - //println!("cargo:rerun-if-changed(../../../Cargo.toml"); let manifest = - Manifest::from_path(&get_vector_toml_path()).expect("Failed to load Vector Cargo.toml"); - let dst = std::path::Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs"); + Manifest::from_path(get_vector_toml_path()).expect("Failed to load Vector Cargo.toml"); + let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs"); write_build_constants(&manifest, &dst).expect("Failed to write constants"); } diff --git a/lib/vector-vrl/web-playground/public/index.css b/lib/vector-vrl/web-playground/public/index.css deleted file mode 100644 index 02eecc7c283388..00000000000000 --- a/lib/vector-vrl/web-playground/public/index.css +++ /dev/null @@ -1,317 +0,0 @@ -body { - margin-right: 2vw; - margin-left: 2vw; -} - -div#App { - display: grid; - width: 100%; - height: 100%; - /* the app will have two columns, one for input - one for output, left and right */ - grid-template-columns: repeat(2, 1fr); - grid-template-rows: 15vh 1vh 75vh; - grid-gap: 1rem; - } - - div#summary-section { - display: grid; - grid-row: 1; - grid-template-rows: 35% 65%; - width: 100%; - font-size: 1vw; - grid-gap: 1vw; - } - - div#summary-section p{ - font-size: .9vw; - } - - div#toolbar-section { - display: grid; - grid-row: 2; - grid-column: 1 / span 2; - grid-template-columns: repeat(8, 1fr); - } - - #toolbar-section #run-code-btn { - grid-column: 1; - } - - #toolbar-section #share-code-btn { - grid-column: 3; - } - - /* input pane */ - div#input-section { - display: grid; - grid-column: 1; - grid-row: 3; - overflow: hidden; - } - - #input-section #cell { - display: grid; - grid-template-rows: 6% 94%; - overflow: hidden; - } - - #input-section #cell #input-cell-title { - height: 100%; - grid-row: 1; - } - - #input-section #cell #container-program { - display: grid; - height: 100%; - } - - div#output-section { - display: grid; - grid-column: 2; - grid-row: 3; - grid-template-rows: 50% 50%; - overflow: hidden; - } - - /* event pane */ - #output-section #event-cell { - display: grid; - /* this is double of input-cell-title row - because we are working with half the space */ - grid-template-rows: 12% 88%; - grid-row: 1; - height: 100%; - } - - #output-section #event-cell #event-cell-title { - display: grid; - grid-row: 1; - } - - #output-section #event-cell #container-event { - display: grid; - grid-row: 2; - height: 100%; - } - - /* output pane */ - #output-section #output-cell { - display: grid; - grid-template-rows: 12% 88%; - grid-row: 2; - height: 100%; - } - - #output-section #output-cell #output-cell-title { - display: grid; - grid-row: 1; - } - - #output-section #output-cell #container-output { - display: grid; - grid-row: 2; - height: 100%; - } - - body { - font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, - Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, - Segoe UI Symbol, Noto Color Emoji; - } - - .btn-primary { - display: inline-block; - outline: 0; - border: none; - cursor: pointer; - border-radius: 4px; - font-size: 13px; - height: 30px; - background-color: #9147ff; - color: white; - padding: 0 20px; - } - - .btn-primary:hover { - background-color: #772ce8; - } - - .btn-secondary { - display: inline-block; - outline: 0; - border: none; - cursor: pointer; - border-radius: 4px; - font-size: 13px; - height: 30px; - background-color: #0000001a; - color: #000000; - padding: 0 20px; - } - - .btn-secondary:hover { - background-color: #dcdcdc; - } - -/* Portrait and Landscape */ -@media only screen - and (min-width: 200px) - and (max-width: 1000px) { - div#App { - display: grid; - width: 100%; - height: 100%; - /* the app will have multiple rows - stacking each section on top of each other */ - grid-template-rows: 20vh 25vh 10vh 50vh; - grid-template-columns: 100%; - } - - div#summary-section { - display: grid; - grid-row: 1; - grid-template-rows: 20% 80%; - width: 100%; - font-size: 1.5vh; - grid-gap: 2vw; - } - - div#summary-section p { - grid-row: 2; - font-size: 2vh; - } - - div#toolbar-section { - display: grid; - grid-row: 3; - grid-column: 1; - grid-template-columns: 100%; - grid-template-rows: repeat(2, 1fr); - } - - #toolbar-section #run-code-btn { - display: grid; - grid-row: 1; - grid-column: 1; - } - - #toolbar-section #share-code-btn { - display: grid; - grid-row: 2; - grid-column: 1; - } - - /* input pane */ - div#input-section { - display: grid; - grid-column: 1; - grid-row: 2; - overflow: hidden; - } - - #input-section #cell { - display: grid; - grid-column: 1; - grid-template-rows: 23% 77%; - overflow: hidden; - } - - #input-section #cell #input-cell-title { - height: 100%; - grid-column: 1; - grid-row: 1; - } - - #input-section #cell #container-program { - display: grid; - height: 100%; - } - - div#output-section { - display: grid; - grid-row: 4 / 5; - grid-column: 1; - grid-template-rows: 50% 50%; - overflow: hidden; - } - - /* event pane */ - #output-section #event-cell { - display: grid; - grid-template-rows: 20% 80%; - grid-row: 1; - height: 100%; - } - - #output-section #event-cell #event-cell-title { - display: grid; - grid-row: 1; - } - - #output-section #event-cell #container-event { - display: grid; - height: 100%; - } - - /* output pane */ - #output-section #output-cell { - display: grid; - grid-template-rows: 20% 80%; - grid-row: 2; - height: 100%; - } - - #output-section #output-cell #output-cell-title { - display: grid; - grid-row: 1; - } - - #output-section #output-cell #container-output { - display: grid; - grid-row: 2; - height: 100%; - } - - body { - font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, - Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, - Segoe UI Symbol, Noto Color Emoji; - } - - .btn-primary { - display: inline-block; - outline: 0; - border: none; - cursor: pointer; - border-radius: 4px; - font-size: 13px; - height: 30px; - background-color: #9147ff; - color: white; - padding: 0 20px; - align-items: center; - } - - .btn-primary:hover { - background-color: #772ce8; - } - - .btn-secondary { - display: inline-block; - outline: 0; - border: none; - cursor: pointer; - border-radius: 4px; - font-size: 13px; - height: 30px; - background-color: #0000001a; - color: #000000; - padding: 0 20px; - align-items: center; - } - - .btn-secondary:hover { - background-color: #dcdcdc; - } -} diff --git a/lib/vector-vrl/web-playground/public/index.html b/lib/vector-vrl/web-playground/public/index.html deleted file mode 100644 index 3b4e31106e182c..00000000000000 --- a/lib/vector-vrl/web-playground/public/index.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - VRL playground - - - - - - - - - -
-
-

VRL Playground

-

- -

- Vector Remap Language (VRL) is an expression-oriented language designed for transforming - observability data. This playground lets you write a program, run it against an event or - events, share it, and see how the events are transformed. -

-
- -
- - -
- -
-
-
-

Program

-
- -
-
-
- -
-
-
-

Event

-
-
-
- -
-
-

Output

-
-
-
-
-
- - - - - - diff --git a/lib/vector-vrl/web-playground/public/index.js b/lib/vector-vrl/web-playground/public/index.js deleted file mode 100644 index 9ffa959c7de5c5..00000000000000 --- a/lib/vector-vrl/web-playground/public/index.js +++ /dev/null @@ -1,250 +0,0 @@ -import init, { run_vrl } from "./pkg/vector_vrl_web_playground.js"; -import { vrlLanguageDefinition, vrlThemeDefinition } from "./vrl-highlighter.js"; - -const PROGRAM_EDITOR_DEFAULT_VALUE = `# Remove some fields -del(.foo) - -# Add a timestamp -.timestamp = now() - -# Parse HTTP status code into local variable -http_status_code = parse_int!(.http_status) -del(.http_status) - -# Add status -if http_status_code >= 200 && http_status_code <= 299 { - .status = "success" -} else { - .status = "error" -}`; - -const EVENT_EDITOR_DEFAULT_VALUE = `{ - "message": "Hello VRL", - "foo": "delete me", - "http_status": "200" -}`; - -const OUTPUT_EDITOR_DEFAULT_VALUE = `{}`; - -const ERROR_INVALID_JSONL_EVENT_MSG = `Error attempting to parse the following string into valid JSON\n -String: {{str}} -\nEnsure that the Event editor contains valid JSON -\nCommon mistakes:\n - Trailing Commas\n Last line is a newline or whitespace\n Unbalanced curly braces - If using JSONL (one log per line), ensure each line is valid JSON\n -You can try validating your JSON here: https://jsonlint.com/ \n`; - -export class VrlWebPlayground { - constructor() { - let temp = init().then(() => { - this.run_vrl = run_vrl; - // require is provided by loader.min.js. - require.config({ - paths: { vs: "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs" }, - }); - // monaco and run_vrl will exist only inside this block - // due to http requests - // TODO: refactor function to be async and await on monaco and run_vrl - require(["vs/editor/editor.main"], () => { - this.monaco = monaco; - // set up vrl highlighting - this.monaco.languages.register( {id: 'vrl'} ); - // Register a tokens provider for the language - this.monaco.editor.defineTheme('vrl-theme', vrlThemeDefinition); - this.monaco.languages.setMonarchTokensProvider('vrl', vrlLanguageDefinition); - this.eventEditor = this.createDefaultEditor("container-event", EVENT_EDITOR_DEFAULT_VALUE, "json", "vs-light"); - this.outputEditor = this.createDefaultEditor("container-output", OUTPUT_EDITOR_DEFAULT_VALUE, "json", "vs-light"); - this.programEditor = this.createDefaultEditor("container-program", PROGRAM_EDITOR_DEFAULT_VALUE, "vrl", "vrl-theme"); - - - const queryString = window.location.search; - if (queryString.length != 0) { - const urlParams = new URLSearchParams(queryString); - const stateParam = decodeURIComponent(urlParams.get("state")); - - try { - let urlState = JSON.parse(atob(stateParam)); - - this.programEditor.setValue(urlState["program"]); - - if (urlState["is_jsonl"] == true) { - this.eventEditor.setValue(urlState["event"]); - } else { - this.eventEditor.setValue(JSON.stringify(urlState["event"], null, "\t")); - } - - console.log("[DEBUG::queryStringLogic] Current Params:", JSON.parse(atob(stateParam))); - let res = this.handleRunCode(JSON.parse(atob(stateParam))); - console.log("[DEBUG::queryStringLogic] Running VRL with current Params:", res); - } catch (e) { - this.outputEditor.setValue(`Error reading the shared URL\n${e}`); - } - } - }); - }); - } - - createDefaultEditor(elementId, value, language, theme) { - return this.monaco.editor.create(document.getElementById(elementId), { - value: value, - language: language, - theme: theme, - minimap: { enabled: false }, - automaticLayout: true, - }); - } - - getState() { - if (this.eventEditorIsJsonl()) { - return { - program: this.programEditor.getValue(), - event: this.eventEditor.getModel().getLinesContent().join("\n"), - is_jsonl: true, - error: null, - }; - } - - const editorValue = this.eventEditor.getValue(); - try { - return { - program: this.programEditor.getValue(), - event: JSON.parse((editorValue.length === 0) ? "{}" : editorValue), - is_jsonl: false, - error: null, - }; - } - catch (error) { - console.error(error); - return { - program: this.programEditor.getValue(), - event: null, - is_jsonl: false, - error: `Could not parse JSON event:\n${editorValue}`, - }; - } - return state; - } - - disableJsonLinting() { - this.monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ - validate: false - }); - } - - enableJsonLinting() { - this.monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ - validate: true - }); - } - - tryJsonParse(str) { - try { - return JSON.parse(str); - } catch (e) { - this.disableJsonLinting(); - let err = ERROR_INVALID_JSONL_EVENT_MSG.toString().replace("{{str}}", str); - this.outputEditor.setValue(err); - throw new Error(err); - } - } - - eventEditorIsJsonl() { - if (this.eventEditor.getModel().getLineCount() > 1) { - let lines = this.eventEditor.getModel().getLinesContent(); - - // if the second line is a json object - // we assume the user is attempting to pass in JSONL - // in the event editor - if (lines[1][0] == "{" && lines[1][lines[1].length - 1] == "}") { - return true; - } - - return false; - } - } - - /** - * - * @param {object} input - * - * input param is optional - * input param is mainly used when we are parsing the - * url for state parameters (when a user shared their program) - * - * { - * program: str, - * event: object - * } - */ - handleRunCode(input) { - if (this.eventEditorIsJsonl()) { - return this.handleRunCodeJsonl(); - } - - if (input == null) { - input = this.getState(); - } - if (input.error) { - this.disableJsonLinting(); - this.outputEditor.setValue(input.error); - return input; - } - - let res = this.run_vrl(input); - console.log("[DEBUG::handleRunCode()] Printing out res: ", res); - if (res.result) { - this.outputEditor.setValue(JSON.stringify(res.result, null, "\t")); - } else if (res.msg) { - // disable json linting for error msgs - // since error msgs are not valid json - this.disableJsonLinting(); - this.outputEditor.setValue(res.msg); - } - return res; - } - - handleRunCodeJsonl() { - let inputs = []; - let program = this.programEditor.getValue(); - let eventLines = this.eventEditor.getModel().getLinesContent(); - - // each line in eventLines is a json object - // we will use the same program in the program editor - // and run it against each line - eventLines.forEach((line) => { - inputs.push({ - program: program, - event: this.tryJsonParse(line) - }) - }); - - let results = []; - inputs.forEach((input) => { - results.push(this.run_vrl(input)); - }) - - let outputs = []; - results.forEach((res) => { - if (res.output != null) { - outputs.push(JSON.stringify(res["result"], null, "\t")); - } else if (res.msg != null) { - outputs.push(res["msg"]); - } - }); - this.disableJsonLinting(); - this.outputEditor.setValue(outputs.join("\n")); - return results; - } - - handleShareCode() { - let state = this.getState(); - console.log("[DEBUG::handleShareCode()] Printing out state", state); - console.log( - "[DEBUG::handleShareCode()] Printing out base64 encoded state\n", - btoa(JSON.stringify(state)) - ); - window.history.pushState(state, "", `?state=${encodeURIComponent(btoa(JSON.stringify(state)))}`); - } -} - -window.vrlPlayground = new VrlWebPlayground(); diff --git a/lib/vector-vrl/web-playground/public/package.json b/lib/vector-vrl/web-playground/public/package.json deleted file mode 100644 index fc6889020fde3d..00000000000000 --- a/lib/vector-vrl/web-playground/public/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "vector-vrl-web-playground", - "version": "0.1.0", - "files": [ - "vector_vrl_web_playground_bg.wasm", - "vector_vrl_web_playground.js", - "vector_vrl_web_playground.d.ts" - ], - "module": "vector_vrl_web_playground.js", - "types": "vector_vrl_web_playground.d.ts", - "sideEffects": false -} diff --git a/lib/vector-vrl/web-playground/public/vrl-highlighter.js b/lib/vector-vrl/web-playground/public/vrl-highlighter.js deleted file mode 100644 index 3efaed67a4a4b6..00000000000000 --- a/lib/vector-vrl/web-playground/public/vrl-highlighter.js +++ /dev/null @@ -1,636 +0,0 @@ -// VRL Language Definition -export let vrlLanguageDefinition = { - defaultToken: "invalid", - ignoreCase: true, - tokenPostfix: ".vrl", - - brackets: [ - { open: "{", close: "}", token: "delimiter.curly" }, - { open: "[", close: "]", token: "delimiter.square" }, - { open: "(", close: ")", token: "delimiter.parenthesis" }, - ], - - regEx: /\/(?!\/\/)(?:[^\/\\]|\\.)*\/[igm]*/, - - keywords: [ - "abort", - "as", - "break", - "continue", - "else", - "false", - "for", - "if", - "impl", - "in", - "let", - "loop", - "null", - "return", - "self", - "std", - "then", - "this", - "true", - "type", - "until", - "use", - "while", - ], - - // we include these common regular expressions - symbols: /[=> JsValue { #[wasm_bindgen] pub fn vector_version() -> String { - "".to_string() + built_info::VECTOR_VERSION.to_string() } #[wasm_bindgen] pub fn vrl_version() -> String { - "".to_string() + built_info::VRL_VERSION.to_string() }