Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appending text to a subgroup #4704

Closed
lambertjosh opened this Issue Oct 7, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@lambertjosh
Copy link

lambertjosh commented Oct 7, 2018

It does not appear possible to append text directly to a subgroup, without introducing characters in between.

I have a metric that outputs the exact HTTP return codes, and I'd like to instead view these as their groups. (e.g. 2xx, 4xx, 5xx)

I can do this with some very ugly nested label_replace's:
sum(label_replace(label_replace(label_replace(label_replace(rate(nginx_ingress_controller_requests[2m]), "status_code", "5xx", "status", "5.*"), "status_code", "4xx", "status", "4.*"), "status_code", "3xx", "status", "3.*"), "status_code", "2xx", "status", "2.*")) by (status_code)

But I would much prefer to use a regex subgroup to grab the group code, then append xx onto it. For example:
label_replace(rate(nginx_ingress_controller_requests[2m]), "status_code", "$1xx", "status", "(.)..")

However this has the weird behavior of actually doing nothing. If you put a space or any symbol between $1 and the trailing text, it works, but it would be nice for there to be some method to do this cleanly.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Oct 7, 2018

Try ${1}.

It makes more sense to ask questions like this on the prometheus-users mailing list rather than in a GitHub issue. On the mailing list, more people are available to potentially respond to your question, and the whole community can benefit from the answers provided.

@lambertjosh

This comment has been minimized.

Copy link
Author

lambertjosh commented Oct 12, 2018

Thanks, for anyone searching this does resolve the problem I was having.

@lock lock bot locked and limited conversation to collaborators Apr 10, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.