Allow non-default registry to be used for metrics of SD components#13023
Conversation
|
I'll have a look ASAP. Could you fix the DCO and the lint issues in the meantime? |
f2c25df to
bfeac67
Compare
Thank you! The CI is green now. |
beorn7
left a comment
There was a problem hiding this comment.
Epic work. Thank you very much. I think you can avoid having the separate registration of "shared" metrics by using ConstLabels or WrapRegistererWith. Feel free to ask if you would like to discuss this approach more. Let's try this out before I do the detailed review.
0c04f6a to
8d8894b
Compare
f801b57 to
f50b965
Compare
|
Thank you very much. I hope I'll get to this tomorrow. |
f50b965 to
7f71a10
Compare
|
I'm still trying very hard to get to this. In the meantime, could you address the lint issues? They seem easy to fix. |
2e5c9f8 to
1d48f6a
Compare
Yes, thank you, this is done now. |
beorn7
left a comment
There was a problem hiding this comment.
Very nice. I have just one concern about the "late WithLabelValues calls inside the anonymous functions in the K8s SD. (I think I sent the first comment directly and not part of this review.) If you have done this on purpose and already know that the performance impact doesn't matter, then fine. Otherwise, I would recommend to do the WithLabelValues call once "outside the loop".
And then there is a merge conflict.
But once those two things are addressed, we can finally merge. Thank you very much.
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
This was flagged by the linter. Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
1d48f6a to
5be085c
Compare
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
5be085c to
27bb57a
Compare
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
3d2e1fc to
d2e9970
Compare
|
@beorn7 Thank you for the review! I addressed the issues which you mentioned. Also, the branch is rebased. |
|
|
||
| svcAddCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleAdd) | ||
| svcUpdateCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleUpdate) | ||
| svcDeleteCount := eventCount.WithLabelValues(RoleService.String(), MetricLabelRoleDelete) |
There was a problem hiding this comment.
@beorn7 I thought it'd be nice to define string constants such as "endpoints", "endpointslice", "add", "update", and "delete" only once and use them as constants instead of rewriting the string. I hope you don't mind.
There was a problem hiding this comment.
There are different camps in Prometheus land. Some people argue, if you see a label value in your metrics, you should be able to find it directly in the code with grep. I don't feel strongly, and I understand that string constants are matching most developers' exceptions much better.
beorn7
left a comment
There was a problem hiding this comment.
Thank you very much. Epic work.
|
NOTE: It seems this PR might have broke something: #13312 |
This PR makes it possible to register metrics of SD components using a registry other than the global one. This is going to be very useful for applications such as Grafana Agent which import Prometheus SDs from the Prometheus repo and instantiate more than one SD per process.
This PR is a follow-up from #12565. This PR does for SD mechanisms what #12958 does for the "scrape" package.
Note that the Kubernetes SD mechanism registers metrics from the Go k8s client. Those metrics are per process and not per SD instance, so I moved them outside of the SD mechanism. They are now registered when the SD Manager metrics are registered, once per process.
Also note that since we register the metrics during the Run() function, we are not able to use the metrics during the SD creation because the Run() function hasn't ran yet. I believe this will not be a problem.
I successfully tested the change locally:
file_sd_configsandkubernetes_sd_configs. I see all the k8s metrics and file SD metrics whenever those SDs are enabled in the config.--enable-feature=new-service-discovery-managercmd option and without. In both cases I get the same metrics.pkill -SIGHUP -i prometheuscommand. This worked ok, Prometheus reloaded the config and kept running, and the same metrics were visible.I did not test promtool.