consul_exporter icon indicating copy to clipboard operation
consul_exporter copied to clipboard

Exposing consul service instance meta data

Open m1keil opened this issue 4 years ago • 10 comments

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?

m1keil avatar Nov 13 '20 06:11 m1keil

I would need to dig deeper into this but maybe could you give me a concrete example?

simonpasquier avatar Jan 29 '21 15:01 simonpasquier

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

m1keil avatar Feb 03 '21 08:02 m1keil

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)?

simonpasquier avatar Feb 05 '21 16:02 simonpasquier

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?

m1keil avatar Feb 06 '21 01:02 m1keil

sure go for it :)

simonpasquier avatar Feb 09 '21 17:02 simonpasquier

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.

m1keil avatar May 02 '21 06:05 m1keil

Hi @m1keil ,

I have the same requirement: using "consul_service_meta" instead of "consul_service_tag". What's the current status ?

rfelgent avatar May 25 '21 10:05 rfelgent

I opened up an initial PR with a POC (#204), waiting to hear feedback from maintainers if this is the way to go.

m1keil avatar May 25 '21 12:05 m1keil

I will look at this in the coming days.

roidelapluie avatar May 25 '21 22:05 roidelapluie

no worries @roidelapluie, cheers!

m1keil avatar May 26 '21 02:05 m1keil