Skip to content

Commit

Permalink
Config updater improvements (#151)
Browse files Browse the repository at this point in the history
* Initial improvements to keep some of the code parsing over

- Can now parse epoch and encode as well as basic response.body.x

* Finished converting all functions except collect over to the config-updater

* Fixed formatting

* Cleaned up the Display Code for Path

* Simplified and fixed the converting of Json object queries

* Fixed the stack overflow bug

- If there was an comparison operators in an expression, it caused a constant stack climb and it repeatedly called display
- Also cleaned up some of the log messages

* Added code to handle parsing of expressions with right hand side

* config-updater updates

- Added fix for empty strings that are parsed as templates with no pieces
- Added initial code to allow parsing of Segments with rest into multiple segments

* Added fix for sting values

* Fixed the complex expressions to parse expressions with vars/providers in them

* Fixed Clippy warnings

* comments and fixes

- Fixed PathSegements that were array references that were quoting the number
- Renamed to_convert() to convert_to_v2() to better describe the functionality
- Added some comments to the parsing Uniform functions

* cargo fmt

* Changed the default order of loggers

* Added code to handle base expresssions with right hand side operations

* Removed ignore that we've removed the dependency

* Changed npm install in build-guide to npm ci

* Updated test for change to logger order

* Updated README

* Updated bugs in the README

* Added an additional bug to README with workaround
  • Loading branch information
tkmcmaster authored Sep 26, 2023
1 parent 0d8ac54 commit de04df8
Show file tree
Hide file tree
Showing 14 changed files with 683 additions and 57 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ C:\vcpkg> set VCPKGRS_DYNAMIC=1 (or simply set it as your environment variable)
Changes:
- Major changes: Javascript scripting!
- Updated config-wasm to parse legacy and scripting yaml files
- New binary pewpew-config-updater will attempt to convert legacy config yamls to the new version. If it can't convert the code it will leave in PLACEHOLDERS and TODO
- Known issues:
- Expressions in vars will not wrap environment variables in the expected `${e:VAR}`
- vars in `logs` and `provides` will not have the prepended `_v.` before the var name.

Bugs:
- Collect returns an array of strings regardless of input type
- auto-converter removes code templates. Leave in and TODO
- Collect returns an array of strings regardless of input type. Workaround, use scripting to `.map(parseInt)`.
- Declare expressions that create strings will escape out any json/quotes. No workaround currently.
- Vars cannot be decimal point values. Ex `peakLoad: 0.87`. Workaround: `peakLoad: ${x:0.87}`
- global loggers may not be running in try script

Bug fixes:
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ unmaintained = "warn"
yanked = "warn"
notice = "warn"
ignore = [
"RUSTSEC-2020-0071",
# "RUSTSEC-2020-0071",
]

[licenses]
Expand Down
2 changes: 1 addition & 1 deletion guide/build-guide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ wasm-pack build --release -t bundler -d $CFG_GEN_OUTPUT_REACT_DIR --scope fs

# build the results viewer (which includes putting the output into the book's src)
cd $RESULTS_VIEWER_REACT_DIR
npm install
npm ci
npm run build

# build the book
Expand Down
2 changes: 1 addition & 1 deletion guide/serve-guide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ wasm-pack build --release -t bundler -d $CFG_GEN_OUTPUT_REACT_DIR --scope fs

# build the results viewer (which includes putting the output into the book's src)
cd $RESULTS_VIEWER_REACT_DIR
npm install
npm ci
npm run build

# build the book
Expand Down
4 changes: 2 additions & 2 deletions lib/config-gen/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ loggers:
timestamp: epoch("ms")
for_each: []
where: null
limit: null
to: stdout
pretty: false
limit: null
kill: false
test2:
query: null
limit: null
to: !file out.txt
pretty: false
limit: null
kill: false
providers:
sequence: !list
Expand Down
59 changes: 51 additions & 8 deletions lib/config/src/configv1/convert_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,60 @@ fn map_query(
for_each: Vec<WithMarker<String>>,
where_clause: Option<WithMarker<String>>,
) -> Option<Query<False>> {
if let Some(w) = where_clause {
// Fallback query if we can't parse anything
let empty_query = Query::simple("PLEASE_UPDATE_MANUALLY".to_owned(), vec![], None).unwrap();

// Attempt to parse the where_clause
let where_clause = if let Some(w) = where_clause {
let w = w.destruct().0;
log::warn!("query `where` item {w:?} must be updated manually");
Some(w)
} else {
None
};
// Attempt to parse the for_each
let for_each: Vec<String> = for_each
.iter()
.map(|fe| (fe.inner.to_string(), fe.marker).0)
.collect();

// See if we can create a fallback with the where and for_each but without the select
let manual_query = match Query::simple(
"PLEASE_UPDATE_MANUALLY".to_owned(),
for_each.clone(),
where_clause.clone(),
) {
Ok(q) => q,
Err(e) => {
log::warn!("query `where` or `for_each` item must be updated manually: {e:?}");
empty_query
}
};
for_each.into_iter().for_each(|fe| {
let fe = fe.destruct().0;
log::warn!("query `for_each` item {fe:?} must be updated manually");
});

// Finally attempt to parse the select but fallback to the manual_query or empty_query
select.map(|s| {
log::warn!("query `select` item {s:?} must be updated manually");
Query::simple("PLEASE_UPDATE_MANUALLY".to_owned(), vec![], None).unwrap()
let select_temp = s.inner();
log::debug!("select_temp query: {select_temp}");
let query = match select_temp {
json::Value::Object(_) => {
log::info!("Object query: {select_temp}");
Query::<False>::complex_json(
format!("{select_temp}").as_str(),
for_each,
where_clause,
)
}
json::Value::String(s) => Query::simple(s.to_string(), for_each, where_clause),
_ => Query::simple(format!("{select_temp}"), for_each, where_clause),
};
let query = match query {
Ok(q) => q,
Err(e) => {
log::warn!("query `select` {select_temp} must be updated manually: {e:?}");
manual_query
}
};
log::debug!("new query: {query:?}");
query
})
}

Expand Down
Loading

0 comments on commit de04df8

Please sign in to comment.