From e2d2911d06574d95773ce560fb197be376d1ed83 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 27 Feb 2017 11:58:10 -0800 Subject: [PATCH] Allow specification of eval/job gc threshold --- command/agent/agent.go | 14 ++++++++++++++ command/agent/config-test-fixtures/basic.hcl | 2 ++ command/agent/config.go | 18 ++++++++++++++++++ command/agent/config_parse.go | 2 ++ command/agent/config_parse_test.go | 2 ++ .../docs/agent/configuration/server.html.md | 8 ++++++++ 6 files changed, 46 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index ca4df6672e9b..bfecfec7dd82 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -165,6 +165,20 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi } conf.NodeGCThreshold = dur } + if gcThreshold := agentConfig.Server.JobGCThreshold; gcThreshold != "" { + dur, err := time.ParseDuration(gcThreshold) + if err != nil { + return nil, err + } + conf.JobGCThreshold = dur + } + if gcThreshold := agentConfig.Server.EvalGCThreshold; gcThreshold != "" { + dur, err := time.ParseDuration(gcThreshold) + if err != nil { + return nil, err + } + conf.EvalGCThreshold = dur + } if heartbeatGrace := agentConfig.Server.HeartbeatGrace; heartbeatGrace != "" { dur, err := time.ParseDuration(heartbeatGrace) diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index 1c5e2001dde8..3ad81148b6db 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -65,6 +65,8 @@ server { num_schedulers = 2 enabled_schedulers = ["test"] node_gc_threshold = "12h" + job_gc_threshold = "12h" + eval_gc_threshold = "12h" heartbeat_grace = "30s" retry_join = [ "1.1.1.1", "2.2.2.2" ] start_join = [ "1.1.1.1", "2.2.2.2" ] diff --git a/command/agent/config.go b/command/agent/config.go index 9efac4b4ddd0..9412e4567b81 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -238,8 +238,20 @@ type ServerConfig struct { EnabledSchedulers []string `mapstructure:"enabled_schedulers"` // NodeGCThreshold controls how "old" a node must be to be collected by GC. + // Age is not the only requirement for a node to be GCed but the threshold + // can be used to filter by age. NodeGCThreshold string `mapstructure:"node_gc_threshold"` + // JobGCThreshold controls how "old" a job must be to be collected by GC. + // Age is not the only requirement for a Job to be GCed but the threshold + // can be used to filter by age. + JobGCThreshold string `mapstructure:"job_gc_threshold"` + + // EvalGCThreshold controls how "old" an eval must be to be collected by GC. + // Age is not the only requirement for a eval to be GCed but the threshold + // can be used to filter by age. + EvalGCThreshold string `mapstructure:"eval_gc_threshold"` + // HeartbeatGrace is the grace period beyond the TTL to account for network, // processing delays and clock skew before marking a node as "down". HeartbeatGrace string `mapstructure:"heartbeat_grace"` @@ -834,6 +846,12 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig { if b.NodeGCThreshold != "" { result.NodeGCThreshold = b.NodeGCThreshold } + if b.JobGCThreshold != "" { + result.JobGCThreshold = b.JobGCThreshold + } + if b.EvalGCThreshold != "" { + result.EvalGCThreshold = b.EvalGCThreshold + } if b.HeartbeatGrace != "" { result.HeartbeatGrace = b.HeartbeatGrace } diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index a9320e5397cb..35229d8059f3 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -498,6 +498,8 @@ func parseServer(result **ServerConfig, list *ast.ObjectList) error { "num_schedulers", "enabled_schedulers", "node_gc_threshold", + "eval_gc_threshold", + "job_gc_threshold", "heartbeat_grace", "start_join", "retry_join", diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 29cf3aef8536..ba9016d7afc3 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -82,6 +82,8 @@ func TestConfig_Parse(t *testing.T) { NumSchedulers: 2, EnabledSchedulers: []string{"test"}, NodeGCThreshold: "12h", + EvalGCThreshold: "12h", + JobGCThreshold: "12h", HeartbeatGrace: "30s", RetryJoin: []string{"1.1.1.1", "2.2.2.2"}, StartJoin: []string{"1.1.1.1", "2.2.2.2"}, diff --git a/website/source/docs/agent/configuration/server.html.md b/website/source/docs/agent/configuration/server.html.md index 901b518b1777..15c6d9f6efd2 100644 --- a/website/source/docs/agent/configuration/server.html.md +++ b/website/source/docs/agent/configuration/server.html.md @@ -68,6 +68,14 @@ server { terminal state before it is garbage collected and purged from the system. This is specified using a label suffix like "30s" or "1h". +- `job_gc_threshold` `(string: "4h")` - Specifies the minimum time a job must be + in the terminal state before it is eligible for garbage collection. This is + specified using a label suffix like "30s" or "1h". + +- `eval_gc_threshold` `(string: "1h")` - Specifies the minimum time an + evaluation must be in the terminal state before it is eligible for garbage + collection. This is specified using a label suffix like "30s" or "1h". + - `num_schedulers` `(int: [num-cores])` - Specifies the number of parallel scheduler threads to run. This can be as many as one per core, or `0` to disallow this server from making any scheduling decisions. This defaults to