Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass without exception if jinja parameter isn't found #6101

Closed
wants to merge 17 commits into from

Conversation

guzzijones
Copy link
Contributor

If a jinja parameter doesn't exist as an input parameter then do not throw an exception and leave the value as a string parameter.
We have some input paramters like:

{ "test": "{{some_text_here}}"}

These cause stackstorm to attempt to resolve some_text_here as a variable since it has matching {{ and }}.

This pr would allow those through as normal strings if they cannot be resolved.

@pull-request-size pull-request-size bot added the size/M PR that changes 30-99 lines. Good size to review. label Dec 21, 2023
@CLAassistant
Copy link

CLAassistant commented Dec 21, 2023

CLA assistant check
All committers have signed the CLA.

@arm4b

This comment was marked as off-topic.

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could:

  • collect a list of nodes (vars) that aren't valid as template vars
  • if ANY of the vars DO exist, throw an error for the missing nodes.
  • if NONE of the vars exist, then assume it is a string and ignore.

Otherwise, I'm concerned this could hide misspellings.

@guzzijones
Copy link
Contributor Author

I don't understand:

collect a list of nodes (vars) that aren't valid as template vars

@guzzijones
Copy link
Contributor Author

guzzijones commented Feb 24, 2024

Most, if not all, my actions already have a jinja template parameter for {{config_context.var}}. So I don't think check if ALL are parameters would work in my case.

We have a lot of log files with {{...}} in the json as a string. These are unable to be processed by Stackstorm currently.
I actually don't understand the use case for putting {{...}} templating parameter evaluation inside stackstorm except for the case of config context or secrets from the KV store.

One can always just utilize a parameter in their python script.

@nzlosh
Copy link
Contributor

nzlosh commented Feb 24, 2024

I'd rather see a more deterministic method to processing (or not) template strings. For example, adding a new input data type raw_string, which will not attempt to process the input variable and treat it at as raw string until it is handed off to the workflow/action. string would remain unchanged and process strings against template detection.

@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/M PR that changes 30-99 lines. Good size to review. labels Mar 8, 2024
fix tests so they do not check for exception for rendering parameters

remove debugging and clean up comments

remove comments in params rendering code

black fixes st2common tests

remove unused var
@guzzijones guzzijones force-pushed the upstream_embedded_jinja branch from e795566 to 9f46039 Compare March 8, 2024 21:17
st2common/st2common/util/param.py Outdated Show resolved Hide resolved
st2common/st2common/util/param.py Outdated Show resolved Hide resolved
@guzzijones
Copy link
Contributor Author

It would be nice to get this merged in. We have a lot of logs with {{ strings in them that we feed into st2.

@guzzijones
Copy link
Contributor Author

Can we get some eyes on this?

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tree traversal logic is confusing for me. 😅 Here's a few more questions as I try to grok this logic.

st2common/st2common/util/param.py Outdated Show resolved Hide resolved
st2common/st2common/util/param.py Outdated Show resolved Hide resolved
st2common/st2common/util/param.py Outdated Show resolved Hide resolved
st2common/st2common/util/param.py Outdated Show resolved Hide resolved
@cognifloyd
Copy link
Member

I can follow the logic in this PR, and it seems like it would be functional. So, I give a technical approval of the implementation.

I'm still hesitant on this change. I'm worried about backwards incompatibility and silently ignoring actual errors. I also see how st2 is currently raising false positive errors for strings that are not Jinja.

If other members of the TSC agree with this change, then I'll approve it.

@nzlosh
Copy link
Contributor

nzlosh commented Nov 20, 2024

I'd still prefer a deterministic solution to applying expression rendering to a parameter because I think this change is going to produce more confusion and loss of time for the general use case of typos or missing variables that silently pass through the input validation process.

Feeding raw logs into an action seems like an edge use case and comes with less control than human input. My initial thought was to suggest log entries are sanitised before calling the action but this suffers from altering logs which would prevent or hinder further processing.

Since a new data type raw_string is an insufficient solution, I suggest we should add a new parameter flag that enables/disables the expression renderer for all data types. The renderer flag would control input processing behaviour in a similar way to immutable or secret and gives users explicit control of rendering for any input variable data type. The flag would be of type boolean and default to true to maintain backward compatibility.

This would allow ingest of raw logs without matching jinja expressions and still provide correct input validation processing with jinja expression rendering for the general use case. The only use case that would not be handled by this would be when someone attempts to send a mixture of rendered and non-rendered jinja expressions in the same input. In the case of mixed expression patterns, post-input processing would be required to tease out the parts needed to be rendered verses non-rendered.

Thoughts?

@guzzijones
Copy link
Contributor Author

guzzijones commented Nov 21, 2024 via email

@guzzijones
Copy link
Contributor Author

This PR is basically dead. I am going to close this and do a 'render flag' PR. @nzlosh @cognifloyd sound good?

@guzzijones guzzijones closed this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L PR that changes 100-499 lines. Requires some effort to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants