mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
27 lines
626 B
Go
27 lines
626 B
Go
package discoveryutils
|
|
|
|
import (
|
|
"net"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
// SanitizeLabelName replaces anything that doesn't match
|
|
// client_label.LabelNameRE with an underscore.
|
|
//
|
|
// This has been copied from Prometheus sources at util/strutil/strconv.go
|
|
func SanitizeLabelName(name string) string {
|
|
return invalidLabelCharRE.ReplaceAllString(name, "_")
|
|
}
|
|
|
|
var (
|
|
invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
|
)
|
|
|
|
// JoinHostPort returns host:port.
|
|
//
|
|
// Host may be dns name, ipv4 or ipv6 address.
|
|
func JoinHostPort(host string, port int) string {
|
|
portStr := strconv.Itoa(port)
|
|
return net.JoinHostPort(host, portStr)
|
|
}
|