diff --git a/config/config.go b/config/config.go index 3141ca8e6..1391f0dfb 100644 --- a/config/config.go +++ b/config/config.go @@ -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") diff --git a/config/config_test.go b/config/config_test.go index 2b0d1b8da..c9a94a46b 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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"`, diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml index ea9acfbf1..ac80a524f 100644 --- a/config/testdata/conf.good.yml +++ b/config/testdata/conf.good.yml @@ -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 diff --git a/config/testdata/jobname.bad.yml b/config/testdata/jobname.bad.yml index 2d08e1f82..3c3099c9a 100644 --- a/config/testdata/jobname.bad.yml +++ b/config/testdata/jobname.bad.yml @@ -1,2 +1,2 @@ scrape_configs: - - job_name: prom^etheus + - job_name: