mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-02 02:42:57 +02:00
metrics_address should be optional parameter (#2087)
This commit is contained in:
parent
1dcccf2b56
commit
c12c0aab49
2 changed files with 10 additions and 16 deletions
|
@ -1,7 +1,6 @@
|
||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,9 +14,3 @@ const (
|
||||||
// path metrics are available at
|
// path metrics are available at
|
||||||
defaultMetricsPath = "/metrics"
|
defaultMetricsPath = "/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errNoMetricsAddr = errors.New("no metrics address provided")
|
|
||||||
errNoMetricsPort = errors.New("no metrics port provided")
|
|
||||||
errNoMetricsHost = errors.New("no metrics host provided")
|
|
||||||
)
|
|
||||||
|
|
|
@ -30,8 +30,7 @@ func (r *Reporter) OnConfigChange(cfg *config.Config) {
|
||||||
|
|
||||||
services, err := getReportedServices(cfg)
|
services, err := getReportedServices(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("service registry reporter")
|
log.Warn().Err(err).Msg("metrics announce to service registry is disabled")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sharedKey, err := base64.StdEncoding.DecodeString(cfg.Options.SharedKey)
|
sharedKey, err := base64.StdEncoding.DecodeString(cfg.Options.SharedKey)
|
||||||
|
@ -63,10 +62,12 @@ func (r *Reporter) OnConfigChange(cfg *config.Config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(services) > 0 {
|
||||||
ctx, cancel := context.WithCancel(context.TODO())
|
ctx, cancel := context.WithCancel(context.TODO())
|
||||||
go runReporter(ctx, pb.NewRegistryClient(registryConn), services)
|
go runReporter(ctx, pb.NewRegistryClient(registryConn), services)
|
||||||
r.cancel = cancel
|
r.cancel = cancel
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getReportedServices(cfg *config.Config) ([]*pb.Service, error) {
|
func getReportedServices(cfg *config.Config) ([]*pb.Service, error) {
|
||||||
mu, err := metricsURL(*cfg.Options)
|
mu, err := metricsURL(*cfg.Options)
|
||||||
|
@ -103,20 +104,20 @@ func metricsURL(o config.Options) (*url.URL, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.MetricsAddr == "" {
|
if o.MetricsAddr == "" {
|
||||||
return nil, errNoMetricsAddr
|
return nil, fmt.Errorf("no metrics address provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
host, port, err := net.SplitHostPort(o.MetricsAddr)
|
host, port, err := net.SplitHostPort(o.MetricsAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid metrics address: %w", err)
|
return nil, fmt.Errorf("invalid metrics address %q: %w", o.MetricsAddr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if port == "" {
|
if port == "" {
|
||||||
return nil, errNoMetricsPort
|
return nil, fmt.Errorf("invalid metrics value %q: port is required", o.MetricsAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if host == "" {
|
if host == "" {
|
||||||
return nil, errNoMetricsHost
|
return nil, fmt.Errorf("invalid metrics value %q: either host or IP address is required", o.MetricsAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &u, nil
|
return &u, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue