Skip to content

Commit

Permalink
Deprecate enable_health flag
Browse files Browse the repository at this point in the history
**What**
- Deprecate the enable_health flag in the env config. Instead, enable or
  disable if the health handler is passed. This simplifies the
  configuration and be simplier for provider implementers.  They can
  choose to add there own health check flag, if they wish, but the
  default with healthcheck will now be easier.

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Oct 30, 2019
1 parent 78c25aa commit 7677057
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
r.HandleFunc("/function/{name:["+NameExpression+"]+}/", handlers.FunctionProxy)
r.HandleFunc("/function/{name:["+NameExpression+"]+}/{params:.*}", handlers.FunctionProxy)

if config.EnableHealth {
if handlers.HealthHandler != nil {
r.HandleFunc("/healthz", handlers.HealthHandler).Methods("GET")
}

Expand Down
7 changes: 6 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ type FaaSHandlers struct {
LogHandler http.HandlerFunc

// UpdateHandler an existing function/service
UpdateHandler http.HandlerFunc
UpdateHandler http.HandlerFunc
// HealthHandler defines the default health endpoint bound to "/healthz
// If the handler is not set, then the "/healthz" path will not be configured
HealthHandler http.HandlerFunc
InfoHandler http.HandlerFunc
ListNamespaceHandler http.HandlerFunc
Expand All @@ -42,6 +44,9 @@ type FaaSConfig struct {
// HTTP timeout for writing a response from functions.
WriteTimeout time.Duration
// EnableHealth enables/disables the default health endpoint bound to "/healthz".
//
// Deprecated: basic auth is enabled automatcally by setting the HealthHandler in the FaaSHandlers
// struct. This value is not longer read or used.
EnableHealth bool
// EnableBasicAuth enforces basic auth on the API. If set, reads secrets from file-system
// location specificed in `SecretMountPath`.
Expand Down
5 changes: 2 additions & 3 deletions types/read_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ func ParseString(val string, fallback string) string {
// Read fetches config from environmental variables.
func (ReadConfig) Read(hasEnv HasEnv) (*FaaSConfig, error) {
cfg := &FaaSConfig{
ReadTimeout: ParseIntOrDurationValue(hasEnv.Getenv("read_timeout"), time.Second*10),
WriteTimeout: ParseIntOrDurationValue(hasEnv.Getenv("write_timeout"), time.Second*10),
// default value from Gateway
ReadTimeout: ParseIntOrDurationValue(hasEnv.Getenv("read_timeout"), time.Second*10),
WriteTimeout: ParseIntOrDurationValue(hasEnv.Getenv("write_timeout"), time.Second*10),
EnableBasicAuth: ParseBoolValue(hasEnv.Getenv("basic_auth"), false),
// default value from Gateway
SecretMountPath: ParseString(hasEnv.Getenv("secret_mount_path"), "/run/secrets/"),
Expand Down
15 changes: 15 additions & 0 deletions types/read_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ func TestRead_BasicAuth_SetTrue(t *testing.T) {
}
}

func TestRead_EnableHealth_Ignored(t *testing.T) {
defaults := NewEnvBucket()
defaults.Setenv("enable_health", "true")

readConfig := ReadConfig{}
config, err := readConfig.Read(defaults)
if err != nil {
t.Fatalf("unexpected error while reading config")
}

if config.EnableBasicAuth != false {
t.Fatalf("config.EnableHealth, is deprecated but got: %t\n", config.EnableBasicAuth)
}
}

func TestRead_MaxIdleConnsDefaults(t *testing.T) {
defaults := NewEnvBucket()

Expand Down

0 comments on commit 7677057

Please sign in to comment.