Substitution in <dyn_variable> for JSONPath#317
Conversation
|
I'd really like to hear your feedback, @nniclausse. Mainly if this approach is at all desirable or not. And if not, if you have another idea what approach you'd see to realise such a enhancement. |
|
@nniclausse ping. I'd really like your feedback. We're using the current patch for some time now and so far it did work just fine. My idea would be to merge this now, and create follow-up issues that we also apply substitutions to other dyn var types. They might have a perf impact, as regular expressions and xpaths will require recompilation. But IMO this is okay, if we document this properly so that the users are aware of this. |
nniclausse
left a comment
There was a problem hiding this comment.
I'm OK with the general idea. Appart from the small typo, the current PR lacks some documentation and maybe some unit tests ?
src/tsung_controller/ts_config.erl
Outdated
| {xpath,Name,CompiledXPathExp}; | ||
| jsonpath -> | ||
| ?LOGF("Add new jsonpath: ~s ~n", [Expr],?INFO), | ||
| EnableSubstition = case {SubstitutionFlag, re:run(Expr, "%%.+%%")} of |
There was a problem hiding this comment.
small typo to fix here: should be EnableSubstitution
|
okay great. I'll take a look at how to test this and will add some remarks to the documentation. |
|
Do you mind to take another look, @nniclausse? I added some tests and a paragraph to the JSONpath documentation. I'm not sure how to go about mentioning unreleased versions. Is it okay to just assume that this will be in 1.8.0? |
|
Yes, that's ok, thanks ! |
Proposal for #316
This PR propagates the substitution flag from
<request subst="…">into the dynvar specification used ints_search:parse_dynvar. NOTE Onlyjsonpathhas been adjusted currently as they don't need to compile. The performance impact should be minimal.It was necessary to pass the current
DynVarsintots_search:parse_dynvarso the arity was changed from 2 to 3. For compatibility reasons (tests mainly)ts_search:parse_dynvar/2is now also present with the same behaviour as before.ts_search:parse_dynvar/3is now used byts_client:update_statsand it is the main point of entry.This PR basically allows us to have this working, which works a lot more as expected to the user:
Note, that the substitution is only performed, when the
substattribute is set totrueand we detect a variable inside the expression (%%*%%).Example
JSON document returned by https://httpbin.org/json:
{ "slideshow": { "author": "Yours Truly", "date": "date of publication", "slides": [{ "title": "Wake up to WonderWidgets!", "type": "all" }, { "items": [ "Why <em>WonderWidgets</em> are great", "Who <em>buys</em> WonderWidgets" ], "title": "Overview", "type": "all" } ], "title": "Sample Slide Show" } }Will produce:
How to proceed?