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

Development: POC for improving Spring configuration via properties/profiles #10336

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

ole-ve
Copy link
Contributor

@ole-ve ole-ve commented Feb 15, 2025

This PR acts as a POC outlining approaches on how to improve the Spring configuration.

Identified Problems:

  1. Properties override are implicitly defined by the order of the profiles in the run config
  2. Opt-out (default config is enabled) is not possible
  3. Configuration for ADMIN- and USER-visible functionality are mixed across the config files

Proposed Solutions:

  1. Don't (fully) rely on Spring Profiles, but rather evaluate conditions on (Spring) properties.
  2. For "simpler" overrides (VCS or CI):
  • Provide admins with a set of "application.yml"-files for the respective functionality (Jenkins, Gitlab, etc.)
  • Admins have to copy-paste those values into the application.yml-file they place next to the packaged JAR before starting Artemis (passing via env-vars is also supported
  1. For complex conditions: Instead of relying on overrides from other application.yml in a specific order, create/update/delete properties from the Spring Environment before Context Initialization (i.e., before dependency injection)
  2. Guiding users with good documentation and (tested) config-examples to separate admin and user-visible config

See here for more details. If you don't have access, feel free to reach out to me.

@ole-ve ole-ve self-assigned this Feb 15, 2025
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) config-change Pull requests that change the config in a way that they require a deployment via Ansible. athena Pull requests that affect the corresponding module buildagent Pull requests that affect the corresponding module core Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module labels Feb 15, 2025
@@ -0,0 +1,10 @@
artemis:
athena:
enabled: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this files is placed next to the packaged JAR and overrides the default config from application.yml-files within the packaged JAR

version-control:
url: https://gitlab.artemis.cit.tum.de # assuming we are using GitLab and have a different URL (than localVC as default)

info:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

room for user-configs, explained in documentation

Comment on lines +68 to +69
new ConfigValidationPostProcessor().attachTo(app);
new PropertyOverridePostProcessor().attachTo(app);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

registers listener after environment has been created, but before context initialization (beans etc.)

@@ -16,7 +14,7 @@
import org.springframework.stereotype.Component;

@Component
@Profile(PROFILE_ATHENA)
@ConditionalOnBean(AthenaConfiguration.class)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of relying on the profile, we rely on the existence of the AthenaConfiguration (which checks the environment)

/**
* This class is necessary to avoid using Jersey (which has an issue deserializing Eureka responses) after the spring boot upgrade.
* It provides the RestClientTransportClientFactories and RestClientDiscoveryClientOptionalArgs that would normally not be instantiated
* when Jersey is found by Eureka.
*/
@Profile({ PROFILE_CORE, PROFILE_BUILDAGENT })
@Conditional(BuildAgentOrCoreCondition.class)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an interesting case: If we want to define more complex conditions based on profile AND/OR properties, we can do that with nested properties like BuildAgentOrCoreCondition

* This bridges the gap between the condition classes and the actual property values.
* WIP: make methods non-static
*/
public class ArtemisConfigHelper {
Copy link
Contributor Author

@ole-ve ole-ve Feb 15, 2025

Choose a reason for hiding this comment

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

We might want to discuss whether we directly use this class in the respective Conditions or if we want to create a new layer of abstraction for when using from within the initialized spring context. (like ArtemisConfigServer with @service)

A reason could be to decouple application-logic from reading the properties and profiles. So we could also mock it and in general, have a clearer separation of concerns

@@ -117,7 +118,9 @@ artemis:
short-name: "artemis-build-agent-1"
display-name: "Artemis Build Agent 1"


version-control:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When removing the buildagent profile/yaml, we need to set those as defaults here

@@ -87,6 +87,7 @@ artemis:
name: Artemis
email: artemis@xcit.tum.de
athena:
enabled: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

default is that athena is enabled, opt-out instead of opt-in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
athena Pull requests that affect the corresponding module buildagent Pull requests that affect the corresponding module config-change Pull requests that change the config in a way that they require a deployment via Ansible. core Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module server Pull requests that update Java code. (Added Automatically!) tests
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

1 participant