Implement log proxy handler

**What**
- Implement log handler method that will hijack the connection and clear
timeouts to allow long lived streams
- Proxies requests to the logs provider and returns the response
unmodified

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
Lucas Roesler
2019-03-10 14:34:45 +01:00
committed by Alex Ellis
parent 3c4077f3df
commit e7e91ecd15
5 changed files with 158 additions and 0 deletions

View File

@ -31,4 +31,7 @@ type HandlerSet struct {
// SecretHandler allows secrets to be managed
SecretHandler http.HandlerFunc
// LogProxyHandler allows streaming of logs for functions
LogProxyHandler http.HandlerFunc
}

View File

@ -72,6 +72,16 @@ func (ReadConfig) Read(hasEnv HasEnv) GatewayConfig {
}
}
if len(hasEnv.Getenv("logs_provider_url")) > 0 {
var err error
cfg.LogsProviderURL, err = url.Parse(hasEnv.Getenv("logs_provider_url"))
if err != nil {
log.Fatal("If logs_provider_url is provided, then it should be a valid URL.", err)
}
} else if cfg.FunctionsProviderURL != nil {
cfg.LogsProviderURL, _ = url.Parse(cfg.FunctionsProviderURL.String())
}
faasNATSAddress := hasEnv.Getenv("faas_nats_address")
if len(faasNATSAddress) > 0 {
cfg.NATSAddress = &faasNATSAddress
@ -158,6 +168,9 @@ type GatewayConfig struct {
// URL for alternate functions provider.
FunctionsProviderURL *url.URL
// URL for alternate function logs provider.
LogsProviderURL *url.URL
// Address of the NATS service. Required for async mode.
NATSAddress *string