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

Bump Inja dependency #248

Merged
merged 12 commits into from
Jul 5, 2023
Merged

Bump Inja dependency #248

merged 12 commits into from
Jul 5, 2023

Conversation

jbohanon
Copy link
Contributor

Uses thread-local storage to pass request data into the TransformerInstance so that we can use the instance (and its registered callbacks) to parse templates at init time.

extractions, json_body, environ_,
cluster_metadata, rng_);

tls_->set([header_map=&header_map, request_headers, get_body, extractions=&extractions, json_body=&json_body, environ=&environ_, cluster_metadata, rng=&rng_](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr {
Copy link
Member

Choose a reason for hiding this comment

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

you can't call set() from transform() as set will set the object on all worker threads.
call set() from the ctor (you only need to call it one time).
Here you can call getTyped and update the existing object

Copy link
Contributor Author

@jbohanon jbohanon Jun 25, 2023

Choose a reason for hiding this comment

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

I changed this to have a set() call construct an empty object during the InjaTransformer constructor, then request context is populated by getting a reference to the thread-local object with getTyped. Is this more in line with how this should be used?

Copy link
Contributor Author

@jbohanon jbohanon left a comment

Choose a reason for hiding this comment

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

I still want to add tests for JSON pointer syntax Added

@solo-changelog-bot
Copy link

Issues linked to changelog:
solo-io/gloo#8177
#247

@@ -115,7 +122,8 @@ class InjaTransformer : public Transformer {

absl::optional<inja::Template> body_template_;
bool merged_extractors_to_body_{};
Envoy::Random::RandomGenerator &rng_;
ThreadLocal::SlotPtr tls_;
std::unique_ptr<TransformerInstance> instance_;
Copy link
Member

Choose a reason for hiding this comment

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

micro-nit: i don't think this needs to be a pointer

Suggested change
std::unique_ptr<TransformerInstance> instance_;
TransformerInstance instance_;

(the .cc will change a bit as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the changes for this all the way until it needs a member function (Environment::render) within the Inja library to be marked const. I think this is because we're using it within the const transform method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's unclear why the build errors occur when this field is a concrete object, but not when it is a pointer. However, the performance overhead should be negligent. We confirmed that the render calls are thread safe because the Renderer constructor that ends up being called by Inja::Environment::render takes const parameters. The same cannot be said of the Parser constructor, but we should not be calling parse on the request path anyway.

@@ -5,7 +5,7 @@ REPOSITORY_LOCATIONS = dict(
remote = "https://github.com/envoyproxy/envoy",
),
inja = dict(
commit = "4c0ee3a46c0bbb279b0849e5a659e52684a37a98",
commit = "5a18986825fc7e5d2916ff345c4369e4b6ea7122", # v3.4 + JSON Pointers
remote = "https://github.com/pantor/inja",
Copy link
Member

Choose a reason for hiding this comment

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

if your PR gets closed / deleted this might become invalid in the future.
Better to point to a commit in your fork, where you tag it so GH won't delete it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I made a solo-io fork, created a tag, and pointed to the commit in that repo. I should probably also update the source of the PR to be the solo-io branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants