diff --git a/kubernetes-manifests/frontend.yaml b/kubernetes-manifests/frontend.yaml index 5c5cd32..b783fae 100644 --- a/kubernetes-manifests/frontend.yaml +++ b/kubernetes-manifests/frontend.yaml @@ -63,6 +63,8 @@ spec: value: "checkoutservice:5050" - name: AD_SERVICE_ADDR value: "adservice:9555" + - name: HTTP_500_PERCENT + value: "3" # - name: JAEGER_SERVICE_ADDR # value: "jaeger-collector:14268" resources: diff --git a/src/frontend/handlers.go b/src/frontend/handlers.go index 46d1a6b..91e19e8 100644 --- a/src/frontend/handlers.go +++ b/src/frontend/handlers.go @@ -45,11 +45,10 @@ func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) { currencies, err := fe.getCurrencies(r.Context()) // NOTE: This artificially injects failures in a fixed percentage of the responess - if (rand.Intn(100) < 3) { + if (rand.Intn(100) < fe.errorRate) { renderHTTPError(log, r, w, errors.Wrap(err, "Random artificial 500 error"), http.StatusInternalServerError) return - } - + } if err != nil { renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError) return diff --git a/src/frontend/main.go b/src/frontend/main.go index a6bccda..1bb0b22 100644 --- a/src/frontend/main.go +++ b/src/frontend/main.go @@ -20,6 +20,7 @@ import ( "net/http" "os" "time" + "strconv" "cloud.google.com/go/profiler" "contrib.go.opencensus.io/exporter/stackdriver" @@ -78,6 +79,8 @@ type frontendServer struct { adSvcAddr string adSvcConn *grpc.ClientConn + + errorRate int } func main() { @@ -110,6 +113,13 @@ func main() { mustMapEnv(&svc.checkoutSvcAddr, "CHECKOUT_SERVICE_ADDR") mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR") mustMapEnv(&svc.adSvcAddr, "AD_SERVICE_ADDR") + i, err := strconv.Atoi(os.Getenv("HTTP_500_PERCENT")) + if err == nil { + svc.errorRate = i + log.Infof("HTTP 500 Error Rate set to " + strconv.Itoa(svc.errorRate)) + } else { + svc.errorRate = 0 + } mustConnGRPC(ctx, &svc.currencySvcConn, svc.currencySvcAddr) mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index f1f98ea..0dbc86b 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -29,25 +29,26 @@ products = [ 'OLJCESPC7Z'] def index(l): - l.client.get("/") + l.client.get("/", headers={'connection': 'close'}) def setCurrency(l): currencies = ['EUR', 'USD', 'JPY', 'CAD'] l.client.post("/setCurrency", - {'currency_code': random.choice(currencies)}) + {'currency_code': random.choice(currencies)}, headers={'connection': 'close'}) def browseProduct(l): - l.client.get("/product/" + random.choice(products)) + l.client.get("/product/" + random.choice(products), headers={'connection': 'close'}) def viewCart(l): - l.client.get("/cart") + l.client.get("/cart", headers={'connection': 'close'}) def addToCart(l): product = random.choice(products) l.client.get("/product/" + product) l.client.post("/cart", { 'product_id': product, - 'quantity': random.choice([1,2,3,4,5,10])}) + 'quantity': random.choice([1,2,3,4,5,10])}, + headers={'connection': 'close'}) def checkout(l): addToCart(l) @@ -62,7 +63,7 @@ def checkout(l): 'credit_card_expiration_month': '1', 'credit_card_expiration_year': '2039', 'credit_card_cvv': '672', - }) + }, headers={'connection': 'close'}) class UserBehavior(TaskSet):