Skip to content

Commit

Permalink
Inline if statements and update README order
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed May 31, 2023
1 parent a5324bf commit 5d4cadc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 38 deletions.
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,32 @@ Environmental variables:

> Note: timeouts should be specified as Golang durations i.e. `1m` or `20s`.
| Option |Usage|
| ---------------------- |-----|
| `fprocess` / `function_process` | Process to execute a server in `http` mode or to be executed for each request in the other modes. For non `http` mode the process must accept input via STDIN and print output via STDOUT. Also known as "function process". |
| `mode` | The mode which of-watchdog operates in, Default `streaming` [see doc](#3-streaming-fork-modestreaming---default). Options are [http](#1-http-modehttp), [serialising fork](#2-serializing-fork-modeserializing), [streaming fork](#3-streaming-fork-modestreaming---default), [static](#4-static-modestatic) |
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds) |
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds) |
| `exec_timeout` | Exec timeout for process exec'd for each incoming request (in seconds). Disabled if set to 0. |
| `max_inflight` | Limit the maximum number of requests in flight, and return a HTTP status 429 when exceeded |
| `prefix_logs` | When set to `true` the watchdog will add a prefix of "Date Time" + "stderr/stdout" to every line read from the function process. Default `true` |
| `log_buffer_size` | The amount of bytes to read from stderr/stdout for log lines. When exceeded, the user will see an "bufio.Scanner: token too long" error. The default value is `bufio.MaxScanTokenSize` |
| `healthcheck_interval` | Interval (in seconds) for HTTP healthcheck by container orchestrator i.e. kubelet. Used for graceful shutdowns. |
| `port` | Specify an alternative TCP port for testing. Default: `8080` |
| `content_type` | Force a specific Content-Type response for all responses - only in forking/serializing modes. |
| `suppress_lock` | When set to `false` the watchdog will attempt to write a lockfile to `/tmp/.lock` for healthchecks. Default `false` |
| `http_upstream_url` | `http` mode only - where to forward requests i.e. `127.0.0.1:5000` |
| `upstream_url` | alias for `http_upstream_url` |
| `http_buffer_req_body` | `http` mode only - buffers request body in memory before forwarding upstream to your template's `upstream_url`. Use if your upstream HTTP server does not accept `Transfer-Encoding: chunked`, for example WSGI tends to require this setting. Default: `false` |
| `buffer_http` | deprecated alias for `http_buffer_req_body`, will be removed in future version |
| `static_path` | Absolute or relative path to the directory that will be served if `mode="static"` |
| `ready_path` | When non-empty, requests to `/_/ready` will invoke the function handler with this path. This can be used to provide custom readiness logic. When `max_inflight` is set, the concurrency limit is checked first before proxying the request to the function. |
| Option | Usage|
| -------------------------------- |---------------------------------------------------------------------|
| `buffer_http` | (Deprecated) Alias for `http_buffer_req_body`, will be removed in future version |
| `content_type` | Force a specific Content-Type response for all responses - only in forking/serializing modes. |
| `exec_timeout` | Exec timeout for process exec'd for each incoming request (in seconds). Disabled if set to 0. |
| `fprocess` / `function_process` | Process to execute a server in `http` mode or to be executed for each request in the other modes. For non `http` mode the process must accept input via STDIN and print output via STDOUT. Also known as "function process". |
| `healthcheck_interval` | Interval (in seconds) for HTTP healthcheck by container orchestrator i.e. kubelet. Used for graceful shutdowns. |
| `http_buffer_req_body` | `http` mode only - buffers request body in memory before forwarding upstream to your template's `upstream_url`. Use if your upstream HTTP server does not accept `Transfer-Encoding: chunked`, for example WSGI tends to require this setting. Default: `false` |
| `http_upstream_url` | `http` mode only - where to forward requests i.e. `http://127.0.0.1:5000` |
| `log_buffer_size` | The amount of bytes to read from stderr/stdout for log lines. When exceeded, the user will see an "bufio.Scanner: token too long" error. The default value is `bufio.MaxScanTokenSize` |
| `max_inflight` | Limit the maximum number of requests in flight, and return a HTTP status 429 when exceeded |
| `mode` | The mode which of-watchdog operates in, Default `streaming` [see doc](#3-streaming-fork-modestreaming---default). Options are [http](#1-http-modehttp), [serialising fork](#2-serializing-fork-modeserializing), [streaming fork](#3-streaming-fork-modestreaming---default), [static](#4-static-modestatic) |
| `port` | Specify an alternative TCP port for testing. Default: `8080` |
| `prefix_logs` | When set to `true` the watchdog will add a prefix of "Date Time" + "stderr/stdout" to every line read from the function process. Default `true` |
| `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds) |
| `ready_path` | When non-empty, requests to `/_/ready` will invoke the function handler with this path. This can be used to provide custom readiness logic. When `max_inflight` is set, the concurrency limit is checked first before proxying the request to the function. |
| `static_path` | Absolute or relative path to the directory that will be served if `mode="static"` |
| `suppress_lock` | When set to `false` the watchdog will attempt to write a lockfile to `/tmp/.lock` for healthchecks. Default `false` |
| `upstream_url` | Alias for `http_upstream_url` |
| `write_timeout` | HTTP timeout for writing a response body from your function (in seconds) |

Unsupported options from the [Classic Watchdog](https://github.com/openfaas/classic-watchdog):

| Option | Usage |
| ------------- | --------------------------------------------------------------------------------------------- |
| `write_debug` | In the classic watchdog, this prints the response body out to the console |
| `read_debug` | In the classic watchdog, this prints the request body out to the console |
| `combined_output` | In the classic watchdog, this returns STDOUT and STDERR in the function's HTTP response, when off it only returns STDOUT and prints STDERR to the logs of the watchdog |
| Option | Usage |
| -------------------- | --------------------------------------------------------------------------------------------- |
| `write_debug` | In the classic watchdog, this prints the response body out to the console |
| `read_debug` | In the classic watchdog, this prints the request body out to the console |
| `combined_output` | In the classic watchdog, this returns STDOUT and STDERR in the function's HTTP response, when off it only returns STDOUT and prints STDERR to the logs of the watchdog |

5 changes: 2 additions & 3 deletions executor/http_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"

units "github.com/docker/go-units"

Expand Down Expand Up @@ -98,7 +97,7 @@ func (f *HTTPFunctionRunner) Run(req FunctionRequest, contentLength int64, r *ht

var body io.Reader
if f.BufferHTTPBody {
reqBody, _ := ioutil.ReadAll(r.Body)
reqBody, _ := io.ReadAll(r.Body)
body = bytes.NewReader(reqBody)
} else {
body = r.Body
Expand Down Expand Up @@ -166,7 +165,7 @@ func (f *HTTPFunctionRunner) Run(req FunctionRequest, contentLength int64, r *ht
if res.Body != nil {
defer res.Body.Close()

bodyBytes, bodyErr := ioutil.ReadAll(res.Body)
bodyBytes, bodyErr := io.ReadAll(res.Body)
if bodyErr != nil {
log.Println("read body err", bodyErr)
}
Expand Down
5 changes: 2 additions & 3 deletions executor/serializing_fork_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"

units "github.com/docker/go-units"
Expand Down Expand Up @@ -91,7 +90,7 @@ func serializeFunction(req FunctionRequest, f *SerializingForkFunctionRunner) (*
}

var err error
data, err = ioutil.ReadAll(reader)
data, err = io.ReadAll(reader)

if err != nil {
return nil, err
Expand Down Expand Up @@ -148,7 +147,7 @@ func pipeToProcess(stdin io.WriteCloser, stdout io.Reader, data *[]byte) (*[]byt

go func(c chan error) {
var err error
result, err := ioutil.ReadAll(stdout)
result, err := io.ReadAll(stdout)
functionResult = &result
if err != nil {
c <- err
Expand Down
11 changes: 4 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -217,14 +216,12 @@ func createLockFile() (string, error) {
path := filepath.Join(os.TempDir(), ".lock")
log.Printf("Writing lock-file to: %s\n", path)

mkdirErr := os.MkdirAll(os.TempDir(), os.ModePerm)
if mkdirErr != nil {
return path, mkdirErr
if err := os.MkdirAll(os.TempDir(), os.ModePerm); err != nil {
return path, err
}

writeErr := ioutil.WriteFile(path, []byte{}, 0660)
if writeErr != nil {
return path, writeErr
if err := os.WriteFile(path, []byte{}, 0660); err != nil {
return path, err
}

atomic.StoreInt32(&acceptingConnections, 1)
Expand Down

0 comments on commit 5d4cadc

Please sign in to comment.