Merge branch 'master' into f-resource-isolation-fingerprinter

This commit is contained in:
Sean Chittenden
2016-07-11 12:23:09 -07:00
10 changed files with 74 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ import (
"path/filepath"
"reflect"
"runtime/debug"
"strconv"
"strings"
"testing"
"time"
@@ -709,7 +710,7 @@ func TestDockerPortsMapping(t *testing.T) {
expectedEnvironment := map[string]string{
"NOMAD_ADDR_main": "127.0.0.1:8080",
"NOMAD_ADDR_REDIS": "127.0.0.1:6379",
"NOMAD_HOST_PORT_main": "8080",
"NOMAD_HOST_PORT_main": strconv.Itoa(docker_reserved),
}
for key, val := range expectedEnvironment {

View File

@@ -129,15 +129,19 @@ func TestDriver_GetTaskEnv(t *testing.T) {
"NOMAD_ADDR_one": "1.2.3.4:80",
"NOMAD_IP_one": "1.2.3.4",
"NOMAD_PORT_one": "80",
"NOMAD_HOST_PORT_one": "80",
"NOMAD_ADDR_two": "1.2.3.4:443",
"NOMAD_IP_two": "1.2.3.4",
"NOMAD_PORT_two": "443",
"NOMAD_HOST_PORT_two": "443",
"NOMAD_ADDR_admin": "1.2.3.4:8081",
"NOMAD_IP_admin": "1.2.3.4",
"NOMAD_PORT_admin": "8081",
"NOMAD_HOST_PORT_admin": "8081",
"NOMAD_ADDR_web": "1.2.3.4:8086",
"NOMAD_IP_web": "1.2.3.4",
"NOMAD_PORT_web": "8086",
"NOMAD_HOST_PORT_web": "8086",
"NOMAD_META_CHOCOLATE": "cake",
"NOMAD_META_STRAWBERRY": "icecream",
"NOMAD_META_ELB_CHECK_INTERVAL": "30s",

View File

@@ -133,16 +133,16 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
// Build the ports
for _, network := range t.Networks {
for label, value := range network.MapLabelToValues(t.PortMap) {
for label, value := range network.MapLabelToValues(nil) {
t.TaskEnv[fmt.Sprintf("%s%s", IpPrefix, label)] = network.IP
t.TaskEnv[fmt.Sprintf("%s%s", HostPortPrefix, label)] = strconv.Itoa(value)
if forwardedPort, ok := t.PortMap[label]; ok {
value = forwardedPort
}
t.TaskEnv[fmt.Sprintf("%s%s", PortPrefix, label)] = fmt.Sprintf("%d", value)
IPPort := fmt.Sprintf("%s:%d", network.IP, value)
t.TaskEnv[fmt.Sprintf("%s%s", AddrPrefix, label)] = IPPort
t.TaskEnv[fmt.Sprintf("%s%s", IpPrefix, label)] = network.IP
t.TaskEnv[fmt.Sprintf("%s%s", PortPrefix, label)] = fmt.Sprintf("%d", value)
// Pass an explicit port mapping to the environment
if port, ok := t.PortMap[label]; ok {
t.TaskEnv[fmt.Sprintf("%s%s", HostPortPrefix, label)] = strconv.Itoa(port)
}
}
}

View File

@@ -151,7 +151,8 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_ADDR_https=127.0.0.1:443",
"NOMAD_PORT_https=443",
"NOMAD_IP_https=127.0.0.1",
"NOMAD_HOST_PORT_https=443",
"NOMAD_HOST_PORT_http=80",
"NOMAD_HOST_PORT_https=8080",
"NOMAD_META_FOO=baz",
"NOMAD_META_BAZ=bam",
}
@@ -177,7 +178,8 @@ func TestEnvironment_ClearEnvvars(t *testing.T) {
"NOMAD_ADDR_https=127.0.0.1:443",
"NOMAD_PORT_https=443",
"NOMAD_IP_https=127.0.0.1",
"NOMAD_HOST_PORT_https=443",
"NOMAD_HOST_PORT_http=80",
"NOMAD_HOST_PORT_https=8080",
"bar=bang",
"foo=baz",
}
@@ -198,7 +200,8 @@ func TestEnvironment_ClearEnvvars(t *testing.T) {
"NOMAD_ADDR_https=127.0.0.1:443",
"NOMAD_PORT_https=443",
"NOMAD_IP_https=127.0.0.1",
"NOMAD_HOST_PORT_https=443",
"NOMAD_HOST_PORT_https=8080",
"NOMAD_HOST_PORT_http=80",
}
sort.Strings(act)
sort.Strings(exp)

View File

@@ -1,4 +1,4 @@
//+build darwin dragonfly freebsd netbsd openbsd solaris
//+build windows darwin dragonfly freebsd netbsd openbsd solaris
package driver

View File

@@ -69,7 +69,21 @@ func (d *DockerLogParser) Parse(line []byte) *SyslogMessage {
func (d *DockerLogParser) logContentIndex(line []byte) int {
cursor := 0
numSpace := 0
numColons := 0
// first look for at least 2 colons. This matches into the date that has no more spaces in it
// DefaultFormatter log line look: '<30>2016-07-06T15:13:11Z00:00 hostname docker/9648c64f5037[16200]'
// UnixFormatter log line look: '<30>Jul 6 15:13:11 docker/9648c64f5037[16200]'
for i := 0; i < len(line); i++ {
if line[i] == ':' {
numColons += 1
if numColons == 2 {
cursor = i
break
}
}
}
// then look for the next space
for i := cursor; i < len(line); i++ {
if line[i] == ' ' {
numSpace += 1
if numSpace == 1 {
@@ -78,12 +92,14 @@ func (d *DockerLogParser) logContentIndex(line []byte) int {
}
}
}
// then the colon is what seperates it, followed by a space
for i := cursor; i < len(line); i++ {
if line[i] == ':' {
cursor = i
if line[i] == ':' && i+1 < len(line) && line[i+1] == ' ' {
cursor = i + 1
break
}
}
// return the cursor to the next character
return cursor + 1
}

View File

@@ -3,6 +3,7 @@
package logging
import (
"bytes"
"log"
"log/syslog"
"os"
@@ -21,7 +22,25 @@ func TestLogParser_Priority(t *testing.T) {
}
idx := d.logContentIndex(line)
expected := 68
expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
if idx != expected {
t.Fatalf("expected idx: %v, got: %v", expected, idx)
}
}
func TestLogParser_Priority_UnixFormatter(t *testing.T) {
line := []byte("<30>Feb 6, 10:16:43 docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf")
d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
p, _, err := d.parsePriority(line)
if err != nil {
t.Fatalf("got an err: %v", err)
}
if p.Severity != syslog.LOG_INFO {
t.Fatalf("expected serverity: %v, got: %v", syslog.LOG_INFO, p.Severity)
}
idx := d.logContentIndex(line)
expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
if idx != expected {
t.Fatalf("expected idx: %v, got: %v", expected, idx)
}

View File

@@ -1,4 +1,4 @@
// +build darwin dragonfly freebsd netbsd openbsd solaris
// +build windows darwin dragonfly freebsd netbsd openbsd solaris
package fingerprint

View File

@@ -1528,16 +1528,16 @@ func (sc *ServiceCheck) Copy() *ServiceCheck {
func (sc *ServiceCheck) validate() error {
switch strings.ToLower(sc.Type) {
case ServiceCheckTCP:
if sc.Timeout > 0 && sc.Timeout <= minCheckTimeout {
return fmt.Errorf("timeout %v is lower than required minimum timeout %v", sc.Timeout, minCheckInterval)
if sc.Timeout < minCheckTimeout {
return fmt.Errorf("timeout (%v) is lower than required minimum timeout %v", sc.Timeout, minCheckInterval)
}
case ServiceCheckHTTP:
if sc.Path == "" {
return fmt.Errorf("http type must have a valid http path")
}
if sc.Timeout > 0 && sc.Timeout <= minCheckTimeout {
return fmt.Errorf("timeout %v is lower than required minimum timeout %v", sc.Timeout, minCheckInterval)
if sc.Timeout < minCheckTimeout {
return fmt.Errorf("timeout (%v) is lower than required minimum timeout %v", sc.Timeout, minCheckInterval)
}
case ServiceCheckScript:
if sc.Command == "" {
@@ -1550,7 +1550,7 @@ func (sc *ServiceCheck) validate() error {
return fmt.Errorf(`invalid type (%+q), must be one of "http", "tcp", or "script" type`, sc.Type)
}
if sc.Interval > 0 && sc.Interval <= minCheckInterval {
if sc.Interval < minCheckInterval {
return fmt.Errorf("interval (%v) can not be lower than %v", sc.Interval, minCheckInterval)
}

View File

@@ -288,12 +288,14 @@ func TestTask_Validate_Services(t *testing.T) {
PortLabel: "bar",
Checks: []*ServiceCheck{
{
Name: "check-name",
Type: ServiceCheckTCP,
Name: "check-name",
Type: ServiceCheckTCP,
Interval: 0 * time.Second,
},
{
Name: "check-name",
Type: ServiceCheckTCP,
Name: "check-name",
Type: ServiceCheckTCP,
Timeout: 2 * time.Second,
},
},
}
@@ -328,6 +330,10 @@ func TestTask_Validate_Services(t *testing.T) {
if !strings.Contains(err.Error(), "check \"check-name\" is duplicate") {
t.Fatalf("err: %v", err)
}
if !strings.Contains(err.Error(), "interval (0) can not be lower") {
t.Fatal("err: %v", err)
}
}
func TestTask_Validate_LogConfig(t *testing.T) {