mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #8766 from Nick-Triller/consul-sd-always-send-targetgroups
Send empty targetgroup if nothing discovered [consul_sd]
This commit is contained in:
commit
2a4b8e12bb
|
@ -262,6 +262,6 @@ Here are some non-obvious parts of adding service discoveries that need to be ve
|
||||||
|
|
||||||
### Examples of Service Discovery pull requests
|
### Examples of Service Discovery pull requests
|
||||||
|
|
||||||
The exemples given might become out of date but should give a good impression about the areas touched by a new service discovery.
|
The examples given might become out of date but should give a good impression about the areas touched by a new service discovery.
|
||||||
|
|
||||||
- [Eureka](https://github.com/prometheus/prometheus/pull/3369)
|
- [Eureka](https://github.com/prometheus/prometheus/pull/3369)
|
||||||
|
|
|
@ -426,6 +426,15 @@ func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send targetgroup with no targets if nothing was discovered.
|
||||||
|
if len(services) == 0 {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case ch <- []*targetgroup.Group{{}}:
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// consulService contains data belonging to the same service.
|
// consulService contains data belonging to the same service.
|
||||||
|
|
|
@ -298,6 +298,23 @@ func TestAllServices(t *testing.T) {
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// targetgroup with no targets is emitted if no services were discovered.
|
||||||
|
func TestNoTargets(t *testing.T) {
|
||||||
|
stub, config := newServer(t)
|
||||||
|
defer stub.Close()
|
||||||
|
config.ServiceTags = []string{"missing"}
|
||||||
|
|
||||||
|
d := newDiscovery(t, config)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
ch := make(chan []*targetgroup.Group)
|
||||||
|
go d.Run(ctx, ch)
|
||||||
|
|
||||||
|
targets := (<-ch)[0].Targets
|
||||||
|
require.Equal(t, 0, len(targets))
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
// Watch only the test service.
|
// Watch only the test service.
|
||||||
func TestOneService(t *testing.T) {
|
func TestOneService(t *testing.T) {
|
||||||
stub, config := newServer(t)
|
stub, config := newServer(t)
|
||||||
|
|
Loading…
Reference in a new issue