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
Allow configuration of collector registry used #302
Conversation
Currently, the registry is hard-coded to the default registry. With this change, this would no longer be the case without changing the default behavior where no custom registry is registered.
Can you explain your use case for this? Custom registries are only generally needed for certain advanced forms of exporters, which isn't something you'd write in Spring (or in Java usually for that matter). |
The default registry makes it impossible to refresh a Spring context where all beans are discarded and reinitialized. If this initialization registrers its metrics from beans with fixed names, the refresh will cause a naming conflict. |
That's the expected behaviour, metrics with a given name should only be defined once. I don't see how what you're proposing here helps with that. |
I register the |
That would give incorrect semantics from a metrics standpoint, once a metric is registered it should stay registered until the process terminates. |
This is not a problem. The application goes offline and online, why would the metrics endpoint bother that it is run in the same OS process? The endpoint does not even know about the process. This is just a deployment detail. |
From a prometheus standpoint, that's not a deployment detail that's an important architectural consideration. |
No, it is a testing harness. But neither does it matter. There is no problem on my end here. It should be possible to refresh a Spring context when using Prometheus, that is my argument here. |
This is a dupe of #279. A custom registry is not the right solution here. |
I never said that it is a Spring Boot test. It is a custom testing harness which is starting and stopping services which sometimes are a Spring Boot application. Besides this one Prometheus-Spring-Boot-integration, this does not cause any problems. It is of course your right to reject this PR but this is a valid use case and I offered a solution. Also, if Prometheus offers custom registries, why should the Spring integration not support this at all? |
@brian-brazil Are there any arguments to reject this PR? I have the issue that integration tests reuse the JVM and the static default registry will live across application contexts. The right solution in this case is to specify the registry via dependency injection and require it from elsewhere via dependency injection, not static definition - which is an anti pattern. |
@brian-brazil we recently switched to using this client due to its spring boot integration. When folks who really know what they are doing are told they are doing it wrong, and PRs are rejected which can avoid ugly hacks.. well this behavior without any viable alternative makes me reconsider if it was a wise choice to use this library. If you can, please take a step back and listen.. you have some experts, for example @raphw we do actually know what we are talking about |
@brian-brazil It would be great for users of the library if you could point us in the direction of the way you propose the issue of the static registry should be dealt with. |
Only register a metric once, and then use that metric for the lifetime of the process. |
@brian-brazil Thank you for your reply. I understand that the metric should only be used once under normal circumstances in order to get semantically correct metrics, but in other situations (like the one @raphw is trying to solve) it is a solid blocker that people will have to work around anyway. |
For testing there are methods to clear the registry and remove metrics from it. These are not things that should be exposed to general instrumentation though, as there are many users who misunderstand how a library like this should be used (largely thinking of a different type of library) and which would lead them down the wrong path. |
@brian-brazil Understood, thanks |
So thinking a little: Allowing users to select a custom registry in instrumentation would be incorrect, that's not what that feature is for. However if test setups could somehow under the covers have the normal registration use a custom registry, that'd be fine. |
@brian-brazil Do you have any specific mechanism in mind? A simple (albeit terrible solution) would be to have JUnit 4 Rule that would clear the metrics upon completion of each test. |
I'm not a Spring expert, I don't know what sort of capabilities it has. I'm imagining something that'd cause metrics from annotations to be registered with a custom registry only for test cases. |
@brian-brazil Thanks! |
If it helps anybody: we have migrated everything to Micrometer which offers integration that is compatible to Spring's way of doing things. This is also what the Spring team recommends. No problems eversince. |
Currently, the registry is hard-coded to the default registry. With this change, this would no longer be the case without changing the default behavior where no custom registry is registered.