prometheus / consul_exporter

Exporter for Consul metrics
Apache License 2.0
437 stars 167 forks source link

Exposing consul service instance meta data #196

Open m1keil opened 3 years ago

m1keil commented 3 years ago

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?

simonpasquier commented 3 years ago

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

m1keil commented 3 years ago

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 consulexporter 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
simonpasquier commented 3 years ago

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

m1keil commented 3 years ago

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?

simonpasquier commented 3 years ago

sure go for it :)

m1keil commented 3 years ago

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.

rfelgent commented 3 years ago

Hi @m1keil ,

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

m1keil commented 3 years ago

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

roidelapluie commented 3 years ago

I will look at this in the coming days.

m1keil commented 3 years ago

no worries @roidelapluie, cheers!