Search code examples
prometheusgrafanapromql

PromQL/prometheus query label_replace() multiple


Tried to find a way with Prometheus query to replace 2 or more labels, but did not find any good and "short" way of doing it.

here is what I have:

label_replace(
label_replace(
label_replace(
  label_replace(
    rate(spring_integration_send_seconds_count{result!="success", application="MyApplicationName"}[1m])
    ,"service", "$1", "name", "(.*).ConsumerEndpointFactoryBean.*"
    )
      , "service", "$1", "name", "(.*).channel.*"
      )
        , "service", "$1", "name", "(.*).Channel.*"
      )
       , "service", "$1", "name", "(.*).handler.*"
      )
)

Is there a shorter/neater way for replacing labels?

in my example, I have 4 cases where I would like to "skip" the ending, when the end of the label value is:

  • .ConsumerEndpointFactoryBean
  • .channel. (starting with a small letter)
  • .Channel. (starting with capital)
  • .handler.

Solution

  • never mind, it was just a question of the regex

    label_replace(
        rate(spring_integration_send_seconds_count{result!="success", app="MyApplicationName"}[1m])
         ,"service", 
        "$1", 
        "name",   "(.*).(channel|Channel|handler|ConsumerEndpointFactoryBean).*"
        )