code: func (m *Manager) ApplyConfig(cfg *config.Config) error {
  	m.mtxScrape.Lock()
  	defer m.mtxScrape.Unlock()
  
  	c := make(map[string]*config.ScrapeConfig)
  	for _, scfg := range cfg.ScrapeConfigs {
  		c[scfg.JobName] = scfg
  	}
  	m.scrapeConfigs = c
  
  	if err := m.setJitterSeed(cfg.GlobalConfig.ExternalLabels); err != nil {
  		return err
  	}
  
  	// Cleanup and reload pool if the configuration has changed.
  	var failed bool
  	for name, sp := range m.scrapePools {
  		if cfg, ok := m.scrapeConfigs[name]; !ok {
  			sp.stop()
  			delete(m.scrapePools, name)
  		} else if !reflect.DeepEqual(sp.config, cfg) {
  			err := sp.reload(cfg)
  			if err != nil {
  				level.Error(m.logger).Log("msg", "error reloading scrape pool", "err", err, "scrape_pool", name)
  				failed = true
  			}
  		}
  	}
  
  	if failed {
  		return errors.New("failed to apply the new configuration")
  	}
  	return nil
  }
docs: // ApplyConfig resets the manager's target providers and job configurations as defined by the new cfg.