Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport for multiple ports in annotations #3756
Comments
This comment has been minimized.
This comment has been minimized.
|
This is really a feature request for Kubernetes to have per-port labels/annotations, we can only work off the metadata that k8 provides to us. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the fast answer, perhaps i'm saying nonsense but it wouldn't be possible to have an annotation like prometheus.io/ports: "9101,9102" in prural? |
This comment has been minimized.
This comment has been minimized.
|
Of course you can have such an annotation, Kubernetes permits it. |
This comment has been minimized.
This comment has been minimized.
|
@brian-brazil you're not being helpful here. Per-port annotations are one way to make this possible, a more expressive relabelling language would be another. You don't want the latter, so you're just pushing for the former, which is not going to happen either because fundamentally ports are not annotatable objects and never will be. @vaijira There is a way to do this already, but it comes with some caveats. Because of the deliberately limited relabelling language, you cannot support an arbitrary number of ports, but you can support ports up to some limit of your choice (up to 3 ports, up to 10 ports, any number you choose). The way you can do this is to have one job definition for each of the possible positions of ports in the list, and then for example for the 2nd port match something like The other consequence is higher load on the Kubernetes API, because Prometheus will open a separate connection and watch for each job description (there is an issue for avoiding that somewhere). For this reason, we default to supporting 1 port only, and raise this limit only for the few apps that actually need more than one. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
One other alternative is to key SD off of port names - for instance, we only scrape pod ports who's name ends with |
This comment has been minimized.
This comment has been minimized.
josdotso
commented
Mar 31, 2018
|
@tomwilkie This approach is brilliant. Thanks! Defined as a second pod job to what is at kubernetes/charts, with some tweaks, I was able to achieve multi-port scrapes without annotations. The port name suffix I'm using is |
josdotso
referenced this issue
Apr 11, 2018
Merged
[incubator/zookeeper] v1.0: Revamp, add exporters, add chroots job #4931
This comment has been minimized.
This comment has been minimized.
|
Yea, we use port naming as an indicator what port should be scraped for pod, but it is limited:
It's fine for us for now, but can cause some troubles if you don't have any way to change metric_path on which metrics are exposed for both containers within pod. Started some discussion here: https://groups.google.com/forum/#!topic/prometheus-users/ihMUWtX477Q Sorry I missed this issue here, my topic is kind of duplicate. |
This comment has been minimized.
This comment has been minimized.
|
There is another, more verbose explanation of solution mentioned in begginning (from google group's topic):
|
This comment has been minimized.
This comment has been minimized.
|
How crazy would be to extend relabelling to add some kind of conditional logic? For example:
That would solve this issue immidiately and will allow for more flexibility for different providers. Any thoughts? So then you can have annotations like:
|
This comment has been minimized.
This comment has been minimized.
|
Not tested but I think another alternative is using a service for each port and use the annotations there. But I'd also happy if we had a one-to-n mapping in relabeling. |
This comment has been minimized.
This comment has been minimized.
|
So.. again, there is no good solution here. Other option and it seems recommended & ultimate way is to do CRD based scrape configuration, which quite neat and insane in the same time. This is exactly what Prometheus Operator does here, however I am not necessarily like sticking to I wonder if the better way would be to allow pointing to pods directly. I might be missing some important discussion that lead to decision for Endpoints. If I am not wrong, Endpoints are created only by Service that has some selectors, otherwise you need to create those manually. Selecting pods would need probably need some even more magic scrape configuration. Anyway, all of this unfortunately involves using some kind of operator, like Prom Operator itself. Since there is no custom resource definition API in scrape Kubernetes discovery (why?), the only solution is genertaing Prometheus configuration on the fly, based on CRDs from KubeAPI and reload it in runtime to given Prometheus. It's quite insane ! Also kudos to Prometheus Operator maintainers for implementing this and delivering so well. All of this would be not needed if the scrape configuration would be improved in Prometheus itself ): |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@discordianfish You are missing important thing here. Prometheus discovers Pod's ports not just pods. However because of:
.. Prometheus discovery gives false impression of just one target/port per pod, as annotation happend to be (accidently) a popular pattern. There is ongoing discussion for years how to resolve this in easiest way and I think we should start maintain some table of potential solutions and their pros/cons ;p |
This comment has been minimized.
This comment has been minimized.
|
Added some table of existing solutions for starting point: https://docs.google.com/document/d/1S6O1czHtjR2DGfK2zeZDLr88wxyLRXB2JpH5g7YM1J8/edit?usp=sharing |
This comment has been minimized.
This comment has been minimized.
pbenefice
commented
Apr 16, 2019
•
|
Hi, I'm also facing the need to scrape two container within a single pod and gave a shot at the "Multiple Pod annotations" solution within the google doc I though I'd share my issues :
|
This comment has been minimized.
This comment has been minimized.
pbenefice
commented
Apr 16, 2019
|
Hi @bwplotka, (related to my comment just above) I don't know if this idea is similar to the
The idea here would be : "If the port defined within the annotations match the port of the pod discovered : keep the target, otherwise drop it" |
This comment has been minimized.
This comment has been minimized.
Why? If you target address you will get two targets per JOB (if you have single Pod with only 2 containers). Since the address is exactly the same K8s service will use just one.
Yes! You have couple of options, I will add them to the doc. Also please comment there.
|
This comment has been minimized.
This comment has been minimized.
|
Your second idea is kind of |
This comment has been minimized.
This comment has been minimized.
pbenefice
commented
Apr 16, 2019
I did'nt expect that quick of answer, but yeah, I know it's not possible, I was just saying this feature would solve my case, as the Port Annotations from kubernetes would solve it, but I understand it's not available. (for now ? |
vaijira commentedJan 29, 2018
The use case is if you have for example several containers in a pod, currently with the port annotation it seems you can only specify one port. The only way i see to scrape several ports is removing the port annotation, the problem is that ports that i dont wanna get scraped are scraped.