Merge pull request #1738 from prometheus/release-0.19

Forward-merge 0.19 fixes into master
This commit is contained in:
Fabian Reinartz 2016-06-14 18:11:47 +02:00 committed by GitHub
commit 4aeab798e8
3 changed files with 143 additions and 125 deletions

View file

@ -1,3 +1,8 @@
## 0.19.3 / 2016-06-14
* [BUGFIX] Handle Marathon apps with zero ports
* [BUGFIX] Fix startup panic in retrieval layer
## 0.19.2 / 2016-05-29 ## 0.19.2 / 2016-05-29
* [BUGFIX] Correctly handle `GROUP_LEFT` and `GROUP_RIGHT` without labels in * [BUGFIX] Correctly handle `GROUP_LEFT` and `GROUP_RIGHT` without labels in

View file

@ -1 +1 @@
0.19.2 0.19.3

View file

@ -24,40 +24,43 @@ import (
"github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/config"
) )
var marathonValidLabel = map[string]string{"prometheus": "yes"} var (
marathonValidLabel = map[string]string{"prometheus": "yes"}
testServers = []string{"http://localhost:8080"}
)
func newTestDiscovery(client AppListClient) (chan []*config.TargetGroup, *Discovery) { func testUpdateServices(client AppListClient, ch chan []*config.TargetGroup) error {
ch := make(chan []*config.TargetGroup) md := Discovery{
md := &Discovery{ Servers: testServers,
Servers: []string{"http://localhost:8080"},
Client: client, Client: client,
} }
return ch, md return md.updateServices(context.Background(), ch)
} }
func TestMarathonSDHandleError(t *testing.T) { func TestMarathonSDHandleError(t *testing.T) {
var errTesting = errors.New("testing failure") var (
ch, md := newTestDiscovery(func(url string) (*AppList, error) { errTesting = errors.New("testing failure")
return nil, errTesting ch = make(chan []*config.TargetGroup, 1)
}) client = func(url string) (*AppList, error) { return nil, errTesting }
go func() { )
if err := testUpdateServices(client, ch); err != errTesting {
t.Fatalf("Expected error: %s", err)
}
select { select {
case tg := <-ch: case tg := <-ch:
t.Fatalf("Got group: %s", tg) t.Fatalf("Got group: %s", tg)
default: default:
} }
}()
err := md.updateServices(context.Background(), ch)
if err != errTesting {
t.Fatalf("Expected error: %s", err)
}
} }
func TestMarathonSDEmptyList(t *testing.T) { func TestMarathonSDEmptyList(t *testing.T) {
ch, md := newTestDiscovery(func(url string) (*AppList, error) { var (
return &AppList{}, nil ch = make(chan []*config.TargetGroup, 1)
}) client = func(url string) (*AppList, error) { return &AppList{}, nil }
go func() { )
if err := testUpdateServices(client, ch); err != nil {
t.Fatalf("Got error: %s", err)
}
select { select {
case tg := <-ch: case tg := <-ch:
if len(tg) > 0 { if len(tg) > 0 {
@ -65,38 +68,40 @@ func TestMarathonSDEmptyList(t *testing.T) {
} }
default: default:
} }
}()
err := md.updateServices(context.Background(), ch)
if err != nil {
t.Fatalf("Got error: %s", err)
}
} }
func marathonTestAppList(labels map[string]string, runningTasks int) *AppList { func marathonTestAppList(labels map[string]string, runningTasks int) *AppList {
task := Task{ var (
task = Task{
ID: "test-task-1", ID: "test-task-1",
Host: "mesos-slave1", Host: "mesos-slave1",
Ports: []uint32{31000}, Ports: []uint32{31000},
} }
docker := DockerContainer{Image: "repo/image:tag"} docker = DockerContainer{Image: "repo/image:tag"}
container := Container{Docker: docker} container = Container{Docker: docker}
app := App{ app = App{
ID: "test-service", ID: "test-service",
Tasks: []Task{task}, Tasks: []Task{task},
RunningTasks: runningTasks, RunningTasks: runningTasks,
Labels: labels, Labels: labels,
Container: container, Container: container,
} }
)
return &AppList{ return &AppList{
Apps: []App{app}, Apps: []App{app},
} }
} }
func TestMarathonSDSendGroup(t *testing.T) { func TestMarathonSDSendGroup(t *testing.T) {
ch, md := newTestDiscovery(func(url string) (*AppList, error) { var (
ch = make(chan []*config.TargetGroup, 1)
client = func(url string) (*AppList, error) {
return marathonTestAppList(marathonValidLabel, 1), nil return marathonTestAppList(marathonValidLabel, 1), nil
}) }
go func() { )
if err := testUpdateServices(client, ch); err != nil {
t.Fatalf("Got error: %s", err)
}
select { select {
case tgs := <-ch: case tgs := <-ch:
tg := tgs[0] tg := tgs[0]
@ -114,18 +119,19 @@ func TestMarathonSDSendGroup(t *testing.T) {
default: default:
t.Fatal("Did not get a target group.") t.Fatal("Did not get a target group.")
} }
}()
err := md.updateServices(context.Background(), ch)
if err != nil {
t.Fatalf("Got error: %s", err)
}
} }
func TestMarathonSDRemoveApp(t *testing.T) { func TestMarathonSDRemoveApp(t *testing.T) {
ch, md := newTestDiscovery(func(url string) (*AppList, error) { var (
ch = make(chan []*config.TargetGroup)
client = func(url string) (*AppList, error) {
return marathonTestAppList(marathonValidLabel, 1), nil return marathonTestAppList(marathonValidLabel, 1), nil
}) }
md = Discovery{
Servers: testServers,
Client: client,
}
)
go func() { go func() {
up1 := (<-ch)[0] up1 := (<-ch)[0]
up2 := (<-ch)[0] up2 := (<-ch)[0]
@ -151,57 +157,69 @@ func TestMarathonSDRemoveApp(t *testing.T) {
} }
func TestMarathonSDRunAndStop(t *testing.T) { func TestMarathonSDRunAndStop(t *testing.T) {
ch, md := newTestDiscovery(func(url string) (*AppList, error) { var (
ch = make(chan []*config.TargetGroup)
client = func(url string) (*AppList, error) {
return marathonTestAppList(marathonValidLabel, 1), nil return marathonTestAppList(marathonValidLabel, 1), nil
}) }
md.RefreshInterval = time.Millisecond * 10 md = Discovery{
Servers: testServers,
Client: client,
RefreshInterval: time.Millisecond * 10,
}
)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
go func() { go func() {
for {
select { select {
case <-ch: case _, ok := <-ch:
if !ok {
return
}
cancel() cancel()
case <-time.After(md.RefreshInterval * 3): case <-time.After(md.RefreshInterval * 3):
cancel() cancel()
t.Fatalf("Update took too long.") t.Fatalf("Update took too long.")
} }
}
}() }()
md.Run(ctx, ch) md.Run(ctx, ch)
select {
case <-ch:
default:
t.Fatalf("Channel not closed.")
}
} }
func marathonTestZeroTaskPortAppList(labels map[string]string, runningTasks int) *AppList { func marathonTestZeroTaskPortAppList(labels map[string]string, runningTasks int) *AppList {
task := Task{ var (
task = Task{
ID: "test-task-2", ID: "test-task-2",
Host: "mesos-slave-2", Host: "mesos-slave-2",
Ports: []uint32{}, Ports: []uint32{},
} }
docker := DockerContainer{Image: "repo/image:tag"} docker = DockerContainer{Image: "repo/image:tag"}
container := Container{Docker: docker} container = Container{Docker: docker}
app := App{ app = App{
ID: "test-service-zero-ports", ID: "test-service-zero-ports",
Tasks: []Task{task}, Tasks: []Task{task},
RunningTasks: runningTasks, RunningTasks: runningTasks,
Labels: labels, Labels: labels,
Container: container, Container: container,
} }
)
return &AppList{ return &AppList{
Apps: []App{app}, Apps: []App{app},
} }
} }
func TestMarathonZeroTaskPorts(t *testing.T) { func TestMarathonZeroTaskPorts(t *testing.T) {
ch, md := newTestDiscovery(func(url string) (*AppList, error) { var (
ch = make(chan []*config.TargetGroup, 1)
client = func(url string) (*AppList, error) {
return marathonTestZeroTaskPortAppList(marathonValidLabel, 1), nil return marathonTestZeroTaskPortAppList(marathonValidLabel, 1), nil
}) }
)
go func() { if err := testUpdateServices(client, ch); err != nil {
t.Fatalf("Got error: %s", err)
}
select { select {
case tgs := <-ch: case tgs := <-ch:
tg := tgs[0] tg := tgs[0]
@ -215,9 +233,4 @@ func TestMarathonZeroTaskPorts(t *testing.T) {
default: default:
t.Fatal("Did not get a target group.") t.Fatal("Did not get a target group.")
} }
}()
err := md.updateServices(context.Background(), ch)
if err != nil {
t.Fatalf("Got error: %s", err)
}
} }