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

Allow AtomixCluster to be autowired everywhere #10354

Merged
merged 7 commits into from
Sep 15, 2022

Conversation

npepinpe
Copy link
Member

@npepinpe npepinpe commented Sep 14, 2022

Description

This PR extracts building the AtomixCluster from the broker into the dist module. Unfortunately, because many of our testing utilities break all kinds of abstraction, and our tests still heavily rely on modifying the cluster via the BrokerCfg, mapping the BrokerCfg to the AtomixCluster is still done in the broker module. However, everything is prepared to eventually move this out to the dist module itself, such that our configuration would simply instantiate the Atomix ClusterConfig type, and later inject a AtomixCluster in the broker. See the StandaloneGateway as an example; there is plenty of opportunity to DRY it up once both are simply configuring ClusterConfig directly, and it will remove intermediate layers of builders/config.

In order to achieve that at the moment, since the network configuration relies on being initialized with the right broker base path, I also had to pull up the working directory into its own configuration, such that it can be autowired as well. This is a little more abstraction than I'd like, but it's due to how the BrokerCfg is still the central point for all the components, even those not specific to the broker.

The broker configuration is thus not initialized in the system context or broker anymore, but is given to the broker already initialized. This is done via the Spring configuration BrokerConfiguration. It uses two beans to do this, which I dislike, but I'm not sure what's the best way to do this. I generally dislike that the configuration must be initialized anyway, it's very brittle and easy to forget, so I'd rather figure a way to avoid this in the future. I would propose a follow up which removes this, and instead enforces that we create the broker config either passing the base already, or using a factory method which does this. I can also do it here, but it will increase how much changes are here.

I think in the future the cluster services should be started before the broker itself, but we can figure this out later. For now, it means that if the actuator wants to make use of them before the broker finishes starting, it will fail - this is something we can handle semi-gracefully, so I would leave it as is.

Related issues

related to #9996

Definition of Done

Not all items need to be done depending on the issue and the pull request.

Code changes:

  • The changes are backwards compatibility with previous versions
  • If it fixes a bug then PRs are created to backport the fix to the last two minor versions. You can trigger a backport by assigning labels (e.g. backport stable/1.3) to the PR, in case that fails you need to create backports manually.

Testing:

  • There are unit/integration tests that verify all acceptance criterias of the issue
  • New tests are written to ensure backwards compatibility with further versions
  • The behavior is tested manually
  • The change has been verified by a QA run
  • The impact of the changes is verified by a benchmark

Documentation:

  • The documentation is updated (e.g. BPMN reference, configuration, examples, get-started guides, etc.)
  • New content is added to the release announcement
  • If the PR changes how BPMN processes are validated (e.g. support new BPMN element) then the Camunda modeling team should be informed to adjust the BPMN linting.

Please refer to our review guidelines.

Instead of having multiple Atomix factories, it makes more sense to
simply eschew going through layers of intermediate configuration classes
and builders, and simply have each application map its configuration to
the general Atomix `ClusterConfig`, from which we can create a cluster
easily. This will greatly simplify injecting the cluster in the broker
later on.
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;

final class WorkingDirectoryConfigurationTest {

Check notice

Code scanning / CodeQL

Unused classes and interfaces

Unused class: WorkingDirectoryConfigurationTest is not referenced within this codebase. If not used as an external API it should be removed.
@github-actions
Copy link
Contributor

github-actions bot commented Sep 14, 2022

Test Results

   858 files   -     1     858 suites   - 1   1h 47m 38s ⏱️ + 4m 42s
6 600 tests  - 112  6 589 ✔️  - 112  11 💤 ±0  0 ±0 
6 784 runs   - 112  6 773 ✔️  - 112  11 💤 ±0  0 ±0 

Results for commit 870286d. ± Comparison against base commit 10e56dc.

♻️ This comment has been updated with latest results.

@npepinpe
Copy link
Member Author

Super cool, since the SystemContext is in charge of initializing the configuration in tests, most tests fail to build a cluster (since we want to inject the cluster).

Copy link
Contributor

@deepthidevaki deepthidevaki left a comment

Choose a reason for hiding this comment

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

Great 🚀 That was a lot of changes, but in the good direction. Thanks.

@npepinpe
Copy link
Member Author

Yes, sorry, this was much more changes than I wanted, and I had to find a balance between fully moving everything shared between broker/gateway to dist and not creating too much work. At the same time, it highlighted that if we will do more with Spring, we may want to learn more about how it works 😄

Resolve the working directory via configuration, as it will be required
to initialize the messaging configuration for `AtomixCluster` down the
line.
Refactors to allow the cluster services to be created outside of the
broker, and injected directly, though not yet started. This reduces the
cluster step to just starting the cluster.

To simplify testing, temporary factories are added, mostly because many
tests expect to be able to modify the cluster services by modifying the
`BrokerCfg`. Most of `ClusterConfigFactory` should be transferable to
the `dist` module once this is not true anymore.
@npepinpe
Copy link
Member Author

bors merge

@zeebe-bors-camunda
Copy link
Contributor

Build succeeded:

@zeebe-bors-camunda zeebe-bors-camunda bot merged commit 9f3dd7c into main Sep 15, 2022
@zeebe-bors-camunda zeebe-bors-camunda bot deleted the 9996-atomix-cluster branch September 15, 2022 13:12
zeebe-bors-camunda bot added a commit that referenced this pull request Sep 15, 2022
10357: Allow reuse of shared actuators depending on BrokerClient r=npepinpe a=npepinpe

## Description

This PR provides the last remaining bit to #9996 by having each application provide a `BrokerClient` bean, allowing us to create shared actuators which do not need any bridge. To showcase, the `RebalancingService` was collapsed into a single class.

## Related issues

closes #9996 
depends on #10354 



Co-authored-by: Nicolas Pepin-Perreault <nicolas.pepin-perreault@camunda.com>
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.

None yet

2 participants