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

[THREESCALE-1709] Routing policy #976

Merged
merged 13 commits into from
Jan 15, 2019
Merged

[THREESCALE-1709] Routing policy #976

merged 13 commits into from
Jan 15, 2019

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Jan 8, 2019

Closes #972

This PR adds a new policy, routing. It can select an upstream based on the request path, a request header, a request query argument, and a JWT claim.

I added a README that explains how the policy works.

Depends on #974 and #975

Ref: https://issues.jboss.org/browse/THREESCALE-1709

@davidor davidor requested a review from a team as a code owner January 8, 2019 14:50
@davidor davidor changed the title [WIP] Routing policy [WIP] [THREESCALE-1709] Routing policy Jan 8, 2019
@@ -0,0 +1,35 @@
local setmetatable = setmetatable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea is to use this module from other policies too.

I think we should instantiate it when the policies context is created for the current request, and store an instance of this module there. I think it would improve code organization, and also avoid reading several times the headers and the query arguments.

I'd rather do that in a different PR because it might affect many policies and need changes in some tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this should become part of the core API. For that, we need a carefully designed interface that is usable by all the policies we have so far. And that that surely wait for another PR 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@davidor
Copy link
Contributor Author

davidor commented Jan 10, 2019

@mikz I added support for conditions with 'or' and for liquid templating in the last two commits.

It's true that supporting those 2 things complicates a bit the config schema because it requires extra attributes. However, I think that those are 2 useful features and we should support them. I added them in 2 separate commits, so they can be reverted easily.

@davidor davidor changed the title [WIP] [THREESCALE-1709] Routing policy [THREESCALE-1709] Routing policy Jan 10, 2019
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.

Good job 👍

I have a few nitpicks, but nothing too critical.

@@ -0,0 +1,35 @@
local setmetatable = setmetatable
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this should become part of the core API. For that, we need a carefully designed interface that is usable by all the policies we have so far. And that that surely wait for another PR 👍

gateway/src/apicast/policy/routing/README.md Show resolved Hide resolved
gateway/src/apicast/policy/routing/apicast-policy.json Outdated Show resolved Hide resolved
--- no_error_log
[error]

=== TEST 22: the rule matches a jwt claim using "!=" and the condition is false
Copy link
Contributor

@mikz mikz Jan 15, 2019

Choose a reason for hiding this comment

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

I think this integration test has way too many test cases to be readable and understandable for me.
Testing all possible options and their negations can be done in lower level tests line unit tests.

I'd rather leave this focused on high level operations, how it treats the http request, what Host header it passes, how it mangles request path, forwards post body etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I think that for each operation (matches , == ... ) it makes sense to test both the case where it evaluates to true and false. I see what you mean, this test is too verbose, but I think part of it is because sending a request with a JWT requires quite a few lines in the config and the request.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to test both cases for each operation, but probably more in a unit test rather than integration one. Integration tests should be focused on the HTTP request itself.
I get that that unit tests might be a bit different because there is no real http request, but that is fine in my opinion. If we find out we have issues with it we try to solve that.

Maybe extracting those common parts into some shared helpers or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I think that for this particular case it's enough to test operations when they match. If we try to match a header and it works, it means that the code was able to extract the header specified correctly, which is one of the things we want to do in these integration tests. Adding an extra test with the same information but evaluating to false does not add much value.

All the operations are covered in the unit tests of the Condition module.

I deleted the redundant tests following that guideline. They went from 32 to 20: 5fa61d2

"items": {
"type": "object",
"properties": {
"url": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need just this? We don't need to control whether it rewrites Host header?

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'm not sure. Do you think we need a way to prevent rewriting the Host header?
Currently, the host is always rewritten calling this method:
https://github.com/3scale/apicast/blob/75eb7e77d466d5ac6ba0aded9446838c87414e95/gateway/src/apicast/upstream.lua#L153

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should double check with out requirements and with people using this.
Host header can be different from the hostname where the traffic should go.
There might be a need to supply own Host header in some cases.

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 think that we can leave this as it is and add the extra parameter later if needed.
Let's check with @vramosp

Copy link
Contributor

@MarkCheshire MarkCheshire Jan 17, 2019

Choose a reason for hiding this comment

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

Is it feasible to offer the following set of options?

  • Host header overwrite by new upstream host (default)
  • Host header unchanged
  • Host header manual overwrite with a new fixed value

If it adds too much complexity then stick with the first one.

Copy link
Contributor Author

@davidor davidor Jan 17, 2019

Choose a reason for hiding this comment

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

I created an issue for this: #981

I think that for this particular case it's enough to test operations
when they match. If we try to match a header and it works, it means that
the code was able to extract the header specified correctly, which is
one of the things we want to do in these integration tests. Adding an
extra test with the same information but evaluating to false does not
add much value.
@davidor davidor merged commit c214825 into master Jan 15, 2019
@davidor davidor deleted the routing-policy branch January 15, 2019 13:19
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.

3 participants