-
Notifications
You must be signed in to change notification settings - Fork 170
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
[wip] Add maintenance mode policy #561
Conversation
1c08f2b
to
6c515ec
Compare
@@ -0,0 +1,25 @@ | |||
#Maintenance Mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github fails to render this correctly. You need to add a space after '#'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with all the other titles in this doc.
|
||
##Example Configuration | ||
```json | ||
"policy_chain": [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would wrap this between {
and }
so it becomes a valid json. Also, I think that indenting this would help readability.
|
||
|
||
function _M.new(configuration) | ||
local policy = new(configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to pass configuration
as a param here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me realize that we are doing the same in the echo policy. We'll need to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidor I think we might want to keep this as this is the signature of the initializer. That the underlying policy does not do anything with it is an implementation detail that can change in the future. What if the policy would actually store it in self.configuration
? We would have to change all policies to pass it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikz I see what you mean, but new()
here is calling function policy.new()
in policy.lua
which does not accept any parameters. Maybe we should add it then to make it less confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should document it and accept _configuration
parameter which would not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidor Ah damn. I actually followed the echo as my baseline. Are you both happy for me to keep this as the signature or change it for now?
|
||
function _M:access() | ||
|
||
local status = self.status_code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 lines are not properly indented.
return ngx.exit(ngx.status) | ||
end | ||
|
||
return _M |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github is complaining because there isn't a newline here.
Same with the rest of files included in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm is this still complaining? I'm fairly sure my git removes the last newline of a file. (I need to check this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alanmoran I think there needs to be a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevprice83 I added it and its there locally but I think git or github removing it.
t/apicast-policy-maintenance-mode.t
Outdated
"proxy": { | ||
"policy_chain": [ | ||
{ "name": "apicast.policy.maintenance_mode", | ||
"configuration": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check indentation here.
t/apicast-policy-maintenance-mode.t
Outdated
Testing 3 things: | ||
1) Check default status code | ||
2) Check default response message | ||
3) TODO - validate upstream doesn't get the request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several options. You could print something in upstream
and then check that it does not appear in the output, or you could put and assertion using luassert
.
Great job @alanmoran 👍 I added some comments about minor issues I found, but this is a good example of how to write and test a policy. I would be interested to hear if you found the documentation to be good enough and the problems you had while writing the policy. I don't think we should include this in the |
04440d0
to
e38cfa4
Compare
@davidor Thanks for the review. I really appreciate it. I've made most of the changes you've recommended and put my feedback into @vramosp feedback doc. Agree on not adding it as one of the default OOTB polices. I'll wait until I hear back about where community policies might live. Could be a good first candidate. |
consider adding as an example in a sub-folder for them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to rebase this PR as #581 added an option to add policies to the example folder. And #579 changed the structure so the main file is called init.lua
.
That should be the final structure of policies. Sorry for the hassle.
Guess we will have to figure out how to write and where to store the tests. I'd probably go for the policy itself or the examples/policies/t
for tests using several of them. But that will require some changes to our CI and the test runner. I'll make those changes soon.
0fdb184
to
ca64a78
Compare
@mikz I've rebased and moved policy to the examples folder. Updated structure to use init.lua also. You should be able to test by updating
I haven't moved the tests yet but will do once we've decided what to do with them. |
ca64a78
to
5278df3
Compare
@alanmoran good job 👍 Unfortunately, as you can see, the tests failed on CircleCI.
This is because by default, Apicast does not look for policies in the
That needs to be specified before There's another problem. All the policies that are not the built-in ones, need to have a version in the configuration so Apicast knows how to load them. So you need something like this in the configuration:
Also, notice that you specified Hope this helps. If anything is not clear or you need help please let me know. |
90c906f
to
d0fcdc3
Compare
7109d0e
to
8546b16
Compare
@davidor I've fixed up the PR. Biggest change really is that I moved the tests under In terms of |
@alanmoran after #632 is merged CI will run integration tests in |
"backend_authentication_value": "token-value", | ||
"proxy": { | ||
"policy_chain": [{ | ||
"name": "maintenance-mode", "version": "1.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid JSON and the test fails. There is missing ,
at the and of the line.
return policy | ||
end | ||
|
||
function _M:access() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both tests fail because this is supposed to be rewrite
.
APIcast policy rejects the requests in rewrite phase because they don't have authentication.
So you either want to first require authentication and then show a maintenance page or show maintenance regardless of passed authentication parameters.
8546b16
to
4579a82
Compare
@alanmoran There's a new requirement to include this policy as a builtin one. I used your commits in #1105 |
First attempt at a PR to apicast. Really basic policy just to introduce myself to Lua and writing some tests.
Wasn't sure what was the best way to test my request didn't hit upstream.
Any comments, tips or suggestions?