@@ -178,15 +178,29 @@ func (allocator *perNodeAllocator) handleTargets(diff diff.Changes[*target.Item]
178
178
}
179
179
180
180
// Check for additions
181
+ unassignedTargetsForJobs := make (map [string ]struct {})
181
182
for k , item := range diff .Additions () {
182
183
// Do nothing if the item is already there
183
184
if _ , ok := allocator .targetItems [k ]; ok {
184
185
continue
185
186
} else {
186
187
// Add item to item pool and assign a collector
187
- allocator .addTargetToTargetItems (item )
188
+ collectorAssigned := allocator .addTargetToTargetItems (item )
189
+ if ! collectorAssigned {
190
+ unassignedTargetsForJobs [item .JobName ] = struct {}{}
191
+ }
192
+ }
193
+ }
194
+ // Check for unassigned targets
195
+ if len (unassignedTargetsForJobs ) > 0 {
196
+ jobs := make ([]string , 0 , len (unassignedTargetsForJobs ))
197
+ for j := range unassignedTargetsForJobs {
198
+ jobs = append (jobs , j )
188
199
}
200
+
201
+ allocator .log .Info ("Could not assign targets for the following jobs due to missing node labels" , "jobs" , jobs )
189
202
}
203
+
190
204
}
191
205
192
206
// addTargetToTargetItems assigns a target to the collector and adds it to the allocator's targetItems
@@ -195,18 +209,21 @@ func (allocator *perNodeAllocator) handleTargets(diff diff.Changes[*target.Item]
195
209
// INVARIANT: allocator.collectors must have at least 1 collector set.
196
210
// NOTE: by not creating a new target item, there is the potential for a race condition where we modify this target
197
211
// item while it's being encoded by the server JSON handler.
198
- // Also, any targets that cannot be assigned to a collector due to no matching node name will be dropped.
199
- func (allocator * perNodeAllocator ) addTargetToTargetItems (tg * target.Item ) {
212
+ // Also, any targets that cannot be assigned to a collector, due to no matching node name, will remain unassigned. These
213
+ // targets are still "silently" added to the targetItems map, to prevent them from being reported as unassigned on each new
214
+ // target items setting.
215
+ func (allocator * perNodeAllocator ) addTargetToTargetItems (tg * target.Item ) bool {
216
+ allocator .targetItems [tg .Hash ()] = tg
200
217
chosenCollector := allocator .findCollector (tg .Labels )
201
218
if chosenCollector == nil {
202
219
allocator .log .V (2 ).Info ("Couldn't find a collector for the target item" , "item" , tg , "collectors" , allocator .collectors )
203
- return
220
+ return false
204
221
}
205
222
tg .CollectorName = chosenCollector .Name
206
- allocator .targetItems [tg .Hash ()] = tg
207
223
allocator .addCollectorTargetItemMapping (tg )
208
224
chosenCollector .NumTargets ++
209
- TargetsPerCollector .WithLabelValues (chosenCollector .Name , leastWeightedStrategyName ).Set (float64 (chosenCollector .NumTargets ))
225
+ TargetsPerCollector .WithLabelValues (chosenCollector .Name , perNodeStrategyName ).Set (float64 (chosenCollector .NumTargets ))
226
+ return true
210
227
}
211
228
212
229
// findCollector finds the collector that matches the node of the target, on the basis of the
0 commit comments