Browse Source

Refactor file discovery init function (#8891)

* Refactor file discovery init function

Combine to one init function like other discovery.

Signed-off-by: songjiayang <songjiayang1@gmail.com>
pull/8900/head
songjiayang 4 years ago committed by GitHub
parent
commit
b781b5cac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      discovery/consul/consul.go
  2. 3
      discovery/dns/dns.go
  3. 35
      discovery/file/file.go

3
discovery/consul/consul.go

@ -102,8 +102,7 @@ var (
func init() { func init() {
discovery.RegisterConfig(&SDConfig{}) discovery.RegisterConfig(&SDConfig{})
prometheus.MustRegister(rpcFailuresCount) prometheus.MustRegister(rpcFailuresCount, rpcDuration)
prometheus.MustRegister(rpcDuration)
} }
// SDConfig is the configuration for Consul service discovery. // SDConfig is the configuration for Consul service discovery.

3
discovery/dns/dns.go

@ -68,8 +68,7 @@ var (
func init() { func init() {
discovery.RegisterConfig(&SDConfig{}) discovery.RegisterConfig(&SDConfig{})
prometheus.MustRegister(dnsSDLookupFailuresCount) prometheus.MustRegister(dnsSDLookupFailuresCount, dnsSDLookupsCount)
prometheus.MustRegister(dnsSDLookupsCount)
} }
// SDConfig is the configuration for DNS based service discovery. // SDConfig is the configuration for DNS based service discovery.

35
discovery/file/file.go

@ -39,6 +39,19 @@ import (
) )
var ( var (
fileSDScanDuration = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "prometheus_sd_file_scan_duration_seconds",
Help: "The duration of the File-SD scan in seconds.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
})
fileSDReadErrorsCount = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "prometheus_sd_file_read_errors_total",
Help: "The number of File-SD read errors.",
})
fileSDTimeStamp = NewTimestampCollector()
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`) patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`)
// DefaultSDConfig is the default file SD configuration. // DefaultSDConfig is the default file SD configuration.
@ -49,6 +62,7 @@ var (
func init() { func init() {
discovery.RegisterConfig(&SDConfig{}) discovery.RegisterConfig(&SDConfig{})
prometheus.MustRegister(fileSDScanDuration, fileSDReadErrorsCount, fileSDTimeStamp)
} }
// SDConfig is the configuration for file based discovery. // SDConfig is the configuration for file based discovery.
@ -153,27 +167,6 @@ func NewTimestampCollector() *TimestampCollector {
} }
} }
var (
fileSDScanDuration = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "prometheus_sd_file_scan_duration_seconds",
Help: "The duration of the File-SD scan in seconds.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
})
fileSDReadErrorsCount = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "prometheus_sd_file_read_errors_total",
Help: "The number of File-SD read errors.",
})
fileSDTimeStamp = NewTimestampCollector()
)
func init() {
prometheus.MustRegister(fileSDScanDuration)
prometheus.MustRegister(fileSDReadErrorsCount)
prometheus.MustRegister(fileSDTimeStamp)
}
// Discovery provides service discovery functionality based // Discovery provides service discovery functionality based
// on files that contain target groups in JSON or YAML format. Refreshing // on files that contain target groups in JSON or YAML format. Refreshing
// happens using file watches and periodic refreshes. // happens using file watches and periodic refreshes.

Loading…
Cancel
Save