Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Node GC Threshold #362

Merged
merged 2 commits into from
Oct 29, 2015
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
9 changes: 9 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sync"
"time"

"github.com/hashicorp/nomad/client"
"github.com/hashicorp/nomad/nomad"
Expand Down Expand Up @@ -137,6 +138,14 @@ func (a *Agent) serverConfig() (*nomad.Config, error) {
conf.SerfConfig.MemberlistConfig.BindPort = port
}

if gcThreshold := a.config.Server.NodeGCThreshold; gcThreshold != "" {
dur, err := time.ParseDuration(gcThreshold)
if err != nil {
return nil, err
}
conf.NodeGCThreshold = dur
}

return conf, nil
}

Expand Down
11 changes: 11 additions & 0 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ func TestAgent_ServerConfig(t *testing.T) {
t.Fatalf("expect 127.0.0.2, got: %s", addr)
}

conf.Server.NodeGCThreshold = "42g"
out, err = a.serverConfig()
if err == nil || !strings.Contains(err.Error(), "unknown unit") {
t.Fatalf("expected unknown unit error, got: %#v", err)
}
conf.Server.NodeGCThreshold = "10s"
out, err = a.serverConfig()
if threshold := out.NodeGCThreshold; threshold != time.Second*10 {
t.Fatalf("expect 10s, got: %s", threshold)
}

// Defaults to the global bind addr
conf.Addresses.RPC = ""
conf.Addresses.Serf = ""
Expand Down
6 changes: 6 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ type ServerConfig struct {
// enabled for this server to handle. This will restrict the evaluations
// that the workers dequeue for processing.
EnabledSchedulers []string `hcl:"enabled_schedulers"`

// NodeGCThreshold contros how "old" a node must be to be collected by GC.
NodeGCThreshold string `hcl:"node_gc_threshold"`
}

// Telemetry is the telemetry configuration for the server
Expand Down Expand Up @@ -372,6 +375,9 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
if b.NumSchedulers != 0 {
result.NumSchedulers = b.NumSchedulers
}
if b.NodeGCThreshold != "" {
result.NodeGCThreshold = b.NodeGCThreshold
}

// Add the schedulers
result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...)
Expand Down
4 changes: 4 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestConfig_Merge(t *testing.T) {
DataDir: "/tmp/data1",
ProtocolVersion: 1,
NumSchedulers: 1,
NodeGCThreshold: "1h",
},
Ports: &Ports{
HTTP: 4646,
Expand Down Expand Up @@ -106,6 +107,7 @@ func TestConfig_Merge(t *testing.T) {
ProtocolVersion: 2,
NumSchedulers: 2,
EnabledSchedulers: []string{structs.JobTypeBatch},
NodeGCThreshold: "12h",
},
Ports: &Ports{
HTTP: 20000,
Expand Down Expand Up @@ -369,6 +371,7 @@ func TestConfig_LoadConfigString(t *testing.T) {
ProtocolVersion: 3,
NumSchedulers: 2,
EnabledSchedulers: []string{"test"},
NodeGCThreshold: "12h",
},
Telemetry: &Telemetry{
StatsiteAddr: "127.0.0.1:1234",
Expand Down Expand Up @@ -441,6 +444,7 @@ server {
protocol_version = 3
num_schedulers = 2
enabled_schedulers = ["test"]
node_gc_threshold = "12h"
}
telemetry {
statsite_address = "127.0.0.1:1234"
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/agent/config.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ configured on client nodes.
sub-schedulers this server will handle. This can be used to restrict the
evaluations that worker threads will dequeue for processing. This
defaults to all available schedulers.
* `node_gc_threshold` This is a string with a unit suffix, such as "300ms",
"1.5h" or "25m". Valid time units are "ns", "us" (or "µs"), "ms", "s",
"m", "h". Controls how long a node must be in a terminal state before it is
garbage collected and purged from the system.

## Client-specific Options

Expand Down