Change some config around DISABLE_PROFILER, ENABLE_RELOAD and DISABLE_TRACING

This commit is contained in:
Duke Nguyen 2020-07-22 14:07:39 +00:00
parent ee8837f101
commit bddf9f8561
2 changed files with 21 additions and 16 deletions

View file

@ -255,8 +255,8 @@ spec:
value: "gcp" value: "gcp"
# - name: DISABLE_TRACING # - name: DISABLE_TRACING
# value: "1" # value: "1"
- name: DISABLE_PROFILER # - name: DISABLE_PROFILER
value: "1" # value: "1"
# - name: JAEGER_SERVICE_ADDR # - name: JAEGER_SERVICE_ADDR
# value: "jaeger-collector:14268" # value: "jaeger-collector:14268"
resources: resources:
@ -360,6 +360,7 @@ spec:
- name: server - name: server
# image: gcr.io/qwiklab-gke-debugging/productcatalogservice:v0.1.0 # image: gcr.io/qwiklab-gke-debugging/productcatalogservice:v0.1.0
image: gcr.io/cloud-ops-demo-app/productservice:latest image: gcr.io/cloud-ops-demo-app/productservice:latest
# imagePullPolicy: Always
ports: ports:
- containerPort: 3550 - containerPort: 3550
env: env:
@ -369,12 +370,12 @@ spec:
# value: "1" # value: "1"
# - name: DISABLE_TRACING # - name: DISABLE_TRACING
# value: "1" # value: "1"
- name: DISABLE_PROFILER # - name: DISABLE_PROFILER
value: "1" # value: "1"
- name: ENABLE_RELOAD # - name: ENABLE_RELOAD
value: "1" # value: "1"
- name: LATENCY_SPIKE # - name: LATENCY_SPIKE
value: "1" # value: "1"
# - name: JAEGER_SERVICE_ADDR # - name: JAEGER_SERVICE_ADDR
# value: "jaeger-collector:14268" # value: "jaeger-collector:14268"
readinessProbe: readinessProbe:

View file

@ -28,7 +28,7 @@ import (
// "syscall" // "syscall"
"time" "time"
"math/rand" "math/rand"
// "strconv" "strconv"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto" pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto"
healthpb "google.golang.org/grpc/health/grpc_health_v1" healthpb "google.golang.org/grpc/health/grpc_health_v1"
@ -76,6 +76,7 @@ func init() {
} }
func main() { func main() {
if os.Getenv("DISABLE_TRACING") == "" { if os.Getenv("DISABLE_TRACING") == "" {
log.Info("Tracing enabled.") log.Info("Tracing enabled.")
go initTracing() go initTracing()
@ -112,6 +113,8 @@ func main() {
extraLatency = time.Duration(0) extraLatency = time.Duration(0)
} }
rand.Seed(time.Now().UnixNano())
if os.Getenv("PORT") != "" { if os.Getenv("PORT") != "" {
port = os.Getenv("PORT") port = os.Getenv("PORT")
} }
@ -242,12 +245,10 @@ func (p *productCatalog) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Hea
func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) { func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) {
time.Sleep(extraLatency) time.Sleep(extraLatency)
if s := os.Getenv("LATENCY_SPIKE"); s != "" { if s := os.Getenv("LATENCY_SPIKE"); s != "" {
// v, err := strconv.Atoi(s) now := time.Now()
// if err != nil { secs := now.Unix()
// log.Fatalf("faigit chaled to parse EXTRA_LATENCY (%s) as int: %+v", v, err) i, _ := strconv.Atoi(s)
// } n := rand.Float64() * rand.Float64() * float64(i) * float64(int(secs / 15) % 5) + 1 // n will be between 0 and v
// rand.Seed(time.Now().UnixNano())
n := 3 + rand.Intn(25) // n will be between 0 and v
time.Sleep(time.Duration(n)*time.Second) time.Sleep(time.Duration(n)*time.Second)
log.Infof("extra latency enabled (duration: %v)", extraLatency) log.Infof("extra latency enabled (duration: %v)", extraLatency)
} else { } else {
@ -258,7 +259,10 @@ func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProdu
func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductRequest) (*pb.Product, error) { func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductRequest) (*pb.Product, error) {
if s := os.Getenv("LATENCY_SPIKE"); s != "" { if s := os.Getenv("LATENCY_SPIKE"); s != "" {
n := 3 + rand.Intn(25) // n will be between 0 and v i, _ := strconv.Atoi(s)
now := time.Now()
secs := now.Unix()
n := rand.Float64() * rand.Float64() * float64(i) * float64(int(secs / 15) % 5) + 1 // n will be between 0 and v
time.Sleep(time.Duration(n)*time.Second) time.Sleep(time.Duration(n)*time.Second)
log.Infof("extra latency enabled (duration: %v)", extraLatency) log.Infof("extra latency enabled (duration: %v)", extraLatency)
} else { } else {