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

Fix bug in export() applied to policies in the local chain #673

Merged
merged 4 commits into from
Apr 23, 2018

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Apr 19, 2018

Fixes #672

@@ -45,6 +46,9 @@ local rewrite = _M.rewrite

function _M:rewrite(context, ...)
build_chain(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be nicer if build_chain would return the policy_chain object? Then we would not have to call find_policy_chain twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. It looks more readable. Changed in new commit.

@@ -45,6 +46,9 @@ local rewrite = _M.rewrite

function _M:rewrite(context, ...)
build_chain(context)

context = LinkedList.readwrite(context, find_policy_chain(context):export())
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this call self:export() instead of find_local_policy_chain ?

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 don't see it. export is not defined in the local chain class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Would it make sense to add it to:
https://github.com/3scale/apicast/blob/85a14f2b5cecb199b856264df1b2e2de6b4cd9da/gateway/src/apicast/policy.lua#L11-L17

Then we should be able to just call it and it would create proper delegator.

Copy link
Contributor Author

@davidor davidor Apr 23, 2018

Choose a reason for hiding this comment

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

I'm not sure. The case of export is a bit different from the rest of phases.

In the rest of phases, we just call that phase for each of the policies. export needs to build a list instead. Like in https://github.com/3scale/apicast/blob/869aa91a3e435cdb1f30cdc5fac698d3adba83f5/gateway/src/apicast/policy_chain.lua#L114

I wouldn't change this now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only the PolicyChain merges those exports. The rest of policies just export something. I think that is exactly the same as the other phases. And if every policy would have an export function we could get rid of the or:
https://github.com/3scale/apicast/blob/869aa91a3e435cdb1f30cdc5fac698d3adba83f5/gateway/src/apicast/policy_chain.lua#L120
Making it easier for LuaJIT.

No need to change this. I just thought it would be even nicer cleanup to treat all phases the same.

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'd leave this for a future PR.

davidor added 4 commits April 23, 2018 11:10
Policies can define an export function to expose the data they need to
share with other policies.

export() worked fine for policies defined in the global chain, but it
did not for policies include in a local (service level) chain. Whatever
was returned in export() did not end up begin in the shared context.
This commit solves the issue.
Makes the code a bit more readable.
@davidor davidor force-pushed the fix-local-chain-export branch from 85a14f2 to 5bfeba3 Compare April 23, 2018 09:11
@davidor
Copy link
Contributor Author

davidor commented Apr 23, 2018

Rebased to solve the changelog conflicts.

Copy link
Contributor

@mikz mikz left a comment

Choose a reason for hiding this comment

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

👍

@davidor davidor merged commit b7018b3 into master Apr 23, 2018
@davidor davidor deleted the fix-local-chain-export branch April 23, 2018 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants