agent: warn on service tags with invalid chars

This commit is contained in:
Ryan Uber 2015-02-09 09:30:06 -08:00
parent 5e801c905d
commit 722b255816

View File

@ -37,8 +37,8 @@ const (
) )
var ( var (
// serviceNameRe checks if a service name is compatible with DNS. // dnsNameRe checks if a name or tag is dns-compatible.
serviceNameRe = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`) dnsNameRe = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)
) )
/* /*
@ -602,11 +602,19 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe
} }
// Warn if the service name is incompatible with DNS // Warn if the service name is incompatible with DNS
if !serviceNameRe.MatchString(service.Service) { if !dnsNameRe.MatchString(service.Service) {
a.logger.Printf("[WARN] Service name %q will not be discoverable "+ a.logger.Printf("[WARN] Service name %q will not be discoverable "+
"via DNS due to invalid characters", service.Service) "via DNS due to invalid characters", service.Service)
} }
// Warn if any tags are incompatible with DNS
for _, tag := range service.Tags {
if !dnsNameRe.MatchString(tag) {
a.logger.Printf("[WARN] Service tag %q will not be discoverable "+
"via DNS due to invalid characters", tag)
}
}
// Add the service // Add the service
a.state.AddService(service) a.state.AddService(service)