Skip to content
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

implement MicroProfile Fault Tolerance 3.0 #264

Merged
merged 3 commits into from
Aug 6, 2020
Merged

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Aug 4, 2020

There are 2 big changes in MicroProfile Fault Tolerance 3.0:

  • Lifecycle of stateful fault tolerance strategies is now specified. The specification prescribes the exact behavior SmallRye Fault Tolerance had since the beginning. No implementation required.
  • Metrics have been revamped. This is what this PR implements.

Resolves #185.

Previously, we had the general metrics (invoked/failed) collected
directly in the code that invokes the `CompletionStage`-returning
method. This is now extraced to a `CompletionStageGeneralMetricsRecorder`,
similarly to synchronous and `Future`-returning methods that use
`GeneralMetricsRecorder`.
@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 4, 2020

We'll have to bump a minor or even a major version. At this point, I'm not sure which it should be. Any opinions @michalszynkiewicz @rhusar @radcortez @kenfinnigan?

@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 4, 2020

My personal opinion: from SmallRye Fault Tolerance perspective, the only breaking change we do is metrics. This doesn't sound like 5.0 material to me, so I'd probably lean towards making it 4.4, but I could easily be persuaded otherwise.

@@ -4,55 +4,16 @@

import io.smallrye.faulttolerance.core.FaultToleranceStrategy;

/**
* @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com
Copy link
Contributor

Choose a reason for hiding this comment

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

:(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to do this when I do larger modifications to the classes, such that I'd have to add another author tag for myself. I find them an unnecessary clutter that convey exactly zero information. Your authorship is carefully preserved in Git history :-)

import io.smallrye.faulttolerance.core.InvocationContextEvent;

public class FallbackEvents {
public static class Defined implements InvocationContextEvent {
Copy link
Contributor

@michalszynkiewicz michalszynkiewicz Aug 4, 2020

Choose a reason for hiding this comment

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

why not enum values? Sth like:

public enum FallbackEvents implements InvocationContextEvent {
   DEFINED,
   APPLIED
}

import io.smallrye.faulttolerance.core.InvocationContextEvent;

public class GeneralMetricsEvents {
public static class ExecutionFinished implements InvocationContextEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

again, seems to me that an enum would be a better fit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enum should actually work well here, I'll check.

@michalszynkiewicz
Copy link
Contributor

👍 from me to bump the minor
I hope to finish reviewing tomorrow

Copy link
Contributor

@michalszynkiewicz michalszynkiewicz left a comment

Choose a reason for hiding this comment

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

Sad to see the author tags go, I think in a few places contants can be replaced with enums (the mentioned ones and a few more) but the change looks good to me :)

@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 5, 2020

Good point about enums, for some reason I didn't consider them, I don't know why. I'll try :-)

@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 5, 2020

Ah, I know why -- the event system is very primitive, it keys events by Class objects. If I used an enum, I'd have to have a switch inside the event handler, which would make the code harder to read.

@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 5, 2020

Actually thanks for suggesting enums, I can use the enum-singleton pattern to make the code much shorter.

Even though I can't really use

public enum FallbackEvents {
    DEFINED,
    APPLIED;
}

I can at least use

public class FallbackEvents {
    public enum Defined implements InvocationContextEvent {
        INSTANCE;
    }

    public enum Applied implements InvocationContextEvent {
        INSTANCE;
    }
}

which is much better than the original.

Ladicek added 2 commits August 5, 2020 11:09
…Tolerance 3.0

The metrics system is now completely based on the event system
in `InvocationContext`. All the fault tolerance strategies emit
events on interesting places in the code, and there's a dedicated
fault tolerance strategy that collects metrics based on those events.
This significantly improves source locality, but has some runtime
cost. This should be pretty negligible though. One interesting
optimization is present: if metrics for fault tolerance are disabled,
the dedicated fault tolerance strategy is never added to the chain,
so in this case, the cost of metrics is virtually zero.
@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 5, 2020

Force-pushed because I amended one of the commits with the enum-singleton stuff.

@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 5, 2020

I have manually reran the jobs and they finished successfully. I have no idea why they still show as "waitin for status" here in the PR.

@radcortez
Copy link
Member

Strange. For some reason it seems that the GH Actions didn't picked the new commit hash. Might be a bug. If everything is ok, just squash it in master that they should run.

@Ladicek Ladicek changed the base branch from master to next August 6, 2020 11:53
@Ladicek
Copy link
Contributor Author

Ladicek commented Aug 6, 2020

I've created a next branch so that I can merge my recent changes. They will stay in next at least until MP FT 3.0 is released. Until then, master is for 4.3.x development (there's been recently some bugfixes, so I might actually do a 4.3.1 release).

@Ladicek Ladicek merged commit 11d2cf8 into smallrye:next Aug 6, 2020
@Ladicek Ladicek deleted the mp-ft-3.0 branch August 6, 2020 12:02
@Ladicek Ladicek mentioned this pull request Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rewrite metrics system
3 participants