bookinfo doc fixes (#1817)

This commit is contained in:
Kent Rancourt 2018-07-23 23:36:23 -04:00 committed by Martin Taillefer
parent 3dee29d873
commit 217c78af01
8 changed files with 58 additions and 53 deletions

View File

@ -608,8 +608,8 @@ spec:
...
{{< /text >}}
_2. Select rule based on HTTP headers_. For example, the following rule only applies to an incoming request if it includes a "cookie" header that
contains the substring "user=jason":
_2. Select rule based on HTTP headers_. For example, the following rule only applies to an incoming request if it includes a custom "end-user" header that
contains the string "jason":
{{< text yaml >}}
apiVersion: networking.istio.io/v1alpha3
@ -622,8 +622,8 @@ spec:
http:
- match:
- headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
{{< /text >}}
@ -654,8 +654,8 @@ semantics apply, depending on the nesting.
If multiple conditions are nested in a single match clause, then the conditions
are ANDed. For example, the following rule only applies if the
client workload is "reviews:v2” AND the "cookie" header containing
"user=jason" is present in the request:
client workload is "reviews:v2" AND the custom "end-user" header containing
"jason" is present in the request:
{{< text yaml >}}
apiVersion: networking.istio.io/v1alpha3
@ -671,8 +671,8 @@ spec:
app: reviews
version: v2
headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
{{< /text >}}
@ -693,13 +693,13 @@ spec:
app: reviews
version: v2
- headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
{{< /text >}}
This rule applies if either the client workload is "reviews:v2 OR
the "cookie" header containing "user=jason" is present in the request.
This rule applies if either the client workload is "reviews:v2" OR
the custom "end-user" header containing "jason" is present in the request.
#### Precedence

View File

@ -93,9 +93,8 @@ If you look in the sample services, you can see that the productpage application
def getForwardHeaders(request):
headers = {}
user_cookie = request.cookies.get("user")
if user_cookie:
headers['Cookie'] = 'user=' + user_cookie
if 'user' in session:
headers['end-user'] = session['user']
incoming_headers = [ 'x-request-id',
'x-b3-traceid',
@ -119,8 +118,9 @@ The reviews application (Java) does something similar:
{{< text jzvz >}}
@GET
@Path("/reviews")
public Response bookReviews(@CookieParam("user") Cookie user,
@Path("/reviews/{productId}")
public Response bookReviewsById(@PathParam("productId") int productId,
@HeaderParam("end-user") String user,
@HeaderParam("x-request-id") String xreq,
@HeaderParam("x-b3-traceid") String xtraceid,
@HeaderParam("x-b3-spanid") String xspanid,
@ -128,11 +128,11 @@ public Response bookReviews(@CookieParam("user") Cookie user,
@HeaderParam("x-b3-sampled") String xsampled,
@HeaderParam("x-b3-flags") String xflags,
@HeaderParam("x-ot-span-context") String xotspan) {
String r1 = "";
String r2 = "";
int starsReviewer1 = -1;
int starsReviewer2 = -1;
if(ratings_enabled){
JsonObject ratings = getRatings(user, xreq, xtraceid, xspanid, xparentspanid, xsampled, xflags, xotspan);
if (ratings_enabled) {
JsonObject ratingsResponse = getRatings(Integer.toString(productId), user, xreq, xtraceid, xspanid, xparentspanid, xsampled, xflags, xotspan);
{{< /text >}}
When you make downstream calls in your applications, make sure to include these headers.

View File

@ -64,8 +64,8 @@ still expect the end-to-end flow to continue without any errors.
percent: 100
match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: ratings
@ -167,8 +167,8 @@ ratings not available` message.
percent: 100
match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: ratings

View File

@ -141,6 +141,11 @@ Next, you will change the route config so that all traffic from a specific user
is routed to a specific service version. In this case, all traffic from a user
named Jason will be routed to the service `reviews:v2`.
Note that Istio doesn't have any special, built-in understanding of user
identity. This example is enabled by the fact that the productpage service
adds a custom "end-user" header to all outbound HTTP requests to the reviews
service.
Remember, `reviews:v2` is the version that includes the star ratings feature.
1. Run the following command to enable the user-based routing:
@ -164,8 +169,8 @@ Remember, `reviews:v2` is the version that includes the star ratings feature.
http:
- match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: reviews
@ -192,8 +197,8 @@ You have successfully configured Istio to route traffic based on user identity.
In this task, you used Istio to send 100% of the traffic to the `v1` version
of each of the Bookinfo services. You then set a rule to selectively send traffic
to version `v2` of the reviews service based on a header (a user cookie) present in
the request.
to version `v2` of the reviews service based on a custom "end-user" header added
to the request by the productpage service.
Note that Kubernetes services, like the Bookinfo ones used in this task, must
adhere to certain restrictions to take advantage of Istio's L7 routing features.

View File

@ -239,7 +239,7 @@ spec:
...
~~~
**3. 根据 HTTP Header 选择规则。**下面的规则只会对包含了 `cookie` 头,且值为 `user=jason` 的请求生效:
**3. 根据 HTTP Header 选择规则。**下面的规则只会对包含了 `end-user` 头,且值为 `jason` 的请求生效:
~~~yaml
apiVersion: networking.istio.io/v1alpha3
@ -252,8 +252,8 @@ spec:
http:
- match:
- headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
~~~
@ -262,7 +262,7 @@ spec:
可以同时设置多个标准,在这个例子中,还包含了 AND 或 OR 的语义,这要根据具体嵌套情况进行判断。如果多个标准嵌套在同一个 match 中,这些条件就是 AND 关系。例如下面的规则的限制条件要求的是同时符合下面两个条件:
- 来源于 `reviews:v2` 服务
- "cookie" 头中包含 "user=jason”
- "end-user" 头中包含 “jason”
~~~yaml
apiVersion: networking.istio.io/v1alpha3
@ -278,8 +278,8 @@ spec:
app: reviews
version: v2
headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
~~~
@ -299,8 +299,8 @@ spec:
app: reviews
version: v2
- headers:
cookie:
regex: "^(.*?;)?(user=jason)(;.*)?$"
end-user:
exact: jason
...
~~~

View File

@ -71,9 +71,8 @@ $ kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=
def getForwardHeaders(request):
headers = {}
user_cookie = request.cookies.get("user")
if user_cookie:
headers['Cookie'] = 'user=' + user_cookie
if 'user' in session:
headers['end-user'] = session['user']
incoming_headers = [ 'x-request-id',
'x-b3-traceid',
@ -97,8 +96,9 @@ def getForwardHeaders(request):
{{< text jzvz >}}
@GET
@Path("/reviews")
public Response bookReviews(@CookieParam("user") Cookie user,
@Path("/reviews/{productId}")
public Response bookReviewsById(@PathParam("productId") int productId,
@HeaderParam("end-user") String user,
@HeaderParam("x-request-id") String xreq,
@HeaderParam("x-b3-traceid") String xtraceid,
@HeaderParam("x-b3-spanid") String xspanid,
@ -106,11 +106,11 @@ public Response bookReviews(@CookieParam("user") Cookie user,
@HeaderParam("x-b3-sampled") String xsampled,
@HeaderParam("x-b3-flags") String xflags,
@HeaderParam("x-ot-span-context") String xotspan) {
String r1 = "";
String r2 = "";
int starsReviewer1 = -1;
int starsReviewer2 = -1;
if(ratings_enabled){
JsonObject ratings = getRatings(user, xreq, xtraceid, xspanid, xparentspanid, xsampled, xflags, xotspan);
if (ratings_enabled) {
JsonObject ratingsResponse = getRatings(Integer.toString(productId), user, xreq, xtraceid, xspanid, xparentspanid, xsampled, xflags, xotspan);
{{< /text >}}
在对下游服务进行调用的时候,就应该在请求中包含上面代码中获取到的 HTTP Header。

View File

@ -54,8 +54,8 @@ aliases:
percent: 100
match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: ratings
@ -123,8 +123,8 @@ Istio 的故障注入规则可帮助您识别此类异常,而不会影响最
percent: 100
match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: ratings

View File

@ -140,8 +140,8 @@ keywords: [traffic-management,routing]
http:
- match:
- headers:
cookie:
regex: ^(.*?;)?(user=jason)(;.*)?$
end-user:
exact: jason
route:
- destination:
host: reviews
@ -158,7 +158,7 @@ keywords: [traffic-management,routing]
## 理解原理
在此任务中,您首先使用 Istio 将100%的请求流量都路由到了 BookInfo 服务的v1版本。 然后再设置了一条路由规则,该路由规则基于请求的 header例如一个用户 cookie选择性地将特定的流量路由到了 reviews 服务的v2版本。
在此任务中,您首先使用 Istio 将100%的请求流量都路由到了 BookInfo 服务的v1版本。 然后再设置了一条路由规则,该路由规则基于请求的 选择性地将特定的流量路由到了 reviews 服务的v2版本。
请注意,为了利用 Istio 的L7路由功能Kubernetes 中的服务(如本任务中使用的 Bookinfo 服务)必须遵守某些特定限制。
参考[sidecar injection documentation](/docs/setup/kubernetes/sidecar-injection/#pod-spec-requirements)了解详情。