| 1234567891011121314151617181920212223242526272829 |
- package scrape
- import (
- "github.com/opencost/opencost/modules/collector-source/pkg/metric"
- )
- type Scraper interface {
- Scrape() []metric.Update
- }
- type ScrapeFunc func() []metric.Update
- func concurrentScrape(scrapeFuncs ...ScrapeFunc) []metric.Update {
- resultCh := make(chan []metric.Update)
- defer close(resultCh)
- for _, scrapeFunc := range scrapeFuncs {
- go func() {
- scrapeResults := scrapeFunc()
- resultCh <- scrapeResults
- }()
- }
- var scrapeResults []metric.Update
- for range scrapeFuncs {
- targetResults := <-resultCh
- scrapeResults = append(scrapeResults, targetResults...)
- }
- return scrapeResults
- }
|