From 5e801c905d8a3d09acd03a7d7d69f885e2968625 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 9 Feb 2015 09:22:51 -0800 Subject: [PATCH] agent: Warn on dns-incompatible characters during service registration. Fixes #683. --- command/agent/agent.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index 9de70594c5..e2b2521810 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -8,6 +8,7 @@ import ( "net" "os" "path/filepath" + "regexp" "strconv" "strings" "sync" @@ -35,6 +36,11 @@ const ( "service, but no reason was provided. This is a default message." ) +var ( + // serviceNameRe checks if a service name is compatible with DNS. + serviceNameRe = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`) +) + /* The agent is the long running process that is run on every machine. It exposes an RPC interface that is used by the CLI to control the @@ -595,6 +601,12 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe } } + // Warn if the service name is incompatible with DNS + if !serviceNameRe.MatchString(service.Service) { + a.logger.Printf("[WARN] Service name %q will not be discoverable "+ + "via DNS due to invalid characters", service.Service) + } + // Add the service a.state.AddService(service)