From 722b255816114d39f1c53b3dbac00dbef4075709 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 9 Feb 2015 09:30:06 -0800 Subject: [PATCH] agent: warn on service tags with invalid chars --- command/agent/agent.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index e2b2521810..e6219a1b83 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -37,8 +37,8 @@ const ( ) var ( - // serviceNameRe checks if a service name is compatible with DNS. - serviceNameRe = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`) + // dnsNameRe checks if a name or tag is dns-compatible. + 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 - if !serviceNameRe.MatchString(service.Service) { + if !dnsNameRe.MatchString(service.Service) { a.logger.Printf("[WARN] Service name %q will not be discoverable "+ "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 a.state.AddService(service)