Merge pull request #26 from DavidSouther/hipster-shop-master

Merge in Hipster shop master
This commit is contained in:
David Souther 2019-10-18 15:26:15 -04:00 committed by GitHub
commit d6468184f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 59 additions and 72 deletions

View file

@ -50,12 +50,12 @@ spec:
readinessProbe: readinessProbe:
initialDelaySeconds: 15 initialDelaySeconds: 15
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"] command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
livenessProbe: livenessProbe:
initialDelaySeconds: 15 initialDelaySeconds: 15
periodSeconds: 10 periodSeconds: 10
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"] command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View file

@ -32,7 +32,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.2
ports: ports:
- containerPort: 8080 - containerPort: 8080
env: env:
@ -85,7 +85,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.2
ports: ports:
- containerPort: 5050 - containerPort: 5050
readinessProbe: readinessProbe:
@ -148,7 +148,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.2
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:
@ -202,7 +202,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/frontend:v0.1.1 image: gcr.io/google-samples/microservices-demo/frontend:v0.1.2
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:
@ -290,7 +290,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.2
ports: ports:
- containerPort: 50051 - containerPort: 50051
env: env:
@ -339,7 +339,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.2
ports: ports:
- containerPort: 3550 - containerPort: 3550
env: env:
@ -391,7 +391,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.2
ports: ports:
- containerPort: 7070 - containerPort: 7070
env: env:
@ -411,12 +411,12 @@ spec:
readinessProbe: readinessProbe:
initialDelaySeconds: 15 initialDelaySeconds: 15
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"] command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
livenessProbe: livenessProbe:
initialDelaySeconds: 15 initialDelaySeconds: 15
periodSeconds: 10 periodSeconds: 10
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"] command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@ -450,9 +450,9 @@ spec:
initContainers: initContainers:
- name: wait-frontend - name: wait-frontend
image: alpine:3.6 image: alpine:3.6
command: ['sh', '-c', 'set -x; apk add --no-cache curl && command: ['sh', '-c', 'set -x; apk add --no-cache curl &&
until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do
echo "waiting for http://${FRONTEND_ADDR}"; echo "waiting for http://${FRONTEND_ADDR}";
sleep 2; sleep 2;
done;'] done;']
env: env:
@ -460,7 +460,7 @@ spec:
value: "frontend:80" value: "frontend:80"
containers: containers:
- name: main - name: main
image: gcr.io/google-samples/microservices-demo/loadgenerator:v0.1.1 image: gcr.io/google-samples/microservices-demo/loadgenerator:v0.1.2
env: env:
- name: FRONTEND_ADDR - name: FRONTEND_ADDR
value: "frontend:80" value: "frontend:80"
@ -490,7 +490,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.2
ports: ports:
- name: grpc - name: grpc
containerPort: 7000 containerPort: 7000
@ -539,7 +539,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.2
ports: ports:
- containerPort: 50051 - containerPort: 50051
env: env:
@ -645,7 +645,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/adservice:v0.1.1 image: gcr.io/google-samples/microservices-demo/adservice:v0.1.2
ports: ports:
- containerPort: 9555 - containerPort: 9555
env: env:
@ -683,4 +683,4 @@ spec:
- name: grpc - name: grpc
port: 9555 port: 9555
targetPort: 9555 targetPort: 9555
--- ---

View file

@ -15,7 +15,6 @@ namespace cartservice {
public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context){ public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context){
Console.WriteLine ("Checking CartService Health"); Console.WriteLine ("Checking CartService Health");
return Task.FromResult(new HealthCheckResponse { return Task.FromResult(new HealthCheckResponse {
Status = dependency.Ping() ? HealthCheckResponse.Types.ServingStatus.Serving : HealthCheckResponse.Types.ServingStatus.NotServing Status = dependency.Ping() ? HealthCheckResponse.Types.ServingStatus.Serving : HealthCheckResponse.Types.ServingStatus.NotServing
}); });

View file

@ -14,7 +14,7 @@
<PackageReference Include="grpc.tools" Version="1.12.0" /> <PackageReference Include="grpc.tools" Version="1.12.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="StackExchange.Redis" Version="1.2.6" /> <PackageReference Include="StackExchange.Redis" Version="2.0.601" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -45,13 +45,13 @@ namespace cartservice.cartstore
var cart = new Hipstershop.Cart(); var cart = new Hipstershop.Cart();
emptyCartBytes = cart.ToByteArray(); emptyCartBytes = cart.ToByteArray();
connectionString = $"{redisAddress},ssl=false,allowAdmin=true,connectRetry=5"; connectionString = $"{redisAddress},ssl=false,allowAdmin=true,connectRetry=5";
redisConnectionOptions = ConfigurationOptions.Parse(connectionString); redisConnectionOptions = ConfigurationOptions.Parse(connectionString);
// Try to reconnect if first retry failed (up to 5 times with exponential backoff) // Try to reconnect if first retry failed (up to 5 times with exponential backoff)
redisConnectionOptions.ConnectRetry = REDIS_RETRY_NUM; redisConnectionOptions.ConnectRetry = REDIS_RETRY_NUM;
redisConnectionOptions.ReconnectRetryPolicy = new ExponentialRetry(100); redisConnectionOptions.ReconnectRetryPolicy = new ExponentialRetry(100);
redisConnectionOptions.KeepAlive = 180; redisConnectionOptions.KeepAlive = 180;
} }
@ -78,11 +78,11 @@ namespace cartservice.cartstore
Console.WriteLine("Connecting to Redis: " + connectionString); Console.WriteLine("Connecting to Redis: " + connectionString);
redis = ConnectionMultiplexer.Connect(redisConnectionOptions); redis = ConnectionMultiplexer.Connect(redisConnectionOptions);
if (redis == null || !redis.IsConnected) if (redis == null || !redis.IsConnected)
{ {
Console.WriteLine("Wasn't able to connect to redis"); Console.WriteLine("Wasn't able to connect to redis");
// We weren't able to connect to redis despite 5 retries with exponential backoff // We weren't able to connect to redis despite 5 retries with exponential backoff
throw new ApplicationException("Wasn't able to connect to redis"); throw new ApplicationException("Wasn't able to connect to redis");
} }
@ -96,14 +96,14 @@ namespace cartservice.cartstore
Console.WriteLine($"Small test result: {res}"); Console.WriteLine($"Small test result: {res}");
redis.InternalError += (o, e) => { Console.WriteLine(e.Exception); }; redis.InternalError += (o, e) => { Console.WriteLine(e.Exception); };
redis.ConnectionRestored += (o, e) => redis.ConnectionRestored += (o, e) =>
{ {
isRedisConnectionOpened = true; isRedisConnectionOpened = true;
Console.WriteLine("Connection to redis was retored successfully"); Console.WriteLine("Connection to redis was retored successfully");
}; };
redis.ConnectionFailed += (o, e) => redis.ConnectionFailed += (o, e) =>
{ {
Console.WriteLine("Connection failed. Disposing the object"); Console.WriteLine("Connection failed. Disposing the object");
isRedisConnectionOpened = false; isRedisConnectionOpened = false;
}; };
@ -118,9 +118,9 @@ namespace cartservice.cartstore
try try
{ {
EnsureRedisConnected(); EnsureRedisConnected();
var db = redis.GetDatabase(); var db = redis.GetDatabase();
// Access the cart from the cache // Access the cart from the cache
var value = await db.HashGetAsync(userId, CART_FIELD_NAME); var value = await db.HashGetAsync(userId, CART_FIELD_NAME);
@ -202,7 +202,6 @@ namespace cartservice.cartstore
{ {
try try
{ {
var redis = ConnectionMultiplexer.Connect(redisConnectionOptions);
var cache = redis.GetDatabase(); var cache = redis.GetDatabase();
var res = cache.Ping(); var res = cache.Ping();
return res != TimeSpan.Zero; return res != TimeSpan.Zero;

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 FROM base as builder

View file

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

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) handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(handler)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
logger.propagate = False
return logger return logger