Allow number to be the first letter as well for job_name

This commit is contained in:
Donatas Abraitis 2016-09-15 08:00:14 +02:00 committed by Donatas Abraitis
commit 1aa8898b66
4 changed files with 50 additions and 5 deletions

View file

@ -28,7 +28,6 @@ import (
)
var (
patJobName = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`)
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`)
patRulePath = regexp.MustCompile(`^[^*]*(\*[^/]*)?$`)
patAuthLine = regexp.MustCompile(`((?:password|bearer_token|secret_key|client_secret):\s+)(".+"|'.+'|[^\s]+)`)
@ -454,8 +453,8 @@ func (c *ScrapeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := checkOverflow(c.XXX, "scrape_config"); err != nil {
return err
}
if !patJobName.MatchString(c.JobName) {
return fmt.Errorf("%q is not a valid job name", c.JobName)
if len(c.JobName) == 0 {
return fmt.Errorf("job_name is empty")
}
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")

View file

@ -307,6 +307,40 @@ var expectedConf = &Config{
},
},
},
{
JobName: "0123service-xxx",
ScrapeInterval: model.Duration(15 * time.Second),
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
MetricsPath: DefaultScrapeConfig.MetricsPath,
Scheme: DefaultScrapeConfig.Scheme,
StaticConfigs: []*TargetGroup{
{
Targets: []model.LabelSet{
{model.AddressLabel: "localhost:9090"},
},
},
},
},
{
JobName: "測試",
ScrapeInterval: model.Duration(15 * time.Second),
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
MetricsPath: DefaultScrapeConfig.MetricsPath,
Scheme: DefaultScrapeConfig.Scheme,
StaticConfigs: []*TargetGroup{
{
Targets: []model.LabelSet{
{model.AddressLabel: "localhost:9090"},
},
},
},
},
},
original: "",
}
@ -351,7 +385,7 @@ var expectedErrors = []struct {
}{
{
filename: "jobname.bad.yml",
errMsg: `"prom^etheus" is not a valid job name`,
errMsg: `job_name is empty`,
}, {
filename: "jobname_dup.bad.yml",
errMsg: `found multiple scrape configs with job name "prometheus"`,

View file

@ -142,3 +142,15 @@ scrape_configs:
- localhost
paths:
- /monitoring
- job_name: 0123service-xxx
metrics_path: /metrics
static_configs:
- targets:
- localhost:9090
- job_name: 測試
metrics_path: /metrics
static_configs:
- targets:
- localhost:9090

View file

@ -1,2 +1,2 @@
scrape_configs:
- job_name: prom^etheus
- job_name: