Merge branch 'master' into cartservice-tests

This commit is contained in:
David Mailhot 2020-01-22 15:52:33 -08:00
commit 31e34ece97
17 changed files with 84 additions and 104 deletions

2
.gitignore vendored
View file

@ -8,4 +8,4 @@ pkg/
.vs/
.idea
.skaffold-*.yaml
.kubernetes-manifests-*/
.kubernetes-manifests-*/

View file

@ -34,7 +34,7 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).
| Service | Language | Description |
| ---------------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| [frontend](./src/frontend) | Go | Exposes an HTTP server to serve the website. Does not require signup/login and generates session IDs for all users automatically. |
| [cartservice](./src/cartservice) | C# | Stores the items in the user's shipping cart in Redis and retrieves it. |
| [cartservice](./src/cartservice) | C# | Stores the items in the user's shopping cart in Redis and retrieves it. |
| [productcatalogservice](./src/productcatalogservice) | Go | Provides the list of products from a JSON file and ability to search products and get individual products. |
| [currencyservice](./src/currencyservice) | Node.js | Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service. |
| [paymentservice](./src/paymentservice) | Node.js | Charges the given credit card info (mock) with the given amount and returns a transaction ID. |
@ -93,8 +93,7 @@ We offer three installation methods:
- kubectl (can be installed via `gcloud components install kubectl`)
- Docker for Desktop (Mac/Windows): It provides Kubernetes support as [noted
here](https://docs.docker.com/docker-for-mac/kubernetes/).
- [skaffold](https://skaffold.dev/docs/getting-started/#installing-skaffold)
(ensure version ≥v0.20)
- [skaffold]( https://skaffold.dev/docs/install/) (ensure version ≥v0.20)
1. Launch “Docker for Desktop”. Go to Preferences:
@ -213,35 +212,28 @@ by deploying the [release manifest](./release) directly to an existing cluster.
--istio-config=auth=MTLS_PERMISSIVE
```
> NOTE: If you need to enable `MTLS_STRICT` mode, you will need to update
> several manifest files:
>
> - `kubernetes-manifests/frontend.yaml`: delete "livenessProbe" and
> "readinessProbe" fields.
> - `kubernetes-manifests/loadgenerator.yaml`: delete "initContainers" field.
1. (Optional) Enable Stackdriver Tracing/Logging with Istio Stackdriver Adapter
2. (Optional) Enable Stackdriver Tracing/Logging with Istio Stackdriver Adapter
by [following this guide](https://cloud.google.com/istio/docs/istio-on-gke/installing#enabling_tracing_and_logging).
1. Install the automatic sidecar injection (annotate the `default` namespace
3. Install the automatic sidecar injection (annotate the `default` namespace
with the label):
```sh
kubectl label namespace default istio-injection=enabled
```
1. Apply the manifests in [`./istio-manifests`](./istio-manifests) directory.
4. Apply the manifests in [`./istio-manifests`](./istio-manifests) directory.
(This is required only once.)
```sh
kubectl apply -f ./istio-manifests
```
1. Deploy the application with `skaffold run --default-repo=gcr.io/[PROJECT_ID]`.
5. Deploy the application with `skaffold run --default-repo=gcr.io/[PROJECT_ID]`.
1. Run `kubectl get pods` to see pods are in a healthy and ready state.
6. Run `kubectl get pods` to see pods are in a healthy and ready state.
1. Find the IP address of your Istio gateway Ingress or Service, and visit the
7. Find the IP address of your Istio gateway Ingress or Service, and visit the
application.
```sh

View file

@ -34,6 +34,8 @@ spec:
env:
- name: PORT
value: "8080"
- name: ENABLE_PROFILER
value: "0"
readinessProbe:
periodSeconds: 5
exec:
@ -42,9 +44,6 @@ spec:
periodSeconds: 5
exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"]
env:
- name: ENABLE_PROFILER
value: "0"
resources:
requests:
cpu: 100m

View file

@ -24,6 +24,8 @@ spec:
metadata:
labels:
app: frontend
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
containers:
- name: server

View file

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
@ -25,20 +24,11 @@ spec:
metadata:
labels:
app: loadgenerator
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
terminationGracePeriodSeconds: 5
restartPolicy: Always
initContainers:
- name: wait-frontend
image: alpine:3.6
command: ['sh', '-c', 'set -x; apk add --no-cache curl &&
until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do
echo "waiting for http://${FRONTEND_ADDR}";
sleep 2;
done;']
env:
- name: FRONTEND_ADDR
value: "frontend:80"
containers:
- name: main
image: loadgenerator
@ -53,4 +43,4 @@ spec:
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
memory: 512Mi

View file

@ -32,12 +32,14 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.3
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"
- name: ENABLE_PROFILER
value: "0"
readinessProbe:
periodSeconds: 5
exec:
@ -46,9 +48,6 @@ spec:
periodSeconds: 5
exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"]
env:
- name: ENABLE_PROFILER
value: "0"
resources:
requests:
cpu: 100m
@ -85,7 +84,7 @@ spec:
spec:
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.3
ports:
- containerPort: 5050
readinessProbe:
@ -148,7 +147,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.3
ports:
- containerPort: 8080
readinessProbe:
@ -199,10 +198,12 @@ spec:
metadata:
labels:
app: frontend
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/frontend:v0.1.2
image: gcr.io/google-samples/microservices-demo/frontend:v0.1.3
ports:
- containerPort: 8080
readinessProbe:
@ -290,7 +291,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.3
ports:
- containerPort: 50051
env:
@ -339,7 +340,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.3
ports:
- containerPort: 3550
env:
@ -391,7 +392,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.3
ports:
- containerPort: 7070
env:
@ -444,23 +445,14 @@ spec:
metadata:
labels:
app: loadgenerator
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
terminationGracePeriodSeconds: 5
restartPolicy: Always
initContainers:
- name: wait-frontend
image: alpine:3.6
command: ['sh', '-c', 'set -x; apk add --no-cache curl &&
until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do
echo "waiting for http://${FRONTEND_ADDR}";
sleep 2;
done;']
env:
- name: FRONTEND_ADDR
value: "frontend:80"
containers:
- name: main
image: gcr.io/google-samples/microservices-demo/loadgenerator:v0.1.2
image: gcr.io/google-samples/microservices-demo/loadgenerator:v0.1.3
env:
- name: FRONTEND_ADDR
value: "frontend:80"
@ -490,7 +482,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.3
ports:
- name: grpc
containerPort: 7000
@ -539,7 +531,7 @@ spec:
spec:
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.3
ports:
- containerPort: 50051
env:
@ -645,7 +637,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/google-samples/microservices-demo/adservice:v0.1.2
image: gcr.io/google-samples/microservices-demo/adservice:v0.1.3
ports:
- containerPort: 9555
env:

26
src/cartservice/genproto.sh Executable file
View file

@ -0,0 +1,26 @@
#!/bin/bash -eu
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Generate the C# code for .proto files
set -e
PROTODIR=../../pb
# enter this directory
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
protoc --csharp_out=$CWD/grpc_generated -I $PROTODIR $PROTODIR/demo.proto

View file

@ -1,4 +1,4 @@
FROM python:3-slim as base
FROM python:3.7-slim as base
FROM base as builder

View file

@ -37,7 +37,9 @@ import googlecloudprofiler
try:
sampler = always_on.AlwaysOnSampler()
exporter = stackdriver_exporter.StackdriverExporter()
exporter = stackdriver_exporter.StackdriverExporter(
project_id=os.environ.get('GCP_PROJECT_ID'),
transport=AsyncTransport)
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter)
except:
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()

View file

@ -37,4 +37,5 @@ def getJSONLogger(name):
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.propagate = False
return logger

View file

@ -15,4 +15,7 @@ COPY --from=builder /install /usr/local
COPY . .
RUN chmod +x ./loadgen.sh
RUN apt-get -qq update \
&& apt-get install -y --no-install-recommends \
curl
ENTRYPOINT ./loadgen.sh

View file

@ -1,4 +1,4 @@
#!/bin/sh -eu
#!/bin/bash
#
# Copyright 2018 Google LLC
#
@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#!/bin/bash
set -e
trap "exit" TERM
@ -24,4 +23,13 @@ if [[ -z "${FRONTEND_ADDR}" ]]; then
fi
set -x
locust --host="http://${FRONTEND_ADDR}" --no-web -c "${USERS:-10}"
# if one request to the frontend fails, then exit
STATUSCODE=$(curl --silent --output /dev/stderr --write-out "%{http_code}" http://${FRONTEND_ADDR})
if test $STATUSCODE -ne 200; then
echo "Error: Could not reach frontend - Status code: ${STATUSCODE}"
exit 1
fi
# else, run loadgen
locust --host="http://${FRONTEND_ADDR}" --no-web -c "${USERS:-10}" 2>&1

View file

@ -1,9 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -1,30 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[prune]
go-tests = true
unused-packages = true

View file

@ -37,4 +37,5 @@ def getJSONLogger(name):
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.propagate = False
return logger

View file

@ -99,7 +99,9 @@ if __name__ == "__main__":
try:
sampler = always_on.AlwaysOnSampler()
exporter = stackdriver_exporter.StackdriverExporter()
exporter = stackdriver_exporter.StackdriverExporter(
project_id=os.environ.get('GCP_PROJECT_ID'),
transport=AsyncTransport)
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter)
except:
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()
@ -123,7 +125,8 @@ if __name__ == "__main__":
product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel)
# create gRPC server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # ,interceptors=(tracer_interceptor,))
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
interceptors=(tracer_interceptor,))
# add class to gRPC server
service = RecommendationService()