You can do this by first using `label_replace` to create a new(!) label with the path prefix. Something like
count by(host) (label_replace(up, "host", "$1", "instance", > "([^:]+)(:[0-9]+)")) > link <https://prometheus.demo.do.prometheus.io/graph?g0.expr=label_replace(up%2C%20%22host%22%2C%20%22%241%22%2C%20%22instance%22%2C%20%22(%5B%5E%3A%5D%2B)(%3A%5B0-9%5D%2B)%22)&g0.tab=1&g0.stacked=0&g0.range_input=1h&g1.expr=count%20by(host)%20(label_replace(up%2C%20%22host%22%2C%20%22%241%22%2C%20%22instance%22%2C%20%22(%5B%5E%3A%5D%2B)(%3A%5B0-9%5D%2B)%22))&g1.tab=1&g1.stacked=0&g1.range_input=1h> However keep in mind that you are still incurring the storage cost of all these raw metrics. It *may* be worthwhile to fix this further up the chain in the app that exposes this data to begin with. /Matthias On Fri, Sep 29, 2023 at 1:16 PM [email protected] <[email protected]> wrote: > Hello, > > I have a question and could not get my head around it. may be if someone > can help. > > I have a recording rule the records rate of api requests for last 5 > minutes. But there are some api requests for which I want the api path to > be stripped only with the first two levels. > > for example: > /test/download/12345 and /test/download/56789 , both these should be > stripped to /test/download and the last part to be removed in the labels. > As the last part is dynamic, i want the recording rules to record only the > first two levels i.e /test/download as label value. > > Thanks in advance > > > > -- > You received this message because you are subscribed to the Google Groups > "Prometheus Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/prometheus-users/ef84f03a-0f37-4ac2-adac-5a6b42e4bb34n%40googlegroups.com > <https://groups.google.com/d/msgid/prometheus-users/ef84f03a-0f37-4ac2-adac-5a6b42e4bb34n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAMV%3D_gaDSjwU9T_-WbFaetT7Gam32hChPZB3a0yeS%3DOxzhfqag%40mail.gmail.com.

