Skip to content

Debug log job definitions obtained by lava-worker using `repr()`

Upstream MR: https://gitlab.com/lava/lava/-/merge_requests/2273

Currently the lava-worker to debug log obtained job definitions uses yaml_safe_load to load them in to dictionary and then passes the parsed dictionary to the logger.

This causes several issues.

First, this loses the accurate representation of the definitions YAML string. What if the string is not a valid YAML for some reason? We would never know the original string.

Second, if YAML loading failed the entire worker would crash. Now only the lava-run would crash which would fail the job. Using the debug logs it would be possible to look in to original YAML string and see how exactly it was malformed.

Third, this has significant performance cost. Parsing YAML is expensive even with C extensions. Even if debug log level was not enabled the yaml_safe_load was placed in the function call arguments meaning it would always be executed and instantly discarded as parsed dictionary is not used anywhere else in the function.

So instead use the raw YAML string and log it with the %r formatter which would pass it through the repr() function. This would mean the unpritable characters like \0 would still be visible in the log. Also the repr() call would only happen if the logger is enabled improving the performance.

Merge request reports