1. environment variable HTTP_500_PERCENT to inject errors
2. modify locust to not use keep alive
This commit is contained in:
mikecohen 2019-07-22 16:47:40 -07:00
parent bbb2ac1fc4
commit 6c6ed09951
4 changed files with 21 additions and 9 deletions

View file

@ -63,6 +63,8 @@ spec:
value: "checkoutservice:5050" value: "checkoutservice:5050"
- name: AD_SERVICE_ADDR - name: AD_SERVICE_ADDR
value: "adservice:9555" value: "adservice:9555"
- name: HTTP_500_PERCENT
value: "3"
# - name: JAEGER_SERVICE_ADDR # - name: JAEGER_SERVICE_ADDR
# value: "jaeger-collector:14268" # value: "jaeger-collector:14268"
resources: resources:

View file

@ -45,11 +45,10 @@ func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) {
currencies, err := fe.getCurrencies(r.Context()) currencies, err := fe.getCurrencies(r.Context())
// NOTE: This artificially injects failures in a fixed percentage of the responess // 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) renderHTTPError(log, r, w, errors.Wrap(err, "Random artificial 500 error"), http.StatusInternalServerError)
return return
} }
if err != nil { if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError) renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
return return

View file

@ -20,6 +20,7 @@ import (
"net/http" "net/http"
"os" "os"
"time" "time"
"strconv"
"cloud.google.com/go/profiler" "cloud.google.com/go/profiler"
"contrib.go.opencensus.io/exporter/stackdriver" "contrib.go.opencensus.io/exporter/stackdriver"
@ -78,6 +79,8 @@ type frontendServer struct {
adSvcAddr string adSvcAddr string
adSvcConn *grpc.ClientConn adSvcConn *grpc.ClientConn
errorRate int
} }
func main() { func main() {
@ -110,6 +113,13 @@ func main() {
mustMapEnv(&svc.checkoutSvcAddr, "CHECKOUT_SERVICE_ADDR") mustMapEnv(&svc.checkoutSvcAddr, "CHECKOUT_SERVICE_ADDR")
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR") mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
mustMapEnv(&svc.adSvcAddr, "AD_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.currencySvcConn, svc.currencySvcAddr)
mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr) mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr)

View file

@ -29,25 +29,26 @@ products = [
'OLJCESPC7Z'] 'OLJCESPC7Z']
def index(l): def index(l):
l.client.get("/") l.client.get("/", headers={'connection': 'close'})
def setCurrency(l): def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD'] currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency", l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)}) {'currency_code': random.choice(currencies)}, headers={'connection': 'close'})
def browseProduct(l): def browseProduct(l):
l.client.get("/product/" + random.choice(products)) l.client.get("/product/" + random.choice(products), headers={'connection': 'close'})
def viewCart(l): def viewCart(l):
l.client.get("/cart") l.client.get("/cart", headers={'connection': 'close'})
def addToCart(l): def addToCart(l):
product = random.choice(products) product = random.choice(products)
l.client.get("/product/" + product) l.client.get("/product/" + product)
l.client.post("/cart", { l.client.post("/cart", {
'product_id': product, '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): def checkout(l):
addToCart(l) addToCart(l)
@ -62,7 +63,7 @@ def checkout(l):
'credit_card_expiration_month': '1', 'credit_card_expiration_month': '1',
'credit_card_expiration_year': '2039', 'credit_card_expiration_year': '2039',
'credit_card_cvv': '672', 'credit_card_cvv': '672',
}) }, headers={'connection': 'close'})
class UserBehavior(TaskSet): class UserBehavior(TaskSet):