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

change: global rules should not be executed on the internal api #3396

Merged
merged 6 commits into from
Feb 10, 2021

Conversation

nic-chen
Copy link
Member

What this PR does / why we need it:

global rules should not be executed on the internal api, currently it will run access and rewrite of plugins in global rule, so we need to change it.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

end
end

if router.api.has_route_not_under_apisix() or
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a configuration in the config.yaml for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander do you mean a switch for it ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander
I thought about it again. There shouldn't have a switch here. If skip the if branch and continue execution, a 404 will occur because the route does not exist.

And I think if need to configure the plugin for the internal api, it is more appropriate to configure a route and then configure the plugin instead of using the global rule.

What do you think ? Looking forward to your opinion. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Better to provide a switch to execute the global rule before matching internal API or don't execute the global rule. It is not skipped the internal API matched.

And I think if need to configure the plugin for the internal api, it is more appropriate to configure a route and then configure the plugin instead of using the global rule.

We can't configure a plugin for internal API, this is the real problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander Thanks for for the explanation. I know that.., emm, will update later.

Copy link
Member

Choose a reason for hiding this comment

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

OK. We can wait for it.

@spacewander spacewander changed the title chore: global rules should not be executed on the internal api change: global rules should not be executed on the internal api Jan 22, 2021
@spacewander
Copy link
Member

We need a test case for it.

@nic-chen
Copy link
Member Author

We need a test case for it.

we have test case for it, : )

t/node/global-rule.t Outdated Show resolved Hide resolved
end
end

if router.api.has_route_not_under_apisix() or
Copy link
Member

Choose a reason for hiding this comment

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

OK. We can wait for it.

apisix/init.lua Outdated
if router.api.has_route_not_under_apisix() or
core.string.has_prefix(uri, "/apisix/")
then
matched_internal_api = router.api.match(api_ctx)
Copy link
Member

Choose a reason for hiding this comment

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

The internal API will call exit inside so there is not change to execute the global rule.
Maybe we can refactor and exact the global rule code, then run it before

code, body = route.handler(api_ctx)

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, thanks!

@@ -89,6 +89,8 @@ apisix:
role: viewer

delete_uri_tail_slash: false # delete the '/' at the end of the URI
global_rule_skip_internal_api: true # does not run global rule in internal apis
Copy link
Member

Choose a reason for hiding this comment

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

Can we add test when global_rule_skip_internal_api is false?

Copy link
Member

Choose a reason for hiding this comment

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

We need to add test when global_rule_skip_internal_api is false.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to add test when global_rule_skip_internal_api is false.

sure, test failed now, submit it after solving it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander teat case added. please help review when you have time, thanks.

@spacewander spacewander merged commit 13f3139 into apache:master Feb 10, 2021
tokers pushed a commit that referenced this pull request Feb 18, 2021
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.

4 participants