Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Yoshi Yamaguchi 2019-06-13 11:52:40 +08:00
commit e967007c5a
19 changed files with 85 additions and 41 deletions

View file

@ -272,6 +272,7 @@ resources.
- [Day 3 Keynote](https://youtu.be/JQPOPV_VH5w?t=815) showing Stackdriver - [Day 3 Keynote](https://youtu.be/JQPOPV_VH5w?t=815) showing Stackdriver
APM (Tracing, Code Search, Profiler, Google Cloud Build) APM (Tracing, Code Search, Profiler, Google Cloud Build)
- [Introduction to Service Management with Istio](https://www.youtube.com/watch?v=wCJrdKdD6UM&feature=youtu.be&t=586) - [Introduction to Service Management with Istio](https://www.youtube.com/watch?v=wCJrdKdD6UM&feature=youtu.be&t=586)
- [KubeCon EU 2019 - Reinventing Networking: A Deep Dive into Istio's Multicluster Gateways - Steve Dake, Independent](https://youtu.be/-t2BfT59zJA?t=982)
--- ---

View file

@ -37,6 +37,8 @@ spec:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:5050"] command: ["/bin/grpc_health_probe", "-addr=:5050"]
env: env:
- name: PORT
value: "5050"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: SHIPPING_SERVICE_ADDR - name: SHIPPING_SERVICE_ADDR

View file

@ -32,6 +32,9 @@ spec:
ports: ports:
- name: grpc - name: grpc
containerPort: 7000 containerPort: 7000
env:
- name: PORT
value: "7000"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7000"] command: ["/bin/grpc_health_probe", "-addr=:7000"]

View file

@ -31,6 +31,9 @@ spec:
image: emailservice image: emailservice
ports: ports:
- containerPort: 8080 - containerPort: 8080
env:
- name: PORT
value: "8080"
readinessProbe: readinessProbe:
periodSeconds: 5 periodSeconds: 5
exec: exec:

View file

@ -47,6 +47,8 @@ spec:
- name: "Cookie" - name: "Cookie"
value: "shop_session-id=x-liveness-probe" value: "shop_session-id=x-liveness-probe"
env: env:
- name: PORT
value: "8080"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: CURRENCY_SERVICE_ADDR - name: CURRENCY_SERVICE_ADDR

View file

@ -31,6 +31,9 @@ spec:
image: paymentservice image: paymentservice
ports: ports:
- containerPort: 50051 - containerPort: 50051
env:
- name: PORT
value: "50051"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:50051"] command: ["/bin/grpc_health_probe", "-addr=:50051"]

View file

@ -31,6 +31,9 @@ spec:
image: productcatalogservice image: productcatalogservice
ports: ports:
- containerPort: 3550 - containerPort: 3550
env:
- name: PORT
value: "3550"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:3550"] command: ["/bin/grpc_health_probe", "-addr=:3550"]

View file

@ -40,6 +40,8 @@ spec:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"] command: ["/bin/grpc_health_probe", "-addr=:8080"]
env: env:
- name: PORT
value: "8080"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: ENABLE_PROFILER - name: ENABLE_PROFILER

View file

@ -30,6 +30,9 @@ spec:
image: shippingservice image: shippingservice
ports: ports:
- containerPort: 50051 - containerPort: 50051
env:
- name: PORT
value: "50051"
readinessProbe: readinessProbe:
periodSeconds: 5 periodSeconds: 5
exec: exec:

View file

@ -48,21 +48,6 @@ spec:
number: 80 number: 80
--- ---
apiVersion: networking.istio.io/v1alpha3 apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: currency-provider-external
spec:
hosts:
- www.ecb.europa.eu
ports:
- number: 80
name: http
protocol: HTTP
- number: 443
name: https
protocol: HTTPS
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService kind: VirtualService
metadata: metadata:
name: frontend name: frontend

View file

@ -32,9 +32,12 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/emailservice:v0.1.1
ports: ports:
- containerPort: 8080 - containerPort: 8080
env:
- name: PORT
value: "8080"
readinessProbe: readinessProbe:
periodSeconds: 5 periodSeconds: 5
exec: exec:
@ -43,6 +46,9 @@ spec:
periodSeconds: 5 periodSeconds: 5
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"] command: ["/bin/grpc_health_probe", "-addr=:8080"]
env:
- name: ENABLE_PROFILER
value: "0"
resources: resources:
requests: requests:
cpu: 100m cpu: 100m
@ -79,7 +85,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/checkoutservice:v0.1.1
ports: ports:
- containerPort: 5050 - containerPort: 5050
readinessProbe: readinessProbe:
@ -89,6 +95,8 @@ spec:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:5050"] command: ["/bin/grpc_health_probe", "-addr=:5050"]
env: env:
- name: PORT
value: "5050"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: SHIPPING_SERVICE_ADDR - name: SHIPPING_SERVICE_ADDR
@ -140,7 +148,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/recommendationservice:v0.1.1
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:
@ -152,8 +160,12 @@ spec:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"] command: ["/bin/grpc_health_probe", "-addr=:8080"]
env: env:
- name: PORT
value: "8080"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: ENABLE_PROFILER
value: "0"
resources: resources:
requests: requests:
cpu: 100m cpu: 100m
@ -190,7 +202,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/frontend:v0.1.0 image: gcr.io/google-samples/microservices-demo/frontend:v0.1.1
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:
@ -210,6 +222,8 @@ spec:
- name: "Cookie" - name: "Cookie"
value: "shop_session-id=x-liveness-probe" value: "shop_session-id=x-liveness-probe"
env: env:
- name: PORT
value: "8080"
- name: PRODUCT_CATALOG_SERVICE_ADDR - name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550" value: "productcatalogservice:3550"
- name: CURRENCY_SERVICE_ADDR - name: CURRENCY_SERVICE_ADDR
@ -276,9 +290,12 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/paymentservice:v0.1.1
ports: ports:
- containerPort: 50051 - containerPort: 50051
env:
- name: PORT
value: "50051"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:50051"] command: ["/bin/grpc_health_probe", "-addr=:50051"]
@ -322,9 +339,12 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/productcatalogservice:v0.1.1
ports: ports:
- containerPort: 3550 - containerPort: 3550
env:
- name: PORT
value: "3550"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:3550"] command: ["/bin/grpc_health_probe", "-addr=:3550"]
@ -371,7 +391,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/cartservice:v0.1.1
ports: ports:
- containerPort: 7070 - containerPort: 7070
env: env:
@ -440,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.0 image: gcr.io/google-samples/microservices-demo/loadgenerator:v0.1.1
env: env:
- name: FRONTEND_ADDR - name: FRONTEND_ADDR
value: "frontend:80" value: "frontend:80"
@ -470,10 +490,13 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/currencyservice:v0.1.1
ports: ports:
- name: grpc - name: grpc
containerPort: 7000 containerPort: 7000
env:
- name: PORT
value: "7000"
readinessProbe: readinessProbe:
exec: exec:
command: ["/bin/grpc_health_probe", "-addr=:7000"] command: ["/bin/grpc_health_probe", "-addr=:7000"]
@ -516,9 +539,12 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/shippingservice:v0.1.1
ports: ports:
- containerPort: 50051 - containerPort: 50051
env:
- name: PORT
value: "50051"
readinessProbe: readinessProbe:
periodSeconds: 5 periodSeconds: 5
exec: exec:
@ -619,7 +645,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/google-samples/microservices-demo/adservice:v0.1.0 image: gcr.io/google-samples/microservices-demo/adservice:v0.1.1
ports: ports:
- containerPort: 9555 - containerPort: 9555
env: env:

View file

@ -11,9 +11,16 @@ COPY . .
RUN chmod +x gradlew RUN chmod +x gradlew
RUN ./gradlew installDist RUN ./gradlew installDist
FROM openjdk:8-alpine FROM openjdk:8-slim
RUN apk add --no-cache libc6-compat # Download Stackdriver Profiler Java agent
RUN apt-get -y update && apt-get install -qqy \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /opt/cprof && \
wget -q -O- https://storage.googleapis.com/cloud-profiler/java/latest/profiler_java_agent.tar.gz \
| tar xzv -C /opt/cprof && \
rm -rf profiler_java_agent.tar.gz
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.1 && \ RUN GRPC_HEALTH_PROBE_VERSION=v0.2.1 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \

View file

@ -118,7 +118,8 @@ task adService(type: CreateStartScripts) {
outputDir = new File(project.buildDir, 'tmp') outputDir = new File(project.buildDir, 'tmp')
classpath = jar.outputs.files + project.configurations.runtime classpath = jar.outputs.files + project.configurations.runtime
defaultJvmOpts = defaultJvmOpts =
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector"] ["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
} }
task adServiceClient(type: CreateStartScripts) { task adServiceClient(type: CreateStartScripts) {
@ -127,7 +128,8 @@ task adServiceClient(type: CreateStartScripts) {
outputDir = new File(project.buildDir, 'tmp') outputDir = new File(project.buildDir, 'tmp')
classpath = jar.outputs.files + project.configurations.runtime classpath = jar.outputs.files + project.configurations.runtime
defaultJvmOpts = defaultJvmOpts =
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector"] ["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
} }
applicationDistribution.into('bin') { applicationDistribution.into('bin') {

View file

@ -46,7 +46,7 @@ const request = {
}; };
function _moneyToString (m) { function _moneyToString (m) {
return `${m.units}.${leftPad(m.nanos, 9, '0')} ${m.currency_code}`; return `${m.units}.${m.nanos.toString().padStart(9,'0')} ${m.currency_code}`;
} }
client.getSupportedCurrencies({}, (err, response) => { client.getSupportedCurrencies({}, (err, response) => {

View file

@ -16,7 +16,6 @@
"async": "^1.5.2", "async": "^1.5.2",
"google-protobuf": "^3.0.0", "google-protobuf": "^3.0.0",
"grpc": "^1.0.0", "grpc": "^1.0.0",
"left-pad": "^1.3.0",
"pino": "^5.6.2", "pino": "^5.6.2",
"request": "^2.87.0", "request": "^2.87.0",
"xml2js": "^0.4.19" "xml2js": "^0.4.19"

View file

@ -36,7 +36,7 @@ const protoLoader = require('@grpc/proto-loader');
const MAIN_PROTO_PATH = path.join(__dirname, './proto/demo.proto'); const MAIN_PROTO_PATH = path.join(__dirname, './proto/demo.proto');
const HEALTH_PROTO_PATH = path.join(__dirname, './proto/grpc/health/v1/health.proto'); const HEALTH_PROTO_PATH = path.join(__dirname, './proto/grpc/health/v1/health.proto');
const PORT = 7000; const PORT = process.env.PORT;
const shopProto = _loadProto(MAIN_PROTO_PATH).hipstershop; const shopProto = _loadProto(MAIN_PROTO_PATH).hipstershop;
const healthProto = _loadProto(HEALTH_PROTO_PATH).grpc.health.v1; const healthProto = _loadProto(HEALTH_PROTO_PATH).grpc.health.v1;

View file

@ -27,7 +27,7 @@ const logger = pino({
}); });
class HipsterShopServer { class HipsterShopServer {
constructor (protoRoot, port = HipsterShopServer.DEFAULT_PORT) { constructor (protoRoot, port = HipsterShopServer.PORT) {
this.port = port; this.port = port;
this.packages = { this.packages = {
@ -99,6 +99,6 @@ class HipsterShopServer {
} }
} }
HipsterShopServer.DEFAULT_PORT = 50051; HipsterShopServer.PORT = process.env.PORT;
module.exports = HipsterShopServer; module.exports = HipsterShopServer;

View file

@ -50,7 +50,7 @@ var (
log *logrus.Logger log *logrus.Logger
extraLatency time.Duration extraLatency time.Duration
port = flag.Int("port", 3550, "port to listen at") port = "3550"
reloadCatalog bool reloadCatalog bool
) )
@ -106,13 +106,16 @@ func main() {
} }
}() }()
log.Infof("starting grpc server at :%d", *port) if os.Getenv("PORT") != "" {
run(*port) port = os.Getenv("PORT")
}
log.Infof("starting grpc server at :%s", port)
run(port)
select {} select {}
} }
func run(port int) string { func run(port string) string {
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) l, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -60,7 +60,7 @@ func main() {
go initProfiling("shippingservice", "1.0.0") go initProfiling("shippingservice", "1.0.0")
port := defaultPort port := defaultPort
if value, ok := os.LookupEnv("APP_PORT"); ok { if value, ok := os.LookupEnv("PORT"); ok {
port = value port = value
} }
port = fmt.Sprintf(":%s", port) port = fmt.Sprintf(":%s", port)