knyar / nginx-lua-prometheus

Prometheus metric library for Nginx written in Lua
MIT License
1.44k stars 230 forks source link

feature request: support OpenMetrics text format and exemplar #143

Open wangrzneu opened 2 years ago

wangrzneu commented 2 years ago

Exemplar can provide a correlation between metrics and traces. https://prometheus.io/docs/instrumenting/exposition_formats/#exemplars-experimental If you think the feature can be accepted, I can work on it.

knyar commented 2 years ago

Thank you for proposing this. This does seem like a useful addition.

In terms of the API, I think inc and observe can accept two additional optional arguments: one with a table for exemplar labels, the second for exemplar timestamp;

counter:inc(value, label_values, {trace_id='d97fc242f0'})
histogram:observe(value, label_values, {}, ngx.now())  -- exemplar with no labels, but a timestamp

In terms of storage, I think we can store exemplar values serialized in the main dictionary, namespaced separately via a reserved key prefix, akin to KEY_INDEX_PREFIX.

Any other design decisions we should discuss before implementing this?

wangrzneu commented 2 years ago

I think a data storage like lua-resty-counter needs to be implemented. The exemplar labels and timestamp will be stored in it. The key have a suffix :exemplar, for example http_count{host="me.com",status="200"}:exemplar, and the value is just like {trace_id="d97fc242f0"},1657556919.