mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Use context timeout to cancel the log request
**What** - Pass the writetimeout to the logs handler to set the context timeout of the log stream. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
db6628d1a5
commit
6df51a3516
@ -14,7 +14,7 @@ const crlf = "\r\n"
|
||||
const upstreamLogsEndpoint = "/system/logs"
|
||||
|
||||
// NewLogHandlerFunc creates and http HandlerFunc from the supplied log Requestor.
|
||||
func NewLogHandlerFunc(logProvider url.URL) http.HandlerFunc {
|
||||
func NewLogHandlerFunc(logProvider url.URL, timeout time.Duration) http.HandlerFunc {
|
||||
writeRequestURI := false
|
||||
if _, exists := os.LookupEnv("write_request_uri"); exists {
|
||||
writeRequestURI = exists
|
||||
@ -23,7 +23,9 @@ func NewLogHandlerFunc(logProvider url.URL) http.HandlerFunc {
|
||||
upstreamLogProviderBase := strings.TrimSuffix(logProvider.String(), "/")
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
ctx, cancelQuery := context.WithTimeout(r.Context(), timeout)
|
||||
defer cancelQuery()
|
||||
|
||||
if r.Body != nil {
|
||||
defer r.Body.Close()
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func main() {
|
||||
forwardingNotifiers,
|
||||
)
|
||||
|
||||
faasHandlers.LogProxyHandler = handlers.NewLogHandlerFunc(*config.LogsProviderURL)
|
||||
faasHandlers.LogProxyHandler = handlers.NewLogHandlerFunc(*config.LogsProviderURL, config.WriteTimeout)
|
||||
|
||||
if config.UseNATS() {
|
||||
log.Println("Async enabled: Using NATS Streaming.")
|
||||
|
Reference in New Issue
Block a user