support host:port in metrics_address (#2042)

This commit is contained in:
wasaga 2021-03-30 18:54:33 -04:00 committed by GitHub
parent 4218f49741
commit c27cd9030d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 25 deletions

View file

@ -3,6 +3,7 @@ package config
import (
"fmt"
"net"
"strconv"
"strings"
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
@ -39,15 +40,19 @@ func GetEnvoyDNSLookupFamily(value string) envoy_config_cluster_v3.Cluster_DnsLo
return envoy_config_cluster_v3.Cluster_AUTO
}
// ValidateListenerAddress validates that a listener address is ip:port, not host:port.
func ValidateListenerAddress(addr string) error {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return fmt.Errorf("invalid address, expected host:port")
// ValidateMetricsAddress validates address for the metrics
func ValidateMetricsAddress(addr string) error {
_, port, err := net.SplitHostPort(addr)
if err != nil || port == "" {
return fmt.Errorf("expected host:port")
}
if host != "" && net.ParseIP(host) == nil {
return fmt.Errorf("invalid address, expected ip for host")
p, err := strconv.Atoi(port)
if err != nil {
return fmt.Errorf("port must be a number")
}
if p <= 0 {
return fmt.Errorf("expected positive port number")
}
return nil