-
Notifications
You must be signed in to change notification settings - Fork 3k
Remove metrics dependency from fault-tolerance extension #4987
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
Remove metrics dependency from fault-tolerance extension #4987
Conversation
97e827a
to
5da955c
Compare
@Ladicek @jmartisk can you review the implementation ? Also the way I switch off metrics for smallrye-fault-tolerance is via a startup event listening methods, I don't know if there is a better way to do this. @gsmet I added the noteworthy label as with this PR quarkus-smallrye-metrics will no longuer be integrated when we add quarkus-smallrye-fault-tolerance. If some people rely of it they could be surprised. |
I'm cancelling CI for now, we need CI resources for other PRs. Sorry about that. Please do not force push until tomorrow afternoon to avoid CI load. Thanks! |
...ployment/src/main/java/io/quarkus/smallrye/faulttolerance/deployment/NoopMetricRegistry.java
Outdated
Show resolved
Hide resolved
5da955c
to
ab9c779
Compare
Let's not push this in 0.28.0. Please wait. |
...eployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsProcessor.java
Outdated
Show resolved
Hide resolved
ab9c779
to
def4285
Compare
@jmartisk raises concern that this implementation should fails on https://github.com/smallrye/smallrye-fault-tolerance/blob/2.1.2/implementation/src/main/java/io/smallrye/faulttolerance/metrics/BulkheadWaitRecorder.java#L55 As there is not a lot of tests inside Quarkus for fault-tolerence, I will add new ones so we will be able to decide if the implementation is OK or not. |
I don't think it should fail, because that code can only be reached when metrics are enabled. See https://github.com/smallrye/smallrye-fault-tolerance/blob/2.1.2/implementation/src/main/java/io/smallrye/faulttolerance/HystrixCommandInterceptor.java#L202-L209 |
Hmm, perhaps this case will work, but we need to really check that SmallRye FT doesn't do anything that will break if we have the no-op registry trick in place, and fix any cases where it could break.. This trick is not a general purpose solution :( |
I don't think it's a trick. I certainly don't want to introduce metrics abstraction in SmallRye FT just to make Metrics optional. MP Metrics is that abstraction. That said, it's probably true that the SmallRye FT code was written with the assumption that an implementation of MP Metrics is always present (and we need to do better with the reimplementation). I think I checked the SmallRye FT codebase when this issue was raised and I believe this approach should work well. I'll also gladly accept any PR in SmallRye FT that would help with this. |
@jmartisk @Ladicek I add tests for all the annotations of MP fault-tolerance inside quarkus-smallrye-fault-tolerance and all tests works. So, is it OK for you guys to merge this ? Meanwhile I saw that the fault tolerance guide was missing documentation on |
I just gave this a round of manual experimentation and it worked well for me. So +1 |
7a58054
to
4f3989a
Compare
|
||
@Test | ||
public void testBulkhead() { | ||
ExecutorService executorService = Executors.newFixedThreadPool(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps shutdown()
the executor service at the end of the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the asserts here happen on different threads, so they don't really count (at least that's how JUnit 4 behaves; I don't know about JUnit 5, but I'd expect the same). Probably easiest would be something like this (writing from memory, some tweaks might be necessary, but the general idea should be clear):
AtomicInteger success = new AtomicInteger();
ExecutorService executorService = Executors.newFixedThreadPool(10);
for (int i = 0; i < 20; i++) {
executorService.submit(() -> {
int bulk = bulkhead.bulkhead();
if (bulk <= 5) {
success.incrementAndGet();
}
});
}
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.SECOND);
assertEquals(20, success.get());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions are done on the same thread (I check the code) so my impl is correct. I assert 20 times that the bulk is less or equals to 5 and it's pretty the same as you code but with an AtomicInteger to count. I prefere mine as it carry the intent better.
I added the closing of the executorService, thanks for pointing this to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the assertTrue
call is in the lambda that you pass to executorService.submit
-- unless I'm seriously mistaken, that means the assert will happen on the thread from the executor thread pool, not on the main thread on which the test runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ladicek you're right, the assert exception is thrown inside the task and ignored ...
But Bulkhead also throws an exception when too many parallel queries run so the test should assert that an exception was thrown or that bulkhead was never more than five.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the new test implementation OK ?
...src/test/java/io/quarkus/smallrye/faulttolerance/test/circuitbreaker/CircuitBreakerBean.java
Outdated
Show resolved
Hide resolved
Two little nitpicks in the tests, otherwise LGTM. |
4f3989a
to
039d894
Compare
039d894
to
7d327b6
Compare
executorService.shutdown(); | ||
executorService.awaitTermination(5, TimeUnit.SECONDS); | ||
assertTrue(success.get()); | ||
assertTrue(bulkheadFailures.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be assertFalse
?
Otherwise it looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this proove that Bulkhead works by checking that a BulkheadException
has been thrown at least once.
I hope that this test will always succeed but as it's a concurency test it can be possible to have some times false negative, maybe I should add a comment on this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ah, true, true, thanks!
if (!capabilities.isCapabilityPresent(Capabilities.METRICS)) { | ||
//disable fault tolerance metrics with the MP sys props and provides a No-op metric registry. | ||
additionalBean.produce(new AdditionalBeanBuildItem(NoopMetricRegistry.class)); | ||
systemProperty.produce(new SystemPropertyBuildItem("MP_Fault_Tolerance_Metrics_Enabled", "false")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this property necessary? I don't see it being used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a configuration option specified by MicroProfile Fault Tolerance to switch off metrics collection. SmallRye Fault Tolerance reads it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and more importantly it's been verified by the experts
Remove the dependency between
quarkus-smallrye-fault-tolerance
andquarkus-smallrye-metics
.With this PR, the metrics extension will no longuer be included when the fault-tolerance extension is used.
The fault-tolerance extension now have a dependency to microprofile-fault-tolerance instead and provides a NOOP MetricsRegistry when the metrics extension is not present.
This fixes #4857