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

Add a default link speed #205

Merged
merged 2 commits into from
Oct 3, 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
4 changes: 4 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Config struct {
// Network interface to be used in network fingerprinting
NetworkInterface string

// Network speed is the default speed of network interfaces if they can not
// be determined dynamically.
NetworkSpeed int

// Servers is a list of known server addresses. These are as "host:port"
Servers []string

Expand Down
1 change: 0 additions & 1 deletion client/fingerprint/env_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestEnvAWSFingerprint_aws(t *testing.T) {
"platform.aws.public-ipv4",
"platform.aws.placement.availability-zone",
"network.ip-address",
"network.internal-ip",
}

for _, k := range keys {
Expand Down
6 changes: 5 additions & 1 deletion client/fingerprint/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func TestNetworkFingerprint_basic(t *testing.T) {
node := &structs.Node{
Attributes: make(map[string]string),
}
cfg := &config.Config{NetworkSpeed: 100}

ok, err := f.Fingerprint(&config.Config{}, node)
ok, err := f.Fingerprint(cfg, node)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -45,4 +46,7 @@ func TestNetworkFingerprint_basic(t *testing.T) {
if net.Device == "" {
t.Fatal("Expected Network Resource to have a Device Name")
}
if net.MBits == 0 {
t.Fatal("Expected Network Resource to have a non-zero bandwith")
}
}
5 changes: 5 additions & 0 deletions client/fingerprint/network_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)
node.Attributes["network.ip-address"] = ip
newNetwork.IP = ip
newNetwork.CIDR = newNetwork.IP + "/32"
} else {
return false, fmt.Errorf("Unable to determine IP on network interface %v", defaultDevice)
}

if throughput := f.linkSpeed(defaultDevice); throughput > 0 {
newNetwork.MBits = throughput
} else {
f.logger.Printf("[DEBUG] fingerprint.network: Unable to read link speed; setting to default %v", cfg.NetworkSpeed)
newNetwork.MBits = cfg.NetworkSpeed
}

if node.Resources == nil {
Expand Down
3 changes: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func (a *Agent) setupClient() error {
conf.NetworkInterface = a.config.Client.NetworkInterface
}
conf.Options = a.config.Client.Options
if a.config.Client.NetworkSpeed != 0 {
conf.NetworkSpeed = a.config.Client.NetworkSpeed
}

// Setup the node
conf.Node = new(structs.Node)
Expand Down
9 changes: 9 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (c *Command) readConfig() *Config {
flags.StringVar(&cmdConfig.Client.NodeClass, "node-class", "", "")
flags.StringVar(&servers, "servers", "", "")
flags.Var((*sliceflag.StringFlag)(&meta), "meta", "")
flags.StringVar(&cmdConfig.Client.NetworkInterface, "network-interface", "", "")
flags.IntVar(&cmdConfig.Client.NetworkSpeed, "network-speed", 0, "")

// General options
flags.Var((*sliceflag.StringFlag)(&configPath), "config", "config")
Expand Down Expand Up @@ -663,6 +665,13 @@ Client Options:
parses a single KEY=VALUE pair. Repeat the meta flag for each key/value pair
to be added.

-network-interface
Forces the network fingerprinter to use the specified network interface.

-network-speed
The default speed for network interfaces in MBits if the link speed can not
be determined dynamically.

Atlas Options:

-atlas=<infrastructure>
Expand Down
9 changes: 8 additions & 1 deletion command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ type ClientConfig struct {

// Interface to use for network fingerprinting
NetworkInterface string `hcl:"network_interface"`

// The network link speed to use if it can not be determined dynamically.
NetworkSpeed int `hcl:"network_speed"`
}

// ServerConfig is configuration specific to the server mode
Expand Down Expand Up @@ -236,7 +239,8 @@ func DefaultConfig() *Config {
AdvertiseAddrs: &AdvertiseAddrs{},
Atlas: &AtlasConfig{},
Client: &ClientConfig{
Enabled: false,
Enabled: false,
NetworkSpeed: 100,
},
Server: &ServerConfig{
Enabled: false,
Expand Down Expand Up @@ -396,6 +400,9 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
if b.NetworkInterface != "" {
result.NetworkInterface = b.NetworkInterface
}
if b.NetworkSpeed != 0 {
result.NetworkSpeed = b.NetworkSpeed
}

// Add the servers
result.Servers = append(result.Servers, b.Servers...)
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 @@ -39,6 +39,7 @@ func TestConfig_Merge(t *testing.T) {
Options: map[string]string{
"foo": "bar",
},
NetworkSpeed: 100,
},
Server: &ServerConfig{
Enabled: false,
Expand Down Expand Up @@ -96,6 +97,7 @@ func TestConfig_Merge(t *testing.T) {
"foo": "bar",
"baz": "zip",
},
NetworkSpeed: 100,
},
Server: &ServerConfig{
Enabled: true,
Expand Down Expand Up @@ -358,6 +360,7 @@ func TestConfig_LoadConfigString(t *testing.T) {
"foo": "bar",
"baz": "zip",
},
NetworkSpeed: 100,
},
Server: &ServerConfig{
Enabled: true,
Expand Down Expand Up @@ -429,6 +432,7 @@ client {
foo = "bar"
baz = "zip"
}
network_speed = 100
}
server {
enabled = true
Expand Down
11 changes: 9 additions & 2 deletions website/source/docs/agent/config.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,13 @@ configured on server nodes.
option is not required and has no default.
* <a id="meta">`meta`</a>: This is a key/value mapping of metadata pairs. This
is a free-form map and can contain any string values.
* `network_interface`: This is a string to force network fingerprinting to use
a specific network interface
* `options`: This is a key/value mapping of internal configuration for clients,
such as for driver configuration.
* <a id="network_interface">`network_interface`</a>: This is a string to force
network fingerprinting to use a specific network interface
* <a id="network_speed">`network_speed`</a>: This is an int that sets the
default link speed of network interfaces, in megabytes, if their speed can
not be determined dynamically.

## Atlas Options

Expand Down Expand Up @@ -257,6 +260,10 @@ via CLI arguments. The `agent` command accepts the following arguments:
Nomad. No other configuration is required to start the agent in this mode.
* `-log-level=<level>`: Equivalent to the [log_level](#log_level) config option.
* `-meta=<key=value>`: Equivalent to the Client [meta](#meta) config option.
* `-network-interface<interface>`: Equivalent to the Client
[network_interface](#network_interface) config option.
* `-network-speed<MBits>`: Equivalent to the Client
[network_speed](#network_speed) config option.
* `-node=<name>`: Equivalent to the [name](#name) config option.
* `-node-class=<class>`: Equivalent to the Client [node_class](#node_class)
config option.
Expand Down