From c3c1d0c2fe8f21d6f5496e08e7d000a94faf3184 Mon Sep 17 00:00:00 2001 From: Kyle Brennan Date: Sun, 22 Mar 2020 17:31:02 -0400 Subject: [PATCH] Add hey sample function Use it to do load testing and observe scaling. Signed-off-by: Kyle Brennan --- sample-functions/hey/Dockerfile | 33 +++++++++++++++++++++++++++++++++ sample-functions/hey/readme.md | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 sample-functions/hey/Dockerfile create mode 100644 sample-functions/hey/readme.md diff --git a/sample-functions/hey/Dockerfile b/sample-functions/hey/Dockerfile new file mode 100644 index 00000000..8988c0c8 --- /dev/null +++ b/sample-functions/hey/Dockerfile @@ -0,0 +1,33 @@ +FROM openfaas/classic-watchdog:0.18.1 as watchdog + +FROM alpine:3.11 + +RUN mkdir -p /home/app + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog + +# Add non root user +RUN addgroup -S app && adduser app -S -G app && chown app /home/app + +WORKDIR /home/app + +# setup hey +RUN apk --no-cache add curl && curl -o /home/app/hey https://storage.googleapis.com/hey-release/hey_linux_amd64 && chmod +x /home/app/hey + +# Change from root user +USER app + +# Setup some timeouts for this function... +ENV write_timeout="60" + +# Run the function +ENV fprocess="xargs ./hey" +# Set to true to see request in function logs +ENV write_debug="false" + +EXPOSE 8080 + +HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/sample-functions/hey/readme.md b/sample-functions/hey/readme.md new file mode 100644 index 00000000..42a5241c --- /dev/null +++ b/sample-functions/hey/readme.md @@ -0,0 +1,25 @@ +# Overview + +[`hey` is a HTTP load generator.](https://github.com/rakyll/hey). + +This is a OpenFaaS Dockerfile function, it wraps `hey`. + +Use it to test your functions! + +For example, generate load and watch them scale up and down!!! + +## Demo + +1. Deploy the `nodeinfo` function +2. Deploy this function +3. Send a request like through the `hey` function to load test the `nodeinfo` function + +```$ +-m POST -d '{}' http://127.0.0.1:8080/function/nodeinfo.openfaas-fn +``` + +## Tips + +* `hey` does not randomize the request payload, there's nothing saying you cannot call it a bunch with different payloads, though. +* `hey` defaults Content-Type to "text/html". +* `hey` requires parameters to be in a certain order. For example, if you don't use the order above, the post body may be empty.