Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions depot/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ type transformer struct {
tempDir string
clock clock.Clock

sidecarRootFS string
useDeclarativeHealthCheck bool
emitHealthCheckMetrics bool
healthyMonitoringInterval time.Duration
unhealthyMonitoringInterval time.Duration
gracefulShutdownInterval time.Duration
healthCheckWorkPool *workpool.WorkPool
sidecarRootFS string
useDeclarativeHealthCheck bool
declarativeHealthCheckDefaultTimeout time.Duration
emitHealthCheckMetrics bool
healthyMonitoringInterval time.Duration
unhealthyMonitoringInterval time.Duration
gracefulShutdownInterval time.Duration
healthCheckWorkPool *workpool.WorkPool

useContainerProxy bool
drainWait time.Duration
Expand All @@ -82,9 +83,14 @@ func WithSidecarRootfs(
}
}

func WithDeclarativeHealthchecks() Option {
func WithDeclarativeHealthChecks(timeout time.Duration) Option {
return func(t *transformer) {
t.useDeclarativeHealthCheck = true

if timeout <= 0 {
timeout = time.Duration(DefaultDeclarativeHealthcheckRequestTimeout) * time.Millisecond
}
t.declarativeHealthCheckDefaultTimeout = timeout
}
}

Expand Down Expand Up @@ -377,7 +383,6 @@ func (t *transformer) StepsRunner(
gardenContainer garden.Container,
logStreamer log_streamer.LogStreamer,
config Config,
// ) (ifrit.Runner, chan steps.ReadinessState, error) {
) (ifrit.Runner, chan steps.ReadinessState, error) {
var setup, action, postSetup, monitor, readinessMonitor, longLivedAction ifrit.Runner
var substeps []ifrit.Runner
Expand Down Expand Up @@ -820,9 +825,10 @@ func (t *transformer) transformReadinessCheckDefinition(
}

func (t *transformer) applyCheckDefaults(timeout int, interval time.Duration, path string) (int, time.Duration, string) {
if timeout == 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this logic about defaults to the initializer package where the config is read in? That way the t.declarativeHealthCheckDefaultTimeout property is always correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to the configuration option, which is still called only during initialization.

timeout = DefaultDeclarativeHealthcheckRequestTimeout
if timeout <= 0 {
timeout = int(t.declarativeHealthCheckDefaultTimeout / time.Millisecond)
}

if path == "" {
path = "/"
}
Expand Down
77 changes: 69 additions & 8 deletions depot/transformer/transformer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transformer_test

import (
"code.cloudfoundry.org/durationjson"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -642,7 +643,8 @@ var _ = Describe("Transformer", func() {

Context("when declarative healthchecks are enabled", func() {
BeforeEach(func() {
options = append(options, transformer.WithDeclarativeHealthchecks())
declarativeHealthCheckTimeout := 42 * time.Second
options = append(options, transformer.WithDeclarativeHealthChecks(declarativeHealthCheckTimeout))

container.StartTimeoutMs = 1000
})
Expand Down Expand Up @@ -848,7 +850,7 @@ var _ = Describe("Transformer", func() {
Path: filepath.Join(transformer.HealthCheckDstPath, "healthcheck"),
Args: []string{
"-port=8989",
"-timeout=1000ms",
"-timeout=42000ms",
"-uri=/",
fmt.Sprintf("-until-ready-interval=%s", unhealthyMonitoringInterval),
},
Expand Down Expand Up @@ -1099,12 +1101,12 @@ var _ = Describe("Transformer", func() {
Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=5432",
"-timeout=1000ms",
"-timeout=42000ms",
"-until-ready-interval=1ms",
}))
Expect(args).To(ContainElement([]string{
"-port=5432",
"-timeout=1000ms",
"-timeout=42000ms",
"-readiness-interval=1s",
}))
})
Expand Down Expand Up @@ -1400,12 +1402,71 @@ var _ = Describe("Transformer", func() {
Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-timeout=42000ms",
"-uri=/",
"-startup-interval=1ms",
"-startup-timeout=1s",
}))
})

Context("and the default declarative healthcheck timeout is not set in the spec", func() {
BeforeEach(func() {
var emptyJsonTime durationjson.Duration
declarativeHealthCheckTimeout := time.Duration(emptyJsonTime)

// This option will override the previously configured default timeout
options = append(options, transformer.WithDeclarativeHealthChecks(declarativeHealthCheckTimeout))
})

It("uses the 1s default for the timeout", func() {
Eventually(gardenContainer.RunCallCount).Should(Equal(2))
paths := []string{}
args := [][]string{}
for i := 0; i < gardenContainer.RunCallCount(); i++ {
spec, _ := gardenContainer.RunArgsForCall(i)
paths = append(paths, spec.Path)
args = append(args, spec.Args)
}

Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-uri=/",
"-startup-interval=1ms",
"-startup-timeout=1s",
}))
})
})

Context("and the declarative healthcheck timeout is set to a value <= 0", func() {
BeforeEach(func() {
declarativeHealthCheckTimeout, _ := time.ParseDuration("-24s")

// This option will override the previously configured default timeout
options = append(options, transformer.WithDeclarativeHealthChecks(declarativeHealthCheckTimeout))
})

It("uses the 1s default for the timeout", func() {
Eventually(gardenContainer.RunCallCount).Should(Equal(2))
paths := []string{}
args := [][]string{}
for i := 0; i < gardenContainer.RunCallCount(); i++ {
spec, _ := gardenContainer.RunArgsForCall(i)
paths = append(paths, spec.Path)
args = append(args, spec.Args)
}

Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-uri=/",
"-startup-interval=1ms",
"-startup-timeout=1s",
}))
})
})
})

It("uses the check definition", func() {
Expand Down Expand Up @@ -1640,7 +1701,7 @@ var _ = Describe("Transformer", func() {
Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-timeout=42000ms",
"-uri=/",
"-liveness-interval=1s",
}))
Expand Down Expand Up @@ -1745,7 +1806,7 @@ var _ = Describe("Transformer", func() {
Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-timeout=42000ms",
"-startup-interval=1ms",
"-startup-timeout=1s",
}))
Expand Down Expand Up @@ -1829,7 +1890,7 @@ var _ = Describe("Transformer", func() {
Expect(paths).To(ContainElement(filepath.Join(transformer.HealthCheckDstPath, "healthcheck")))
Expect(args).To(ContainElement([]string{
"-port=6432",
"-timeout=1000ms",
"-timeout=42000ms",
"-liveness-interval=1s",
}))
})
Expand Down
11 changes: 10 additions & 1 deletion initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type ExecutorConfig struct {
EnableContainerProxy bool `json:"enable_container_proxy,omitempty"`
EnableContainerProxyHealthChecks bool `json:"enable_container_proxy_healthcheck,omitempty"`
EnableDeclarativeHealthcheck bool `json:"enable_declarative_healthcheck,omitempty"`
DeclarativeHealthCheckDefaultTimeout durationjson.Duration `json:"declarative_healthcheck_default_timeout,omitempty"`
EnableHealtcheckMetrics bool `json:"enable_healthcheck_metrics,omitempty"`
EnableUnproxiedPortMappings bool `json:"enable_unproxied_port_mappings"`
EnvoyConfigRefreshDelay durationjson.Duration `json:"envoy_config_refresh_delay"`
Expand Down Expand Up @@ -268,6 +269,7 @@ func Initialize(
time.Duration(config.EnvoyDrainTimeout),
config.EnableContainerProxyHealthChecks,
time.Duration(config.ProxyHealthCheckInterval),
time.Duration(config.DeclarativeHealthCheckDefaultTimeout),
)

hub := event.NewHub()
Expand Down Expand Up @@ -574,14 +576,16 @@ func initializeTransformer(
drainWait time.Duration,
enableProxyHealthChecks bool,
proxyHealthCheckInterval time.Duration,
declarativeHealthCheckDefaultTimeout time.Duration,

) transformer.Transformer {
var options []transformer.Option
compressor := compressor.NewTgz()

options = append(options, transformer.WithSidecarRootfs(declarativeHealthcheckRootFS))

if useDeclarativeHealthCheck {
options = append(options, transformer.WithDeclarativeHealthchecks())
options = append(options, transformer.WithDeclarativeHealthChecks(declarativeHealthCheckDefaultTimeout))
}

if emitHealthCheckMetrics {
Expand Down Expand Up @@ -767,6 +771,11 @@ func (config *ExecutorConfig) Validate(logger lager.Logger) bool {
valid = false
}

if config.EnableDeclarativeHealthcheck && time.Duration(config.DeclarativeHealthCheckDefaultTimeout) <= 0 {
logger.Error("declarative_healthcheck_default_timeout", nil)
valid = false
}

return valid
}

Expand Down