Merge pull request #12726 from bboreham/fix-dropped-targets

Fix dropped targets
pull/12671/merge
Bryan Boreham 1 year ago committed by GitHub
commit c579144f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -529,7 +529,7 @@ func (sp *scrapePool) Sync(tgs []*targetgroup.Group) {
case nonEmpty: case nonEmpty:
all = append(all, t) all = append(all, t)
case !t.discoveredLabels.IsEmpty(): case !t.discoveredLabels.IsEmpty():
if sp.config.KeepDroppedTargets != 0 && uint(len(sp.droppedTargets)) < sp.config.KeepDroppedTargets { if sp.config.KeepDroppedTargets == 0 || uint(len(sp.droppedTargets)) < sp.config.KeepDroppedTargets {
sp.droppedTargets = append(sp.droppedTargets, t) sp.droppedTargets = append(sp.droppedTargets, t)
} }
sp.droppedTargetsCount++ sp.droppedTargetsCount++

@ -88,27 +88,30 @@ func TestDroppedTargetsList(t *testing.T) {
SourceLabels: model.LabelNames{"job"}, SourceLabels: model.LabelNames{"job"},
}, },
}, },
KeepDroppedTargets: 1,
} }
tgs = []*targetgroup.Group{ tgs = []*targetgroup.Group{
{ {
Targets: []model.LabelSet{ Targets: []model.LabelSet{
{model.AddressLabel: "127.0.0.1:9090"}, {model.AddressLabel: "127.0.0.1:9090"},
{model.AddressLabel: "127.0.0.1:9091"},
}, },
}, },
} }
sp, _ = newScrapePool(cfg, app, 0, nil, &Options{}) sp, _ = newScrapePool(cfg, app, 0, nil, &Options{})
expectedLabelSetString = "{__address__=\"127.0.0.1:9090\", __scrape_interval__=\"0s\", __scrape_timeout__=\"0s\", job=\"dropMe\"}" expectedLabelSetString = "{__address__=\"127.0.0.1:9090\", __scrape_interval__=\"0s\", __scrape_timeout__=\"0s\", job=\"dropMe\"}"
expectedLength = 1 expectedLength = 2
) )
sp.Sync(tgs) sp.Sync(tgs)
sp.Sync(tgs) sp.Sync(tgs)
if len(sp.droppedTargets) != expectedLength { require.Equal(t, expectedLength, len(sp.droppedTargets))
t.Fatalf("Length of dropped targets exceeded expected length, expected %v, got %v", expectedLength, len(sp.droppedTargets)) require.Equal(t, expectedLength, sp.droppedTargetsCount)
} require.Equal(t, expectedLabelSetString, sp.droppedTargets[0].DiscoveredLabels().String())
if sp.droppedTargets[0].DiscoveredLabels().String() != expectedLabelSetString {
t.Fatalf("Got %v, expected %v", sp.droppedTargets[0].DiscoveredLabels().String(), expectedLabelSetString) // Check that count is still correct when we don't retain all dropped targets.
} sp.config.KeepDroppedTargets = 1
sp.Sync(tgs)
require.Equal(t, 1, len(sp.droppedTargets))
require.Equal(t, expectedLength, sp.droppedTargetsCount)
} }
// TestDiscoveredLabelsUpdate checks that DiscoveredLabels are updated // TestDiscoveredLabelsUpdate checks that DiscoveredLabels are updated

Loading…
Cancel
Save