mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
discovery: simplify code. (#7725)
Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
parent
9848e77678
commit
01d096567b
|
@ -678,16 +678,14 @@ func TestTargetUpdatesOrder(t *testing.T) {
|
||||||
for _, up := range tc.updates {
|
for _, up := range tc.updates {
|
||||||
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
|
go newMockDiscoveryProvider(up...).Run(ctx, provUpdates)
|
||||||
if len(up) > 0 {
|
if len(up) > 0 {
|
||||||
totalUpdatesCount = totalUpdatesCount + len(up)
|
totalUpdatesCount += len(up)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loop:
|
|
||||||
for x := 0; x < totalUpdatesCount; x++ {
|
for x := 0; x < totalUpdatesCount; x++ {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
t.Errorf("%d: no update arrived within the timeout limit", x)
|
t.Fatalf("%d: no update arrived within the timeout limit", x)
|
||||||
break Loop
|
|
||||||
case tgs := <-provUpdates:
|
case tgs := <-provUpdates:
|
||||||
discoveryManager.updateGroup(poolKey{setName: strconv.Itoa(i), provider: tc.title}, tgs)
|
discoveryManager.updateGroup(poolKey{setName: strconv.Itoa(i), provider: tc.title}, tgs)
|
||||||
for _, got := range discoveryManager.allGroups() {
|
for _, got := range discoveryManager.allGroups() {
|
||||||
|
@ -1195,16 +1193,10 @@ func newMockDiscoveryProvider(updates ...update) mockdiscoveryProvider {
|
||||||
func (tp mockdiscoveryProvider) Run(ctx context.Context, upCh chan<- []*targetgroup.Group) {
|
func (tp mockdiscoveryProvider) Run(ctx context.Context, upCh chan<- []*targetgroup.Group) {
|
||||||
for _, u := range tp.updates {
|
for _, u := range tp.updates {
|
||||||
if u.interval > 0 {
|
if u.interval > 0 {
|
||||||
t := time.NewTicker(u.interval)
|
select {
|
||||||
defer t.Stop()
|
case <-ctx.Done():
|
||||||
Loop:
|
return
|
||||||
for {
|
case <-time.After(u.interval):
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case <-t.C:
|
|
||||||
break Loop
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tgs := make([]*targetgroup.Group, len(u.targetGroups))
|
tgs := make([]*targetgroup.Group, len(u.targetGroups))
|
||||||
|
|
Loading…
Reference in a new issue