mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Add file SD to configuration.
This commit is contained in:
parent
d5aa012fd0
commit
3b21c7037a
|
@ -14,7 +14,10 @@ import (
|
||||||
"github.com/prometheus/prometheus/utility"
|
"github.com/prometheus/prometheus/utility"
|
||||||
)
|
)
|
||||||
|
|
||||||
var jobNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_-]*$")
|
var (
|
||||||
|
patJobName = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`)
|
||||||
|
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml)$`)
|
||||||
|
)
|
||||||
|
|
||||||
// Load parses the YAML input s into a Config.
|
// Load parses the YAML input s into a Config.
|
||||||
func Load(s string) (*Config, error) {
|
func Load(s string) (*Config, error) {
|
||||||
|
@ -69,6 +72,11 @@ var (
|
||||||
DefaultDNSSDConfig = DefaultedDNSSDConfig{
|
DefaultDNSSDConfig = DefaultedDNSSDConfig{
|
||||||
RefreshInterval: Duration(30 * time.Second),
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The default file SD configuration.
|
||||||
|
DefaultFileSDConfig = DefaultedFileSDConfig{
|
||||||
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the top-level configuration for Prometheus's config files.
|
// Config is the top-level configuration for Prometheus's config files.
|
||||||
|
@ -164,7 +172,7 @@ func (c *ScrapeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !jobNameRE.MatchString(c.JobName) {
|
if !patJobName.MatchString(c.JobName) {
|
||||||
return fmt.Errorf("%q is not a valid job name", c.JobName)
|
return fmt.Errorf("%q is not a valid job name", c.JobName)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -189,6 +197,8 @@ type DefaultedScrapeConfig struct {
|
||||||
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
|
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
|
||||||
// List of DNS service discovery configurations.
|
// List of DNS service discovery configurations.
|
||||||
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
||||||
|
// List of file service discovery configurations.
|
||||||
|
FileSDConfigs []*FileSDConfig `yaml:"file_sd_configs,omitempty"`
|
||||||
// List of relabel configurations.
|
// List of relabel configurations.
|
||||||
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
|
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -266,7 +276,7 @@ func (c *DNSSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(c.Names) == 0 {
|
if len(c.Names) == 0 {
|
||||||
return fmt.Errorf("DNS config must contain at least one SRV record name")
|
return fmt.Errorf("DNS-SD config must contain at least one SRV record name")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -277,6 +287,36 @@ type DefaultedDNSSDConfig struct {
|
||||||
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
|
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FileSDConfig is the configuration for file based discovery.
|
||||||
|
type FileSDConfig struct {
|
||||||
|
// DefaultedFileSDConfig contains the actual fields for FileSDConfig.
|
||||||
|
DefaultedFileSDConfig `yaml:",inline"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements the yaml.Unmarshaller interface.
|
||||||
|
func (c *FileSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
c.DefaultedFileSDConfig = DefaultFileSDConfig
|
||||||
|
err := unmarshal(&c.DefaultedFileSDConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(c.Names) == 0 {
|
||||||
|
return fmt.Errorf("file discovery config must contain at least on path name")
|
||||||
|
}
|
||||||
|
for _, name := range c.Names {
|
||||||
|
if !patFileSDName.MatchString(name) {
|
||||||
|
return fmt.Errorf("path name %q is not valid for file discovery", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultedFileSDConfig is a proxy type for FileSDConfig.
|
||||||
|
type DefaultedFileSDConfig struct {
|
||||||
|
Names []string `yaml:"names"`
|
||||||
|
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// RelabelAction is the action to be performed on relabeling.
|
// RelabelAction is the action to be performed on relabeling.
|
||||||
type RelabelAction string
|
type RelabelAction string
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,17 @@ var expectedConf = &Config{DefaultedConfig{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
FileSDConfigs: []*FileSDConfig{
|
||||||
|
{DefaultedFileSDConfig{
|
||||||
|
Names: []string{"foo/*.slow.json", "foo/*.slow.yml"},
|
||||||
|
RefreshInterval: Duration(10 * time.Minute),
|
||||||
|
}},
|
||||||
|
{DefaultedFileSDConfig{
|
||||||
|
Names: []string{"bar/*.yaml"},
|
||||||
|
RefreshInterval: Duration(30 * time.Second),
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
|
||||||
RelabelConfigs: []*RelabelConfig{
|
RelabelConfigs: []*RelabelConfig{
|
||||||
{DefaultedRelabelConfig{
|
{DefaultedRelabelConfig{
|
||||||
SourceLabels: clientmodel.LabelNames{"job", "__meta_dns_srv_name"},
|
SourceLabels: clientmodel.LabelNames{"job", "__meta_dns_srv_name"},
|
||||||
|
|
8
config/testdata/conf.good.yml
vendored
8
config/testdata/conf.good.yml
vendored
|
@ -24,6 +24,14 @@ scrape_configs:
|
||||||
labels:
|
labels:
|
||||||
foo: baz
|
foo: baz
|
||||||
|
|
||||||
|
file_sd_configs:
|
||||||
|
- names:
|
||||||
|
- foo/*.slow.json
|
||||||
|
- foo/*.slow.yml
|
||||||
|
refresh_interval: 10m
|
||||||
|
- names:
|
||||||
|
- bar/*.yaml
|
||||||
|
|
||||||
target_groups:
|
target_groups:
|
||||||
- targets: ['localhost:9090', 'localhost:9191']
|
- targets: ['localhost:9090', 'localhost:9191']
|
||||||
labels:
|
labels:
|
||||||
|
|
Loading…
Reference in a new issue