mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Allow number to be the first letter as well for job_name
This commit is contained in:
commit
1aa8898b66
|
@ -28,7 +28,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
patJobName = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`)
|
|
||||||
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`)
|
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`)
|
||||||
patRulePath = regexp.MustCompile(`^[^*]*(\*[^/]*)?$`)
|
patRulePath = regexp.MustCompile(`^[^*]*(\*[^/]*)?$`)
|
||||||
patAuthLine = regexp.MustCompile(`((?:password|bearer_token|secret_key|client_secret):\s+)(".+"|'.+'|[^\s]+)`)
|
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 {
|
if err := checkOverflow(c.XXX, "scrape_config"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !patJobName.MatchString(c.JobName) {
|
if len(c.JobName) == 0 {
|
||||||
return fmt.Errorf("%q is not a valid job name", c.JobName)
|
return fmt.Errorf("job_name is empty")
|
||||||
}
|
}
|
||||||
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
|
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
|
||||||
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")
|
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")
|
||||||
|
|
|
@ -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: "",
|
original: "",
|
||||||
}
|
}
|
||||||
|
@ -351,7 +385,7 @@ var expectedErrors = []struct {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
filename: "jobname.bad.yml",
|
filename: "jobname.bad.yml",
|
||||||
errMsg: `"prom^etheus" is not a valid job name`,
|
errMsg: `job_name is empty`,
|
||||||
}, {
|
}, {
|
||||||
filename: "jobname_dup.bad.yml",
|
filename: "jobname_dup.bad.yml",
|
||||||
errMsg: `found multiple scrape configs with job name "prometheus"`,
|
errMsg: `found multiple scrape configs with job name "prometheus"`,
|
||||||
|
|
12
config/testdata/conf.good.yml
vendored
12
config/testdata/conf.good.yml
vendored
|
@ -142,3 +142,15 @@ scrape_configs:
|
||||||
- localhost
|
- localhost
|
||||||
paths:
|
paths:
|
||||||
- /monitoring
|
- /monitoring
|
||||||
|
|
||||||
|
- job_name: 0123service-xxx
|
||||||
|
metrics_path: /metrics
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost:9090
|
||||||
|
|
||||||
|
- job_name: 測試
|
||||||
|
metrics_path: /metrics
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost:9090
|
||||||
|
|
2
config/testdata/jobname.bad.yml
vendored
2
config/testdata/jobname.bad.yml
vendored
|
@ -1,2 +1,2 @@
|
||||||
scrape_configs:
|
scrape_configs:
|
||||||
- job_name: prom^etheus
|
- job_name:
|
||||||
|
|
Loading…
Reference in a new issue