From 4604271076a96ae70b4488afdc516f62fd802dd7 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" <alex@openfaas.com> Date: Tue, 30 Aug 2022 14:00:00 +0100 Subject: [PATCH] Introduce welcome message and change default timeout The welcome message shows the difference between Pro and CE. The timeout of 8 seconds was never going to be useful as a default, so changing to 60 seconds. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com> --- gateway/main.go | 20 ++++++++------------ gateway/types/readconfig.go | 2 +- gateway/types/readconfig_test.go | 15 +++++++++------ gateway/version/version.go | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/gateway/main.go b/gateway/main.go index a8ebf9da..dfc7c446 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -27,10 +27,6 @@ const NameExpression = "-a-zA-Z_0-9." func main() { - if len(version.GitCommitMessage) == 0 { - version.GitCommitMessage = "See GitHub for latest changes" - } - osEnv := types.OsEnv{} readConfig := types.ReadConfig{} config, configErr := readConfig.Read(osEnv) @@ -38,15 +34,18 @@ func main() { if configErr != nil { log.Fatalln(configErr) } - - log.Printf("HTTP Read Timeout: %s", config.ReadTimeout) - log.Printf("HTTP Write Timeout: %s", config.WriteTimeout) - if !config.UseExternalProvider() { log.Fatalln("You must provide an external provider via 'functions_provider_url' env-var.") } - log.Printf("Binding to external function provider: %s", config.FunctionsProviderURL) + fmt.Printf("OpenFaaS Gateway - Community Edition (CE)\n"+ + "\nVersion: %s Commit: %s\nTimeouts: read=%s\twrite=%s\tupstream=%s\nFunction provider: %s\n\n", + version.BuildVersion(), + version.GitCommitSHA, + config.ReadTimeout, + config.WriteTimeout, + config.UpstreamTimeout, + config.FunctionsProviderURL) // credentials is used for service-to-service auth var credentials *auth.BasicAuthCredentials @@ -67,9 +66,6 @@ func main() { servicePollInterval := time.Second * 5 - metadataQuery := metrics.NewMetadataQuery(credentials) - fmt.Println(metadataQuery) - metricsOptions := metrics.BuildMetricsOptions() exporter := metrics.NewExporter(metricsOptions, credentials, config.Namespace) exporter.StartServiceWatcher(*config.FunctionsProviderURL, metricsOptions, "func", servicePollInterval) diff --git a/gateway/types/readconfig.go b/gateway/types/readconfig.go index b0b2ff9f..aea31521 100644 --- a/gateway/types/readconfig.go +++ b/gateway/types/readconfig.go @@ -59,7 +59,7 @@ func (ReadConfig) Read(hasEnv HasEnv) (*GatewayConfig, error) { PrometheusPort: 9090, } - defaultDuration := time.Second * 8 + defaultDuration := time.Second * 60 cfg.ReadTimeout = parseIntOrDurationValue(hasEnv.Getenv("read_timeout"), defaultDuration) cfg.WriteTimeout = parseIntOrDurationValue(hasEnv.Getenv("write_timeout"), defaultDuration) diff --git a/gateway/types/readconfig_test.go b/gateway/types/readconfig_test.go index e81a0276..acada92d 100644 --- a/gateway/types/readconfig_test.go +++ b/gateway/types/readconfig_test.go @@ -198,13 +198,16 @@ func TestRead_EmptyTimeoutConfig(t *testing.T) { config, _ := readConfig.Read(defaults) - if (config.ReadTimeout) != time.Duration(8)*time.Second { - t.Log("ReadTimeout incorrect") - t.Fail() + want := time.Second * 60 + got := config.ReadTimeout + if got != want { + t.Fatalf("config.ReadTimeout want: %s, but got: %s", want, got) } - if (config.WriteTimeout) != time.Duration(8)*time.Second { - t.Log("WriteTimeout incorrect") - t.Fail() + + want = time.Second * 60 + got = config.WriteTimeout + if got != want { + t.Fatalf("config.WriteTimeout want: %s, but got: %s", want, got) } } diff --git a/gateway/version/version.go b/gateway/version/version.go index e1011c27..70e5fcd1 100644 --- a/gateway/version/version.go +++ b/gateway/version/version.go @@ -8,7 +8,7 @@ var ( GitCommitSHA string // GitCommitMessage as read from the latest tag/release - GitCommitMessage string + GitCommitMessage = "See GitHub for latest changes" // DevVersion string for the development version DevVersion = "dev" -- GitLab