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

Ability to set a tag on Consul's own service registration #2299

Open
far-blue opened this issue Aug 23, 2016 · 13 comments
Open

Ability to set a tag on Consul's own service registration #2299

far-blue opened this issue Aug 23, 2016 · 13 comments
Labels
theme/service-metadata Anything related to management/tracking of service metadata type/enhancement Proposed improvement or new feature

Comments

@far-blue
Copy link

It would be useful if consul was able to add tags to its own service registration. This could be to allow referring to particular instances by DNS or it could be for external uses such as Fabio proxy routing.

@slackpad
Copy link
Contributor

Hi @far-blue - what uses were you thinking of? We probably should just have Consul tag itself automatically for most things (leader, follower seems like a good one for servers), any other use cases you had in mind?

@slackpad slackpad added the type/enhancement Proposed improvement or new feature label Aug 23, 2016
@far-blue
Copy link
Author

leader / follower is a good example for an automated tag but tagging is also helpful just as labels for managing resources. Some third party apps such as Fabio and anything built using consul-template to react to service data also tend to use tags to identify or exclude services.

@slackpad
Copy link
Contributor

Are you looking to add tags related to Consul's service itself, though, or are you more looking for tags that represent the node as a whole?

@far-blue
Copy link
Author

That's a good question. I guess I was thinking in terms of Consul's Rest API as a service - much like Nomad and Vault present their API interface(s) as services and that is still my interest.

However, I guess it is also fair to say that nodes themselves could have tags rather than the consul service per-se. I guess this would be closer to Nomad's 'meta' info for agents. Grouping of nodes based on a tag would allow dns queries for nodes similar to services.

@bfgoodrich
Copy link

As far as tags for nodes - #154

@bacoboy
Copy link

bacoboy commented Sep 30, 2016

A good use case for this is when using traefik's consul_catalog.

Consul's self registration gets picked up as a real service on port 8300. The way you tell traefik to ignore this is by setting a tag traefik.enable=false on the service (like traefik does to its own services):

% curl -s http://127.0.0.1:8500/v1/catalog/services | jq
{
  "consul": [],
  "traefik-dashboard": [
    "traefik.enable=false"
  ],
  "traefik-http": [
    "traefik.enable=false"
  ]
}

I stumbled across this issue looking for how to set a tag on consul's self-registration 😉

@slackpad slackpad added the theme/service-metadata Anything related to management/tracking of service metadata label May 18, 2017
@sev3ryn
Copy link

sev3ryn commented Aug 6, 2020

I'm using tags to point Prometheus what services to scrape for metrics and what metric_path to use - this would be useful to be able to scrape from Consul's /v1/agent/metrics?format=prometheus endpoint

@jinnatar
Copy link

jinnatar commented Sep 15, 2021

Any updates to this one? While I can manage any service in Consul with tags to configure it for Traefik, ironically I cannot manage the Consul UI itself since I cannot add tags to it that would then be consumed by the Traefik consul_catalog. I can configure it as a static Traefik routing but then lose health check based load balancing.

@blmhemu
Copy link

blmhemu commented Sep 28, 2021

Hello @Artanicus ! May I ask, if you can share your static config. I am looking for something similar and came across this...

@itorres
Copy link

itorres commented Oct 4, 2021

@blmhemu something like this will expose the local consul agent (and in our case also nomad):

http:                                    
  routers:                               
    consul:                              
      rule: "Host(`consul.example.net`)"
      service: "consul"                  
    nomad:                               
      rule: "Host(`nomad.example.net`)" 
      service: "nomad"                   
  services:                              
    consul:                              
      loadBalancer:                      
        servers:                         
          - url: "http://localhost:8500" 
    nomad:                               
      loadBalancer:                      
        servers:                         
          - url: "http://localhost:4646" 

@blmhemu
Copy link

blmhemu commented Oct 5, 2021

@itorres Thanks for the reply ! In the meanwhile, while searching on web, I think I may have found another solution (thanks to Michael Aldrige) using consul's service discovery. http://localhost:4646 can also be written as http://nomad.service.consul:4646.

@dnephin
Copy link
Contributor

dnephin commented Oct 7, 2021

Cross posting a comment I left on a duplicate issue about how this might be implemented.

We discussed this a bit. It us my understanding that this could actually be challenging to implement correctly because of how Consul registers itself as a service. When a Consul node starts it does not itself perform an RPC call to register itself in the Catalog. Instead, what happens is that the gossip "node join" event causes the leader to register the node in the Catalog. So to get these tags into the Catalog the tags would have to be added to the serf tags. This is a problem because serf message have a fixed maximum size, so someone trying to add many tags could exceed the maximum size and cause the node join to fail.

It's difficult to determine the maximum size for tags because we don't know at the time of config validation the size of the other parts of the message.

Two options for addressing this problem would be:

We could introduce some very strict limits for the tags (both number of tags, and maximum size for the key and value)
We could find a different way of registering nodes in the Catalog. I believe the anti-entropy sync also updates the node registration. Maybe that could be used to update the tags?

If we do it as part of the anti-entropy sync, we could add the tags here: https://github.com/hashicorp/consul/blob/v1.10.3/agent/local/state.go#L1360-L1370

But @rboyer pointed out that for this to work the agent token would need additional privileges to update the consul service .

@chrisvanmeer
Copy link

Any new thoughts on this? My use case would for using this with Traefik, but I don't want to expose all my services by default so I should be able to manually add tags to the own consul service.

For now I will have to stick to a file provider and manually configure the Consul servers in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/service-metadata Anything related to management/tracking of service metadata type/enhancement Proposed improvement or new feature
Projects
None yet
Development

No branches or pull requests

10 participants