Replace example config with new YAML format.

This commit is contained in:
Fabian Reinartz 2015-05-07 16:47:18 +02:00
parent 5fbde88919
commit 86087120dd
7 changed files with 79 additions and 64 deletions

View file

@ -66,7 +66,7 @@ var (
}
// The default DNS SD configuration.
DefaultDNSConfig = DefaultedDNSConfig{
DefaultDNSSDConfig = DefaultedDNSSDConfig{
RefreshInterval: Duration(30 * time.Second),
}
)
@ -80,7 +80,7 @@ type Config struct {
original string
}
func (c *Config) String() string {
func (c Config) String() string {
if c.original != "" {
return c.original
}
@ -117,12 +117,12 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// DefaultedConfig is a proxy type for Config.
type DefaultedConfig struct {
GlobalConfig *GlobalConfig `yaml:"global_config"`
GlobalConfig *GlobalConfig `yaml:"global"`
RuleFiles []string `yaml:"rule_files,omitempty"`
ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"`
}
// GlobalConfig configures values that used across other configuration
// GlobalConfig configures values that are used across other configuration
// objects.
type GlobalConfig struct {
// DefaultedGlobalConfig contains the actual fields for GlobalConfig.
@ -141,11 +141,11 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// DefaultedGlobalConfig is a proxy type for GlobalConfig.
type DefaultedGlobalConfig struct {
// How frequently to scrape targets by default.
ScrapeInterval Duration `yaml:"scrape_interval"`
ScrapeInterval Duration `yaml:"scrape_interval,omitempty"`
// The default timeout when scraping targets.
ScrapeTimeout Duration `yaml:"scrape_timeout"`
ScrapeTimeout Duration `yaml:"scrape_timeout,omitempty"`
// How frequently to evaluate rules by default.
EvaluationInterval Duration `yaml:"evaluation_interval"`
EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"`
// The labels to add to any timeseries that this Prometheus instance scrapes.
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
@ -175,18 +175,18 @@ type DefaultedScrapeConfig struct {
// The job name to which the job label is set by default.
JobName string `yaml:"job_name"`
// How frequently to scrape the targets of this scrape config.
ScrapeInterval Duration `yaml:"scrape_interval"`
ScrapeInterval Duration `yaml:"scrape_interval,omitempty"`
// The timeout for scraping targets of this config.
ScrapeTimeout Duration `yaml:"scrape_timeout"`
ScrapeTimeout Duration `yaml:"scrape_timeout,omitempty"`
// The HTTP resource path on which to fetch metrics from targets.
MetricsPath string `yaml:"metrics_path"`
MetricsPath string `yaml:"metrics_path,omitempty"`
// The URL scheme with which to fetch metrics from targets.
Scheme string `yaml:"scheme"`
Scheme string `yaml:"scheme,omitempty"`
// List of labeled target groups for this job.
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
// List of DNS service discovery configurations.
DNSConfigs []*DNSConfig `yaml:"dns_configs,omitempty"`
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
// List of relabel configurations.
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
}
@ -203,7 +203,7 @@ type TargetGroup struct {
Source string `yaml:"-", json:"-"`
}
func (tg *TargetGroup) String() string {
func (tg TargetGroup) String() string {
return tg.Source
}
@ -229,29 +229,44 @@ func (tg *TargetGroup) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}
// DNSConfig is the configuration for DNS based service discovery.
type DNSConfig struct {
// DefaultedDNSConfig contains the actual fields for DNSConfig.
DefaultedDNSConfig `yaml:",inline"`
// MarshalYAML implements the yaml.Marshaller interface.
func (tg TargetGroup) MarshalYAML() (interface{}, error) {
g := &struct {
Targets []string `yaml:"targets"`
Labels clientmodel.LabelSet `yaml:"labels,omitempty"`
}{
Targets: make([]string, 0, len(tg.Targets)),
Labels: tg.Labels,
}
for _, t := range tg.Targets {
g.Targets = append(g.Targets, string(t[clientmodel.AddressLabel]))
}
return g, nil
}
// DNSSDConfig is the configuration for DNS based service discovery.
type DNSSDConfig struct {
// DefaultedDNSSDConfig contains the actual fields for DNSSDConfig.
DefaultedDNSSDConfig `yaml:",inline"`
}
// UnmarshalYAML implements the yaml.Unmarshaller interface.
func (c *DNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
c.DefaultedDNSConfig = DefaultDNSConfig
err := unmarshal(&c.DefaultedDNSConfig)
func (c *DNSSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
c.DefaultedDNSSDConfig = DefaultDNSSDConfig
err := unmarshal(&c.DefaultedDNSSDConfig)
if err != nil {
return err
}
if len(c.Names) == 0 {
return fmt.Errorf("DNS config must contain at least one SRV server name")
return fmt.Errorf("DNS config must contain at least one SRV record name")
}
return nil
}
// DefaultedDNSConfig is a proxy type for DNSConfig.
type DefaultedDNSConfig struct {
// DefaultedDNSSDConfig is a proxy type for DNSSDConfig.
type DefaultedDNSSDConfig struct {
Names []string `yaml:"names"`
RefreshInterval Duration `yaml:"refresh_interval"`
RefreshInterval Duration `yaml:"refresh_interval,omitempty"`
}
// RelabelAction is the action to be performed on relabeling.
@ -298,7 +313,7 @@ type DefaultedRelabelConfig struct {
// with the configured separator in order.
SourceLabels clientmodel.LabelNames `yaml:"source_labels,flow"`
// Separator is the string between concatenated values from the source labels.
Separator string `yaml:"separator"`
Separator string `yaml:"separator,omitempty"`
// Regex against which the concatenation is matched.
Regex *Regexp `yaml:"regex"`
// The label to which the resulting string is written in a replacement.
@ -306,7 +321,7 @@ type DefaultedRelabelConfig struct {
// Replacement is the regex replacement pattern to be used.
Replacement string `yaml:"replacement,omitempty"`
// Action is the action to be performed for the relabeling.
Action RelabelAction `yaml:"action"`
Action RelabelAction `yaml:"action,omitempty"`
}
// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.
@ -329,7 +344,7 @@ func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
// MarshalYAML implements the yaml.Marshaller interface.
func (re *Regexp) MarshalYAML() (interface{}, error) {
func (re Regexp) MarshalYAML() (interface{}, error) {
return re.String(), nil
}

View file

@ -72,15 +72,15 @@ var expectedConf = &Config{DefaultedConfig{
MetricsPath: "/my_path",
Scheme: "http",
DNSConfigs: []*DNSConfig{
{DefaultedDNSConfig{
DNSSDConfigs: []*DNSSDConfig{
{DefaultedDNSSDConfig{
Names: []string{
"first.dns.address.domain.com",
"second.dns.address.domain.com",
},
RefreshInterval: Duration(15 * time.Second),
}},
{DefaultedDNSConfig{
{DefaultedDNSSDConfig{
Names: []string{
"first.dns.address.domain.com",
},

View file

@ -1,5 +1,5 @@
# my global config
global_config:
global:
scrape_interval: 15s
evaluation_interval: 30s
# scrape_timeout is set to the global default (10s).
@ -46,7 +46,7 @@ scrape_configs:
metrics_path: /my_path
# scheme defaults to 'http'.
dns_configs:
dns_sd_configs:
- refresh_interval: 15s
names:
- first.dns.address.domain.com

View file

@ -1,3 +1,3 @@
global_config:
global:
labels:
not$allowed: value

View file

@ -1,30 +0,0 @@
# Global default settings.
global {
scrape_interval: "15s" # By default, scrape targets every 15 seconds.
evaluation_interval: "15s" # By default, evaluate rules every 15 seconds.
# Attach these extra labels to all timeseries collected by this Prometheus instance.
labels: {
label: {
name: "monitor"
value: "codelab-monitor"
}
}
# Load and evaluate rules in this file every 'evaluation_interval' seconds. This field may be repeated.
#rule_file: "prometheus.rules"
}
# A job definition containing exactly one endpoint to scrape: Here it's prometheus itself.
job: {
# The job name is added as a label `job={job-name}` to any timeseries scraped from this job.
name: "prometheus"
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: "5s"
# Let's define a group of targets to scrape for this job. In this case, only one.
target_group: {
# These endpoints are scraped via HTTP.
target: "http://localhost:9090/metrics"
}
}

View file

@ -0,0 +1,30 @@
# my global config
global_config:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these extra labels to all timeseries collected by this Prometheus instance.
labels:
monitor: codelab-monitor
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
rule_files:
# - "first.rules"
# - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: prometheus
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
scrape_timeout: 10s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
target_groups:
- targets: ['localhost:9090']

View file

@ -360,7 +360,7 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
func ProvidersFromConfig(cfg *config.ScrapeConfig) ([]TargetProvider, error) {
var providers []TargetProvider
for _, dnscfg := range cfg.DNSConfigs {
for _, dnscfg := range cfg.DNSSDConfigs {
dnsSD := discovery.NewDNSDiscovery(dnscfg.Names, time.Duration(dnscfg.RefreshInterval))
providers = append(providers, dnsSD)
}