func()

in collector/scraper.go [420:472]


func (s *Scraper) resync(ctx context.Context) {
	t := time.NewTicker(30 * time.Second)
	defer t.Stop()

	for {
		select {
		case <-ctx.Done():
			return
		case <-t.C:
			pods, err := s.scrapeClient.Pods()
			if err != nil {
				logger.Errorf("Failed to list pods: %s", err.Error())
				continue
			}

			podsOnNode := make(map[string]struct{})
			s.mu.Lock()
			for _, p := range pods.Items {
				podsOnNode[string(p.UID)] = struct{}{}

				targets := s.isScrapeable(&p)
				if len(targets) == 0 {
					continue
				}

				for _, target := range targets {
					existing, ok := s.targets[string(p.UID)]
					if ok {
						if target.Equals(existing) {
							continue
						}
						logger.Infof("Updating target %s %s", target.path(), target)
					} else {
						logger.Infof("Adding target %s %s", target.path(), target)
					}
					s.targets[string(p.UID)] = target
				}
			}

			for k, target := range s.targets {
				if target.Static {
					continue
				}
				if _, ok := podsOnNode[k]; !ok {
					logger.Infof("Removing target %s", k)
					delete(s.targets, k)
				}
			}

			s.mu.Unlock()
		}
	}
}