Skip to content

Instantly share code, notes, and snippets.

@LucasRoesler
Created March 2, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucasRoesler/254fa07e42adb980d87e9e5a658e0743 to your computer and use it in GitHub Desktop.
Save LucasRoesler/254fa07e42adb980d87e9e5a658e0743 to your computer and use it in GitHub Desktop.
  1. install openfaas with my fork
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
helm upgrade openfaas --install openfaas/openfaas \
    --namespace openfaas  \
    --set basic_auth=true \
    --set faasnetesd.image=theaxer/faas-netes:logger \
    --set faasnetesd.imagePullPolicy=IfNotPresent \
    --set functionNamespace=openfaas-fn
  1. expose the k8s provider API
kubectl -n openfaas port-forward $(kubectl -n openfaas get po -l "app=gateway" -o name) 8081
  1. deploy a function, e.g. Alex's echo fn we use to load testing
git clone git@github.com:alexellis/echo-fn.git
cd echo-fn
faas-cli deploy --gateway http://localhost:31112
  1. generate some logs
echo "$SECONDS" | faas-cli invoke go-echo --gateway=http://localhost:31112

or

hey -c 2 -q 10 -n 100000 http://127.0.0.1:31112/function/go-echo
  1. ask the api for the function logs
curl -v -H "Connection: keep-alive" -X GET "localhost:8081/system/logs?name=go-echo&follow=true"

Notes:

The request is read from the GET parameters, as described below

type Request struct {
	// Name is the function name and is required
	Name string `json:"name"`
	// Instance is the optional container name, that allows you to request logs from a specific function instance
	Instance string `json:"instance"`
	// Since is the optional datetime value to start the logs from
	Since *time.Time `json:"since"`
	// Limit sets the maximum number of log messages to return, <=0 means unlimited
	Limit int `json:"limit"`
	// Follow is allows the user to request a stream of logs
	Follow bool `json:"follow"`
	// Pattern is an optional regexp value to filter the log messages
	Pattern *string `json:"pattern"`
	// Invert allows you to control if the Pattern should be matched or negated
	Invert bool `json:"invert"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment