mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-30 07:59:40 -08:00
Merge pull request #1738 from prometheus/release-0.19
Forward-merge 0.19 fixes into master
This commit is contained in:
commit
4aeab798e8
|
@ -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
|
||||||
|
|
|
@ -24,108 +24,114 @@ 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() {
|
)
|
||||||
select {
|
if err := testUpdateServices(client, ch); err != errTesting {
|
||||||
case tg := <-ch:
|
|
||||||
t.Fatalf("Got group: %s", tg)
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
err := md.updateServices(context.Background(), ch)
|
|
||||||
if err != errTesting {
|
|
||||||
t.Fatalf("Expected error: %s", err)
|
t.Fatalf("Expected error: %s", err)
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case tg := <-ch:
|
||||||
|
t.Fatalf("Got group: %s", tg)
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
)
|
||||||
select {
|
if err := testUpdateServices(client, ch); err != nil {
|
||||||
case tg := <-ch:
|
|
||||||
if len(tg) > 0 {
|
|
||||||
t.Fatalf("Got group: %v", tg)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
err := md.updateServices(context.Background(), ch)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Got error: %s", err)
|
t.Fatalf("Got error: %s", err)
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case tg := <-ch:
|
||||||
|
if len(tg) > 0 {
|
||||||
|
t.Fatalf("Got group: %v", tg)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func marathonTestAppList(labels map[string]string, runningTasks int) *AppList {
|
func marathonTestAppList(labels map[string]string, runningTasks int) *AppList {
|
||||||
task := Task{
|
var (
|
||||||
ID: "test-task-1",
|
task = Task{
|
||||||
Host: "mesos-slave1",
|
ID: "test-task-1",
|
||||||
Ports: []uint32{31000},
|
Host: "mesos-slave1",
|
||||||
}
|
Ports: []uint32{31000},
|
||||||
docker := DockerContainer{Image: "repo/image:tag"}
|
}
|
||||||
container := Container{Docker: docker}
|
docker = DockerContainer{Image: "repo/image:tag"}
|
||||||
app := App{
|
container = Container{Docker: docker}
|
||||||
ID: "test-service",
|
app = App{
|
||||||
Tasks: []Task{task},
|
ID: "test-service",
|
||||||
RunningTasks: runningTasks,
|
Tasks: []Task{task},
|
||||||
Labels: labels,
|
RunningTasks: runningTasks,
|
||||||
Container: container,
|
Labels: labels,
|
||||||
}
|
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 (
|
||||||
return marathonTestAppList(marathonValidLabel, 1), nil
|
ch = make(chan []*config.TargetGroup, 1)
|
||||||
})
|
client = func(url string) (*AppList, error) {
|
||||||
go func() {
|
return marathonTestAppList(marathonValidLabel, 1), nil
|
||||||
select {
|
|
||||||
case tgs := <-ch:
|
|
||||||
tg := tgs[0]
|
|
||||||
|
|
||||||
if tg.Source != "test-service" {
|
|
||||||
t.Fatalf("Wrong target group name: %s", tg.Source)
|
|
||||||
}
|
|
||||||
if len(tg.Targets) != 1 {
|
|
||||||
t.Fatalf("Wrong number of targets: %v", tg.Targets)
|
|
||||||
}
|
|
||||||
tgt := tg.Targets[0]
|
|
||||||
if tgt[model.AddressLabel] != "mesos-slave1:31000" {
|
|
||||||
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel])
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
t.Fatal("Did not get a target group.")
|
|
||||||
}
|
}
|
||||||
}()
|
)
|
||||||
err := md.updateServices(context.Background(), ch)
|
if err := testUpdateServices(client, ch); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Got error: %s", err)
|
t.Fatalf("Got error: %s", err)
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case tgs := <-ch:
|
||||||
|
tg := tgs[0]
|
||||||
|
|
||||||
|
if tg.Source != "test-service" {
|
||||||
|
t.Fatalf("Wrong target group name: %s", tg.Source)
|
||||||
|
}
|
||||||
|
if len(tg.Targets) != 1 {
|
||||||
|
t.Fatalf("Wrong number of targets: %v", tg.Targets)
|
||||||
|
}
|
||||||
|
tgt := tg.Targets[0]
|
||||||
|
if tgt[model.AddressLabel] != "mesos-slave1:31000" {
|
||||||
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel])
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
t.Fatal("Did not get a target group.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarathonSDRemoveApp(t *testing.T) {
|
func TestMarathonSDRemoveApp(t *testing.T) {
|
||||||
ch, md := newTestDiscovery(func(url string) (*AppList, error) {
|
var (
|
||||||
return marathonTestAppList(marathonValidLabel, 1), nil
|
ch = make(chan []*config.TargetGroup)
|
||||||
})
|
client = func(url string) (*AppList, error) {
|
||||||
|
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,73 +157,80 @@ func TestMarathonSDRemoveApp(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarathonSDRunAndStop(t *testing.T) {
|
func TestMarathonSDRunAndStop(t *testing.T) {
|
||||||
ch, md := newTestDiscovery(func(url string) (*AppList, error) {
|
var (
|
||||||
return marathonTestAppList(marathonValidLabel, 1), nil
|
ch = make(chan []*config.TargetGroup)
|
||||||
})
|
client = func(url string) (*AppList, error) {
|
||||||
md.RefreshInterval = time.Millisecond * 10
|
return marathonTestAppList(marathonValidLabel, 1), nil
|
||||||
|
}
|
||||||
|
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() {
|
||||||
select {
|
for {
|
||||||
case <-ch:
|
select {
|
||||||
cancel()
|
case _, ok := <-ch:
|
||||||
case <-time.After(md.RefreshInterval * 3):
|
if !ok {
|
||||||
cancel()
|
return
|
||||||
t.Fatalf("Update took too long.")
|
}
|
||||||
|
cancel()
|
||||||
|
case <-time.After(md.RefreshInterval * 3):
|
||||||
|
cancel()
|
||||||
|
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 (
|
||||||
ID: "test-task-2",
|
task = Task{
|
||||||
Host: "mesos-slave-2",
|
ID: "test-task-2",
|
||||||
Ports: []uint32{},
|
Host: "mesos-slave-2",
|
||||||
}
|
Ports: []uint32{},
|
||||||
docker := DockerContainer{Image: "repo/image:tag"}
|
}
|
||||||
container := Container{Docker: docker}
|
docker = DockerContainer{Image: "repo/image:tag"}
|
||||||
app := App{
|
container = Container{Docker: docker}
|
||||||
ID: "test-service-zero-ports",
|
app = App{
|
||||||
Tasks: []Task{task},
|
ID: "test-service-zero-ports",
|
||||||
RunningTasks: runningTasks,
|
Tasks: []Task{task},
|
||||||
Labels: labels,
|
RunningTasks: runningTasks,
|
||||||
Container: container,
|
Labels: labels,
|
||||||
}
|
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 (
|
||||||
return marathonTestZeroTaskPortAppList(marathonValidLabel, 1), nil
|
ch = make(chan []*config.TargetGroup, 1)
|
||||||
})
|
client = func(url string) (*AppList, error) {
|
||||||
|
return marathonTestZeroTaskPortAppList(marathonValidLabel, 1), nil
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case tgs := <-ch:
|
|
||||||
tg := tgs[0]
|
|
||||||
|
|
||||||
if tg.Source != "test-service-zero-ports" {
|
|
||||||
t.Fatalf("Wrong target group name: %s", tg.Source)
|
|
||||||
}
|
|
||||||
if len(tg.Targets) != 0 {
|
|
||||||
t.Fatalf("Wrong number of targets: %v", tg.Targets)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
t.Fatal("Did not get a target group.")
|
|
||||||
}
|
}
|
||||||
}()
|
)
|
||||||
err := md.updateServices(context.Background(), ch)
|
if err := testUpdateServices(client, ch); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Got error: %s", err)
|
t.Fatalf("Got error: %s", err)
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case tgs := <-ch:
|
||||||
|
tg := tgs[0]
|
||||||
|
|
||||||
|
if tg.Source != "test-service-zero-ports" {
|
||||||
|
t.Fatalf("Wrong target group name: %s", tg.Source)
|
||||||
|
}
|
||||||
|
if len(tg.Targets) != 0 {
|
||||||
|
t.Fatalf("Wrong number of targets: %v", tg.Targets)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
t.Fatal("Did not get a target group.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue