-
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
Add document that explains the new policies system #512
Conversation
7497017
to
ce0cdec
Compare
@nmasse-itix this might be interesting to you, review/suggestion much welcomed |
`init_worker`, `rewrite`, `access`, `balancer`, `header_filter`, `body_filter`, | ||
`post_action`, and `log`. | ||
|
||
Policies can share data between them. They do that through what we call the |
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.
maybe say "share data between phases" to be even more explicit (or people could understand sharing between policies)
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 things are possible.
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.
To clarify, whatever you write in the context will be available in later phases of the same policy and in other policies as well. Do you think that's clear in the document?
that describes what to run in `access` and `header_filter`. Assume also that | ||
when describing the chain, we indicate that policy A should be run before | ||
policy B. When APIcast receives a request, it will check the policy chain | ||
described to see what it should run on each phase: |
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.
what would the term/name to use here? "policy chain definition" (sustantivo)
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.
Not sure what you mean here @andrewdavidmackenzie
doc/policies.md
Outdated
when describing the chain, we indicate that policy A should be run before | ||
policy B. When APIcast receives a request, it will check the policy chain | ||
described to see what it should run on each phase: | ||
- rewrite: execute what policy A specifies for this phase. |
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.
"execute the method/function policy A provides for this phase" or similar?
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.
✅
- post_action: do nothing. Neither policy A nor B describe what to do. | ||
- log: do nothing. Neither policy A nor B describe what to do. | ||
|
||
Notice that we did not indicate what APIcast does in the `init` and the |
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.
Instead of describing "in the negative", explain this as part of APIcast start-up before this, then move onto the description of handling requests?
for a given service. This means that we can apply different policies to our | ||
services, or the same policies but configured differently, or in a different | ||
order. On the other hand, there's only one global chain, and the behavior it | ||
defines applies to all the services. |
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.
so, policies defined by both chains will be run?
How is order defined between policies in the global chain and policies in the service 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.
Yes, per-service are included as part of the global one.
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.
The order of policies in the global chain is configurable. The order of policies in per-service chains is also configurable.
doc/policies.md
Outdated
[Policy](../gateway/src/apicast/policy.lua) and defines a method for each of | ||
the phases where it needs to execute something. | ||
|
||
Suppose that we wanted to run a policy that logged some message in the |
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.
"logged a message"
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.
✅
doc/policies.md
Outdated
-- Read something from the context. | ||
local smth = context.something | ||
|
||
-- Write 'b' in the context so other policies or later phases can read it. |
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.
"into" maybe...
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.
✅
local _M = policy.new('My custom policy') | ||
local new = _M.new | ||
|
||
function _M.new(config) |
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.
Maybe explain when new() is called?
How to store values from the config it receives for use in the per-request methods later?
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 think that documenting when it's instantiated it's too much detail for this document.
Your second question is exactly what I wanted to show with this example. See self.option_a
and self.option_b
below.
``` | ||
|
||
In the [policy folder](../gateway/src/apicast/policy) you can find several | ||
policies. These ones are quite simple and can be used as examples to write your |
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.
"They are quite..."
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 don't think that's correct, because I'm not listing all of them, just some examples.
doc/policies.md
Outdated
|
||
## Integrate your policies | ||
|
||
At some point, it will be possible to configure policies through the 3scale UI, |
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.
"configure policies and policy chains" ?
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.
✅
doc/policies.md
Outdated
## Integrate your policies | ||
|
||
At some point, it will be possible to configure policies through the 3scale UI, | ||
but you can also integrate them in APIcast using a configuration file. Remember |
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.
use the same verb: "configure"?
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.
✅
doc/policies.md
Outdated
Here's an example that shows how to define a policy chain with the CORS policy | ||
and the APIcast one. Please note that the configuration of services is more | ||
complex than shown here. This is a very simplified version to illustrate how | ||
policies can be integrated: |
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.
"configured"?
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.
✅
doc/policies.md
Outdated
} | ||
``` | ||
|
||
If instead of configuring the policy chain of a specific service, you need to |
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.
"you want to"...
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.
✅
doc/policies.md
Outdated
|
||
If instead of configuring the policy chain of a specific service, you need to | ||
customize the global policy chain, you can take a look at | ||
[this example](../examples/policy_chain/README.md). |
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.
Good job David and Michal! We're on our way to vast improvements......
d2f1e29
to
4f96811
Compare
Thanks for the review @andrewdavidmackenzie . I addressed all your comments. |
4f96811
to
defc79b
Compare
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.
Love it! 🥇
I think it nails the level of detail to be usable but not to dive into too technical details to be overwhelming.
Closes #509
/cc @3scale/documentation