Per-ingress request metrics
Welcome!
- Yes, I've searched similar issues on GitHub and didn't find any.
- Yes, I've searched similar issues on the Traefik community forum and didn't find any.
What did you expect to see?
Traefik supports Kubernetes Ingress objects through its kubernetes provider and its kubernetesingressnginx provider. As far as I understand, traefik generates routers for each ingress rule and path. There are metrics for endpoints, routers and services, but no metrics for ingresses out of the box.
I've tried to generate aggregates using recording rules in Prometheus, but that won't reliably work, as far as I can tell, at least for the kubernetes case.
So my feature request is to either:
- Provide a traefik_ingress_request* metric set out of the box, or
- Improve generated router naming to make it truly parseable, or
- Add more labels to existing metrics for clearer matching
I note that the access log actually does contain ingress name. I can then theoretically query the logs to produce ingress metrics, but this seems roundabout, when traefik produces metrics in general. As the log contains this, it looks like there is connective tissue somewhere. This is comparable to ingress-nginx, although I recognize that this application is a pure ingress controller.
I'm basing my work on the ingress metrics in kube-state-metrics, which gives me metrics kube_ingress_info, _paths, _labels and _annotations.
Router naming:
The kubernetesingressnginx provider (ingressClassName: nginx) seems to generate router names of the form:
{namespace}-{ingress}-rule-{index}-path-{index}[-tls]@{provider}For the kubernetes provider (ingressClassName: traefik):
{entrypoint}-{namespace}-{ingress}-{hostname}[-{rule-index}]@{provider}Each of namespace, ingress, entrypoint can natively contain dashes. The hostname part has dots replaced with dashes making regex matching tricky.
I don't care about rules or paths when aggregating on ingress, so I can generate a full regex match given an ingress name and namespace for the kubernetesingressnginx case. Arguably, it'd be nice to have metrics on the rule/path level too, but that's secondary.
I've been wracking my brain to produce a regex that can do label matching and joining for the kubernetes case, but they have to be greedy somewhere to produce a match and replacement. If I can produce a dotted-hostname to dashed-hostname mapping in my metrics pipeline, I could make it work, but it gets awkward.
Suggestions:
- Align the router naming between
kubernetesandkubernetesingressnginx, preferably to the nginx variant. - Use something else than dashes as the component separator
Labeling
As far as I can tell, there is no entrypoint or (dotted or dashed) hostname label on the traefik_router_request* metrics. I guess providing a hostname label doesn't quite fit the non-ingress case for routers.
The naming implies one router is only attached to one entrypoint. As such, it'd be nice with an entrypoint label, but I guess the problem is that a Traefik router could be attached to multiple entrypoints outside of the ingress case. Decomposing router and entrypoint attachments in metrics would be good here. Providing "info" gauge metrics like kube-state-metrics does would also be useful for joining in general.
This is just patching to make label matching easier though. A better solution is to provide ingress metrics natively out of the box.
Source: traefik/traefik