Question about Service name in metrics

Hello! First Post!

I have a question regarding the reported service name as seen in the metrics. For example:

traefik_service_requests_total{code="200",method="GET",protocol="http",service="xxxx-xxxxxx-traefik-ingress-9d50afc83b446c8a5c01@kubernetescrd"} 1059

My question is as follows: Is there a way to have it show the actual service name the router is forwarding to instead of this generated name?

TIA

I'm sorry, I did not look in depth at metrics, but from common sense:

  • Traefik service is not the same as kubernetes service
  • From you excerpt, it looks like what is being shown is the traefik name
  • It does not look like there is a way to provide the service name in the IngressRoute object for that purpose. The service name is always generated.
  • So as it is now, no, it is not possible

@ldez would you support it if I write a GitHub feature request for this, or do we already have anything similar? It seems a few other options are also missing on IngressRoute, e.g sans for LE certificates, service stickiness, mirroring, etc.

Thanks @zespri for your reply. It would be nice if the name can be defined. This came up when I added Traefik metrics into Prometheus. As I started looking at the data, it was hard to determine which service referred to what. It's easy to tell in the Traefik dashboard since each Traefik service prints out the configured rule, but not outsides that dashboard.

I noticed this open PR if merged, it can resolved the issue.

Awesome thanks for that! I will keep an eye out on that PR.

Hi!
It doesn't look like the PR is solving the problem as I still see this happening in v2.1.2, or am I missing something?

@golgoth

I did not have much experience with metrics, so I cannot definitely tell you if it is resolved or now, it looks like it should. Of course it goes without saying, that you have to update your configuration accordingly, ot take advantage of that PR. If you did not change anything in your configs, that I would expect no change in this behaviour either. Having said that, I have not tried that personally, so I do not have a definite answer.

Are you able to tell us in this thread what you should be changing in the configs to be able to see the correct service names in the metrics ?

Im useing kubernetes and traefik and are having trouble using the metrics for anything at the moment.

@larsbloch I have not tried it but it looks like property name of kind TrafeikService is what you need to set.

Hi, I just stumbled upon this thread since I was also annoyed by the lengthy and cryptic service specifiers. So I tried the method proposed in the PR:

  • I added a TraefikService in addition to the kubernetes service
  • I referred to this service in the ingress definition

This is successful in terms that it removes the hash from the service name. But from what I see at the moment, it always results in two services shown in traefik:

  • a service of type weighted or mirroring -> naming scheme namespace-name
  • at least one service of type loadbalancer -> naming scheme namespace-name-port

So my question is: Is it possible to directly create a TraefikService of type loadbalancer? Since I run only one backend anyway I would like to skip the additional service... But I don't see anything like that in the documentation.

To have some example code:

apiVersion: v1
kind: Service
metadata:
  name: grafana # -> results in namespace-grafana-http-grafana-HASHHASHHASHHASH@kubernetescrd
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-grafana
  selector:
    app: grafana
  sessionAffinity: None
  type: LoadBalancer
---
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
  name: grafana # -> results in namespace-grafana@kubernetescrd service
spec:
  weighted:
    services:
      - name: grafana # -> results in namespace-grafana-3000@kubernetescrd service
        weight: 1
        port: 3000
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: grafana-web-https
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`somedomain.xyz`)
      kind: Rule
      services:
        - name: grafana
          port: 3000
          kind: TraefikService  
  tls:
    secretName: grafana-tls

Just thought id add what i tried, @moritzj29 my case is a service of type nodeport not loadbalancer, but the one part you may have missed is how its defined in the router

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: grafana
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`grafana.some.domain`)
      kind: Rule
      services:
        - name: grafana
          kind: TraefikService

adding this part also resulte in two http services though

but they are called

namespace-grafana-3000@kubernetescrd
namespace-grafana@kubernetescrd

so no hash, and the metrics are only output on namespace-grafana-3000@kubernetescrd which atleast handles the case of matching to the service easier and have no cross contamination of metrics for rollback mesurement

not perfect but does the job