Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't grab instances that service.Name include "." #1205

Closed
curry7313 opened this issue Apr 19, 2019 · 3 comments · Fixed by #1220
Closed

Can't grab instances that service.Name include "." #1205

curry7313 opened this issue Apr 19, 2019 · 3 comments · Fixed by #1220
Labels
Milestone

Comments

@curry7313
Copy link

curry7313 commented Apr 19, 2019

Consul include two services:

consul
go.micro.api.greeter

Configuration

Consul Template configuration file(app.ctmpl):

{{range services}}
 	 upstream {{.Name}} {
    	 {{range service .Name}}
   	     server {{.Address}}:{{.Port}};
	 {{end}}
    }
{{end}}

Shell

consul-template -template "app.ctmpl:nginx.conf" -once

nginx.conf

upstream consul { 
   	     server 127.0.0.1:8300; 
    }   
 upstream go.micro.api.greeter {	 
   }

why instances of "go.micro.api.greeter" is not be found?

@curry7313 curry7313 changed the title Can't grab instances that service Can't grab instances that service.Name incloud "." Apr 19, 2019
@curry7313 curry7313 changed the title Can't grab instances that service.Name incloud "." Can't grab instances that service.Name include "." Apr 19, 2019
@eikenb
Copy link
Contributor

eikenb commented Jun 18, 2019

To reproduce this I created a small config file for the service...

$ cat greeter.json
{
  "Service": {
    "Name": "go.micro.api.greeter",
    "Address": "localhost",
    "Port": 99
  }
}

Registered it...

$ consul services register greeter.json

Then ran consul-template and got the same results as you...

$ consul-template -once -dry -template ./app.ctmpl
(output same as you list)

If I switch the dots to dashes though, it works.

$ cat greeter-dashes.json
{
  "Service": {
    "Name": "go-micro-api-greeter",
    "Address": "localhost", 
    "Port": 99
  }
}

Registered it like above, and ran the template and it worked...
consul-template -once -template ./app.tmpl -dry

upstream consul {
    server 127.0.0.1:8300;
}

upstream go-micro-api-greeter {
    server localhost:99;
}

I know consul's DNS interface doesn't like service names with dots in them and it might be related. Haven't dug into the code yet, just wanted to note how I reproduced it at this point.

@eikenb
Copy link
Contributor

eikenb commented Jun 18, 2019

I'm labeling as a bug for the moment but if it ends up that it is using consul in a way that it is hitting this DNS limitation then it will probably change to a documentation issue.

@eikenb
Copy link
Contributor

eikenb commented Jun 21, 2019

Found the problem and I think this is going to change to a documentation issue. Names with dots/periods ('.') in them won't work properly with the template format as it uses the dot for a separator. Snipped from the service api functions section in the readme...

Query Consul for services based on their health.

{{ service "<TAG>.<NAME>@<DATACENTER>~<NEAR>|<FILTER>" }}

Notice the dot between the tag and name, <TAG>.<NAME>. That is matching against the service name with the dots in it and interprets it as with the TAG being 'go.micro.api' and the name being just 'greeter'. So the service api lookup call fails to find a match.

There is no way to fix this in the code with that delimiter being what it is, so I'm going to make this issue a documentation issue to make sure to call that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants