From 888b9937a252648f55df3ba510e3b61bce7a6519 Mon Sep 17 00:00:00 2001 From: Piotr Gwizdala <17101802+thampiotr@users.noreply.github.com> Date: Fri, 10 May 2024 14:54:48 +0100 Subject: [PATCH] feedback --- internal/component/discovery/distributed_targets.go | 7 ++++--- internal/component/prometheus/scrape/scrape.go | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/component/discovery/distributed_targets.go b/internal/component/discovery/distributed_targets.go index dd1baac2d2..c0b2831b8d 100644 --- a/internal/component/discovery/distributed_targets.go +++ b/internal/component/discovery/distributed_targets.go @@ -57,9 +57,10 @@ func (dt *DistributedTargets) LocalTargets() []Target { return dt.localTargets } -// MovedToRemoteInstance returns targets that have been moved from this local node to another node, given the provided -// previous targets distribution. If a target has simply disappeared, it will not be returned. Previous targets -// distribution can be nil, in which case no targets will be returned. +// MovedToRemoteInstance returns the set of local targets from prev +// that are no longer local in dt, indicating an active target has moved. +// Only targets which exist in both prev and dt are returned. If prev +// contains an empty list of targets, no targets are returned. func (dt *DistributedTargets) MovedToRemoteInstance(prev *DistributedTargets) []Target { if prev == nil { return nil diff --git a/internal/component/prometheus/scrape/scrape.go b/internal/component/prometheus/scrape/scrape.go index 974146327e..4693d08959 100644 --- a/internal/component/prometheus/scrape/scrape.go +++ b/internal/component/prometheus/scrape/scrape.go @@ -126,15 +126,15 @@ type Component struct { opts component.Options cluster cluster.Cluster - reloadTargets chan struct{} - - mut sync.RWMutex - args Arguments - scraper *scrape.Manager - appendable *prometheus.Fanout + reloadTargets chan struct{} targetsGauge client_prometheus.Gauge movedTargetsCounter client_prometheus.Counter + mut sync.RWMutex + args Arguments + scraper *scrape.Manager + appendable *prometheus.Fanout + dtMutex sync.Mutex distributedTargets *discovery.DistributedTargets }