Skip to content

Conversation

loicmathieu
Copy link
Contributor

Remove the dependency between quarkus-smallrye-fault-tolerance and quarkus-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

@loicmathieu
Copy link
Contributor Author

@Ladicek @jmartisk can you review the implementation ?
I'm not proud of the NoopMetricsRegistry but I don't think there is a better way.

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.

@gsmet gsmet added this to the 0.28.0 milestone Oct 29, 2019
@gsmet
Copy link
Member

gsmet commented Oct 29, 2019

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!

@loicmathieu loicmathieu force-pushed the fix/smallrye-metrics-depdendency branch from 5da955c to ab9c779 Compare October 30, 2019 14:08
@loicmathieu loicmathieu changed the title Remove metrics depdendency from fault-tolerance extension Remove metrics dependency from fault-tolerance extension Oct 30, 2019
@gsmet gsmet modified the milestones: 0.28.0, 1+ Oct 30, 2019
@gsmet
Copy link
Member

gsmet commented Oct 30, 2019

Let's not push this in 0.28.0. Please wait.

@loicmathieu loicmathieu force-pushed the fix/smallrye-metrics-depdendency branch from ab9c779 to def4285 Compare November 7, 2019 11:00
@loicmathieu
Copy link
Contributor Author

@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.

@loicmathieu loicmathieu changed the title Remove metrics dependency from fault-tolerance extension WIP - Remove metrics dependency from fault-tolerance extension Nov 12, 2019
@Ladicek
Copy link
Contributor

Ladicek commented Nov 12, 2019

@jmartisk
Copy link
Contributor

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 :(

@Ladicek
Copy link
Contributor

Ladicek commented Nov 12, 2019

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.

@loicmathieu loicmathieu changed the title WIP - Remove metrics dependency from fault-tolerance extension Remove metrics dependency from fault-tolerance extension Nov 12, 2019
@loicmathieu
Copy link
Contributor Author

@jmartisk @Ladicek I add tests for all the annotations of MP fault-tolerance inside quarkus-smallrye-fault-tolerance and all tests works.
As the extension tests uses the no-op impl, it means it works :)

So, is it OK for you guys to merge this ?

Meanwhile I saw that the fault tolerance guide was missing documentation on @Bulkhead and @Asynchronous. Is it worth opening an issue to covers them in the guide ?

@jmartisk
Copy link
Contributor

I just gave this a round of manual experimentation and it worked well for me. So +1

@loicmathieu
Copy link
Contributor Author

@jmartisk if all is OK for you can you approve it ?
@Ladicek is it OK for you also ot is there still some concern about it ?

I'll rebase the PR as there is some conflict

@loicmathieu loicmathieu force-pushed the fix/smallrye-metrics-depdendency branch from 7a58054 to 4f3989a Compare November 19, 2019 10:17

@Test
public void testBulkhead() {
ExecutorService executorService = Executors.newFixedThreadPool(10);
Copy link
Contributor

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?

Copy link
Contributor

@Ladicek Ladicek Nov 19, 2019

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());

Copy link
Contributor Author

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 :)

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

@Ladicek
Copy link
Contributor

Ladicek commented Nov 19, 2019

Two little nitpicks in the tests, otherwise LGTM.

@loicmathieu loicmathieu force-pushed the fix/smallrye-metrics-depdendency branch from 4f3989a to 039d894 Compare November 19, 2019 11:26
@loicmathieu loicmathieu force-pushed the fix/smallrye-metrics-depdendency branch from 039d894 to 7d327b6 Compare November 19, 2019 11:57
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.SECONDS);
assertTrue(success.get());
assertTrue(bulkheadFailures.get());
Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

Copy link
Contributor

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!

@loicmathieu loicmathieu added this to the 1.1.0 milestone Nov 19, 2019
@loicmathieu
Copy link
Contributor Author

@gsmet ready to be merged and needed #5272, can we merge it ?

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"));
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

Copy link
Contributor

@geoand geoand left a 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

@geoand geoand merged commit 3892023 into quarkusio:master Nov 25, 2019
@loicmathieu loicmathieu deleted the fix/smallrye-metrics-depdendency branch November 26, 2019 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quarkus-smallrye-fault-tolerance extension should not have a hard dependency to quarkus-smallrye-metrics

5 participants