Merge branch 'master' into oc-instrument-python

This commit is contained in:
Chris Kleinknecht 2018-12-10 23:10:58 -08:00
commit 679ffec91e
No known key found for this signature in database
GPG key ID: 860B7D4FF3B8AC6C
20 changed files with 76 additions and 59 deletions

View file

@ -4,7 +4,7 @@ services:
- docker - docker
install: install:
- curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v0.16.0/skaffold-linux-amd64 - curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v0.18.0/skaffold-linux-amd64
- chmod +x skaffold - chmod +x skaffold
- sudo mv skaffold /usr/local/bin - sudo mv skaffold /usr/local/bin

View file

@ -103,24 +103,17 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).
kubectl get nodes kubectl get nodes
2. Enable Google Container Registry (GCR) on your GCP project and configure the 1. Enable Google Container Registry (GCR) on your GCP project and configure the
`docker` CLI to authenticate to GCR: `docker` CLI to authenticate to GCR:
gcloud services enable containerregistry.googleapis.com gcloud services enable containerregistry.googleapis.com
gcloud auth configure-docker -q gcloud auth configure-docker -q
3. Set your project ID on image names: 1. In the root of this repository, run `skaffold run --default-repo=gcr.io/[PROJECT_ID]`,
where [PROJECT_ID] is your GCP project ID.
- Edit `skaffold.yaml`, update the `imageName:` fields that look like
`gcr.io/[PROJECT_ID]` with your own GCP project ID. This command:
- Similarly, edit all Kubernetes Deployment manifests in the
[`./kubernetes-manifests`](./kubernetes-manifests) directory. Find the
`image:` fields with `gcr.io/[...]` and change them to your own GCP project
ID.
5. Run `skaffold run` from the root of this repository. This command:
- builds the container images - builds the container images
- pushes them to GCR - pushes them to GCR
- applies the `./kubernetes-manifests` deploying the application to - applies the `./kubernetes-manifests` deploying the application to
@ -128,9 +121,9 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).
**Troubleshooting:** If you get "No space left on device" error on Google Cloud Shell, **Troubleshooting:** If you get "No space left on device" error on Google Cloud Shell,
you can build the images on Google Cloud Build: you can build the images on Google Cloud Build:
[Enable the Cloud Build API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com), then run `skaffold run -p gcb` instead. [Enable the Cloud Build API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com), then run `skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID]` instead.
6. Find the IP address of your application, then visit the application on your 1. Find the IP address of your application, then visit the application on your
browser to confirm installation. browser to confirm installation.
kubectl get service frontend-external kubectl get service frontend-external
@ -168,7 +161,7 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).
This is required only once. This is required only once.
5. Deploy the application with `skaffold run`. 5. Deploy the application with `skaffold run --default-repo=gcr.io/[PROJECT_ID]`.
6. 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.

View file

@ -1,17 +1,25 @@
# This file is used to build and deploy the app into a GKE cluster using Google # This configuration file is used to build and deploy the app into a
# Cloud Build. # GKE cluster using Google Cloud Build.
# #
# Requirements: # PREREQUISITES:
# - Give the Google Cloud Build service account "Kubernetes Engine Developer" # - Cloud Build service account must have role: "Kubernetes Engine Developer"
# IAM role on the GCP project.
# - Set up Google Cloud Build trigger on Cloud Console. # USAGE:
# GCP zone and GKE target cluster must be specified as substitutions
# Example invocation:
# `gcloud builds submit --config=cloudbuild.yaml --substitutions=_ZONE=us-central1-b,_CLUSTER=demo-app-staging .`
steps: steps:
- name: gcr.io/k8s-skaffold/skaffold:v0.16.0 - id: 'Deploy application to cluster'
args: ['skaffold', 'run', '-f=skaffold.yaml'] name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0'
env: entrypoint: 'bash'
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-b' args:
- 'CLOUDSDK_CONTAINER_CLUSTER=demo-app-staging' - '-c'
timeout: 1800s - >
options: # Add more power, and more time, for heavy Skaffold build gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER;
machineType: 'N1_HIGHCPU_8' skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID;
# Add more power, and more time, for heavy Skaffold build
timeout: '3600s'
options:
machineType: 'N1_HIGHCPU_8'

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/adservice image: adservice
ports: ports:
- containerPort: 9555 - containerPort: 9555
env: env:

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/cartservice image: cartservice
ports: ports:
- containerPort: 7070 - containerPort: 7070
env: env:

View file

@ -24,7 +24,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/checkoutservice image: checkoutservice
ports: ports:
- containerPort: 5050 - containerPort: 5050
readinessProbe: readinessProbe:

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/currencyservice image: currencyservice
ports: ports:
- name: grpc - name: grpc
containerPort: 7000 containerPort: 7000

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: emailservice - name: emailservice
image: gcr.io/microservices-demo-app/emailservice image: emailservice
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:

View file

@ -24,7 +24,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/frontend image: frontend
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:

View file

@ -38,7 +38,7 @@ spec:
value: "frontend:80" value: "frontend:80"
containers: containers:
- name: main - name: main
image: gcr.io/microservices-demo-app/loadgenerator image: loadgenerator
env: env:
- name: FRONTEND_ADDR - name: FRONTEND_ADDR
value: "frontend:80" value: "frontend:80"

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/paymentservice image: paymentservice
ports: ports:
- containerPort: 50051 - containerPort: 50051
readinessProbe: readinessProbe:

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/productcatalogservice image: productcatalogservice
ports: ports:
- containerPort: 3550 - containerPort: 3550
readinessProbe: readinessProbe:

View file

@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
containers: containers:
- name: recommendationservice - name: recommendationservice
image: gcr.io/microservices-demo-app/recommendationservice image: recommendationservice
ports: ports:
- containerPort: 8080 - containerPort: 8080
readinessProbe: readinessProbe:

View file

@ -24,7 +24,7 @@ spec:
spec: spec:
containers: containers:
- name: server - name: server
image: gcr.io/microservices-demo-app/shippingservice image: shippingservice
ports: ports:
- containerPort: 50051 - containerPort: 50051
readinessProbe: readinessProbe:

View file

@ -16,27 +16,31 @@ apiVersion: skaffold/v1alpha5
kind: Config kind: Config
build: build:
artifacts: artifacts:
- image: gcr.io/microservices-demo-app/emailservice # image tags are relative; to specify an image repo (e.g. GCR), you
# must provide a "default repo" using one of the methods described
# here:
# https://github.com/GoogleContainerTools/skaffold/blob/master/docs/concepts.adoc#2-push
- image: emailservice
context: src/emailservice context: src/emailservice
- image: gcr.io/microservices-demo-app/productcatalogservice - image: productcatalogservice
context: src/productcatalogservice context: src/productcatalogservice
- image: gcr.io/microservices-demo-app/recommendationservice - image: recommendationservice
context: src/recommendationservice context: src/recommendationservice
- image: gcr.io/microservices-demo-app/shippingservice - image: shippingservice
context: src/shippingservice context: src/shippingservice
- image: gcr.io/microservices-demo-app/checkoutservice - image: checkoutservice
context: src/checkoutservice context: src/checkoutservice
- image: gcr.io/microservices-demo-app/paymentservice - image: paymentservice
context: src/paymentservice context: src/paymentservice
- image: gcr.io/microservices-demo-app/currencyservice - image: currencyservice
context: src/currencyservice context: src/currencyservice
- image: gcr.io/microservices-demo-app/cartservice - image: cartservice
context: src/cartservice context: src/cartservice
- image: gcr.io/microservices-demo-app/frontend - image: frontend
context: src/frontend context: src/frontend
- image: gcr.io/microservices-demo-app/loadgenerator - image: loadgenerator
context: src/loadgenerator context: src/loadgenerator
- image: gcr.io/microservices-demo-app/adservice - image: adservice
context: src/adservice context: src/adservice
tagPolicy: tagPolicy:
gitCommit: {} gitCommit: {}

View file

@ -207,16 +207,24 @@ public class AdService {
// Registers logging trace exporter. // Registers logging trace exporter.
LoggingTraceExporter.register(); LoggingTraceExporter.register();
long sleepTime = 10; /* seconds */ long sleepTime = 10; /* seconds */
int maxAttempts = 3; int maxAttempts = 5;
boolean statsExporterRegistered = false;
boolean traceExporterRegistered = false;
for (int i=0; i<maxAttempts; i++) { for (int i=0; i<maxAttempts; i++) {
try { try {
StackdriverTraceExporter.createAndRegister( if (!traceExporterRegistered) {
StackdriverTraceConfiguration.builder().build()); StackdriverTraceExporter.createAndRegister(
StackdriverStatsExporter.createAndRegister( StackdriverTraceConfiguration.builder().build());
StackdriverStatsConfiguration.builder() traceExporterRegistered = true;
.setExportInterval(Duration.create(15, 0)) }
.build()); if (!statsExporterRegistered) {
StackdriverStatsExporter.createAndRegister(
StackdriverStatsConfiguration.builder()
.setExportInterval(Duration.create(60, 0))
.build());
statsExporterRegistered = true;
}
} catch (Exception e) { } catch (Exception e) {
if (i==(maxAttempts-1)) { if (i==(maxAttempts-1)) {
logger.log(Level.WARN, "Failed to register Stackdriver Exporter." + logger.log(Level.WARN, "Failed to register Stackdriver Exporter." +

View file

@ -99,6 +99,7 @@ func main() {
} }
func initStats(exporter *stackdriver.Exporter) { func initStats(exporter *stackdriver.Exporter) {
view.SetReportingPeriod(60 * time.Second)
view.RegisterExporter(exporter) view.RegisterExporter(exporter)
if err := view.Register(ocgrpc.DefaultServerViews...); err != nil { if err := view.Register(ocgrpc.DefaultServerViews...); err != nil {
log.Warn("Error registering default server views") log.Warn("Error registering default server views")

View file

@ -143,6 +143,7 @@ func main() {
} }
func initStats(log logrus.FieldLogger, exporter *stackdriver.Exporter) { func initStats(log logrus.FieldLogger, exporter *stackdriver.Exporter) {
view.SetReportingPeriod(60 * time.Second)
view.RegisterExporter(exporter) view.RegisterExporter(exporter)
if err := view.Register(ochttp.DefaultServerViews...); err != nil { if err := view.Register(ochttp.DefaultServerViews...); err != nil {
log.Warn("Error registering http default server views") log.Warn("Error registering http default server views")

View file

@ -90,6 +90,7 @@ func run(port int) string {
} }
func initStats(exporter *stackdriver.Exporter) { func initStats(exporter *stackdriver.Exporter) {
view.SetReportingPeriod(60 * time.Second)
view.RegisterExporter(exporter) view.RegisterExporter(exporter)
if err := view.Register(ocgrpc.DefaultServerViews...); err != nil { if err := view.Register(ocgrpc.DefaultServerViews...); err != nil {
log.Info("Error registering default server views") log.Info("Error registering default server views")

View file

@ -129,6 +129,7 @@ func (s *server) ShipOrder(ctx context.Context, in *pb.ShipOrderRequest) (*pb.Sh
} }
func initStats(exporter *stackdriver.Exporter) { func initStats(exporter *stackdriver.Exporter) {
view.SetReportingPeriod(60 * time.Second)
view.RegisterExporter(exporter) view.RegisterExporter(exporter)
if err := view.Register(ocgrpc.DefaultServerViews...); err != nil { if err := view.Register(ocgrpc.DefaultServerViews...); err != nil {
log.Warn("Error registering default server views") log.Warn("Error registering default server views")