consul_exporter
consul_exporter copied to clipboard
Exposing consul service instance meta data
Currently, consul_exporter exposes both catalogue KV and service tags via consul_service_tag
.
Registered services in consul can also expose metadata which is a KV structure but without the special meaning of tags during lookups.
I wonder if support for service metadata is something that you would consider adding in a future release?
I would need to dig deeper into this but maybe could you give me a concrete example?
Service instances in Consul can include both tags
and meta
:
The tags property is a list of values that are opaque to Consul but can be used to distinguish between primary or secondary nodes, different versions, or any other service level labels.
The meta object is a map of max 64 key/values with string semantics (...). All those meta data can be retrieved individually per instance of the service and all the instances of a given service have their own copy of it.
We use the meta
where we want to attach metadata to a service and don't require any special DNS handling. Stuff like service version, service owner, and so on.
From what I can tell, the meta is only exposed in Web UI or the HTTP API, not the Consul CLI.
So exposing this metadata with consul_exporter can be useful, for example, it can expose service versions in one central location without the need to instrument every service individually with info_* metrics.
For example, today consul_exporter exposes tags like this:
consul_service_tag{service_id="_nomad-client-c753udjlfd7tszi4r5hgwuypz3n4xwey", tag="http"} 1
Would be nice if similarly we could see the meta:
consul_service_meta{service_id="_nomad-client-c753udjlfd7tszi4r5hgwuypz3n4xwey", key1="value1", key2="value2"} 1
I can see how it could potentially lead to high label cardinality. At the very least it should be behind a flag. Does it make sense to be able to filter which keys get exported (e.g. like it's done for K/V pairs)?
Yep, that would make sense, similar to kv filter.
Its been a while since I wrote Go, but I can give it a crack, would a PR be welcome?
sure go for it :)
Took me a while to get back to it but just opened a PR for initial attempt. Let me know if I'm in a good direction. Cheers.
Hi @m1keil ,
I have the same requirement: using "consul_service_meta" instead of "consul_service_tag". What's the current status ?
I opened up an initial PR with a POC (#204), waiting to hear feedback from maintainers if this is the way to go.
I will look at this in the coming days.
no worries @roidelapluie, cheers!