| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package vsphere |
| 4 | |
| 5 | import "fmt" |
| 6 | |
| 7 | func (c *Collector) goDiscovery() { |
| 8 | c.stopDiscoveryTask(false) |
| 9 | c.Infof("starting discovery process, will do discovery every %s", c.DiscoveryInterval) |
| 10 | |
| 11 | job := func() { |
| 12 | err := c.discoverOnce() |
| 13 | if err != nil { |
| 14 | c.Limit(logKeyDiscoveryError, 1, recurringLogEvery). |
| 15 | Errorf("periodic vSphere discovery failed: %v", err) |
| 16 | } |
| 17 | } |
| 18 | c.discoveryTask = newTask(job, c.DiscoveryInterval.Duration()) |
| 19 | } |
| 20 | |
| 21 | func (c *Collector) discoverOnce() error { |
| 22 | res, err := c.Discover() |
| 23 | if err != nil { |
| 24 | return fmt.Errorf("discover vSphere resources through configured discoverer: %w", err) |
| 25 | } |
| 26 | |
| 27 | c.collectionLock.Lock() |
| 28 | c.resources = res |
| 29 | c.collectionLock.Unlock() |
| 30 | |
| 31 | return nil |
| 32 | } |