mirror of
https://github.com/prometheus/prometheus.git
synced 2026-06-06 23:22:11 -04:00
Provide full SD configs to discovery constructors.
Some SD configs may have many options. To be readable and consistent, make all discovery constructors receive the full config rather than the separate arguments.
This commit is contained in:
parent
93548a8882
commit
9ca47869ed
4 changed files with 16 additions and 16 deletions
|
|
@ -70,11 +70,11 @@ type DNSDiscovery struct {
|
|||
}
|
||||
|
||||
// NewDNSDiscovery returns a new DNSDiscovery which periodically refreshes its targets.
|
||||
func NewDNSDiscovery(names []string, refreshInterval time.Duration) *DNSDiscovery {
|
||||
func NewDNSDiscovery(conf *config.DNSSDConfig) *DNSDiscovery {
|
||||
return &DNSDiscovery{
|
||||
names: names,
|
||||
names: conf.Names,
|
||||
done: make(chan struct{}),
|
||||
ticker: time.NewTicker(refreshInterval),
|
||||
ticker: time.NewTicker(time.Duration(conf.RefreshInterval)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,12 @@ type FileDiscovery struct {
|
|||
}
|
||||
|
||||
// NewFileDiscovery returns a new file discovery for the given paths.
|
||||
func NewFileDiscovery(paths []string, interval time.Duration) *FileDiscovery {
|
||||
fd := &FileDiscovery{
|
||||
paths: paths,
|
||||
interval: interval,
|
||||
func NewFileDiscovery(conf *config.FileSDConfig) *FileDiscovery {
|
||||
return &FileDiscovery{
|
||||
paths: conf.Names,
|
||||
interval: time.Duration(conf.RefreshInterval),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
return fd
|
||||
}
|
||||
|
||||
// Sources implements the TargetProvider interface.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ func TestFileSD(t *testing.T) {
|
|||
func testFileSD(t *testing.T, ext string) {
|
||||
// As interval refreshing is more of a fallback, we only want to test
|
||||
// whether file watches work as expected.
|
||||
fsd := NewFileDiscovery([]string{"fixtures/_*" + ext}, 1*time.Hour)
|
||||
var conf config.FileSDConfig
|
||||
conf.Names = []string{"fixtures/_*" + ext}
|
||||
conf.RefreshInterval = config.Duration(1 * time.Hour)
|
||||
|
||||
fsd := NewFileDiscovery(&conf)
|
||||
|
||||
ch := make(chan *config.TargetGroup)
|
||||
go fsd.Run(ch)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
|
|
@ -356,13 +355,11 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
|
|||
func ProvidersFromConfig(cfg *config.ScrapeConfig) []TargetProvider {
|
||||
var providers []TargetProvider
|
||||
|
||||
for _, dnscfg := range cfg.DNSSDConfigs {
|
||||
dnsSD := discovery.NewDNSDiscovery(dnscfg.Names, time.Duration(dnscfg.RefreshInterval))
|
||||
providers = append(providers, dnsSD)
|
||||
for _, c := range cfg.DNSSDConfigs {
|
||||
providers = append(providers, discovery.NewDNSDiscovery(c))
|
||||
}
|
||||
for _, filecfg := range cfg.FileSDConfigs {
|
||||
fileSD := discovery.NewFileDiscovery(filecfg.Names, time.Duration(filecfg.RefreshInterval))
|
||||
providers = append(providers, fileSD)
|
||||
for _, c := range cfg.FileSDConfigs {
|
||||
providers = append(providers, discovery.NewFileDiscovery(c))
|
||||
}
|
||||
if len(cfg.TargetGroups) > 0 {
|
||||
providers = append(providers, NewStaticProvider(cfg.TargetGroups))
|
||||
|
|
|
|||
Loading…
Reference in a new issue