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

Problem when including spring profiles with logical operators #16303

Closed
bondj opened this issue Mar 25, 2019 · 4 comments
Closed

Problem when including spring profiles with logical operators #16303

bondj opened this issue Mar 25, 2019 · 4 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@bondj
Copy link

bondj commented Mar 25, 2019

Spring Boot v2.1.3.RELEASE

I have an application.yml where I want to include profiles based on logical conditions on what profiles are active. I've attached my application.yml

---
spring.profiles: a & b
spring:
  profiles:
    include:
      - includeAandB
mypropAandB: valueAandB

---
spring.profiles: a
spring:
  profiles:
    include:
      - includeA
mypropA: valueA
---
spring.profiles: b
spring:
  profiles:
    include:
      - includeB
mypropB: valueB

---
spring.profiles: c
spring:
  profiles:
    include:
      - includeC
mypropC: valueC

When I run

SPRING_PROFILES_ACTIVE=a,b ./gradlew bootRun

I get

The following profiles are active: a,includeA,b,includeB

This seems inconsistent, I was expecting a,includeA,b,includeB,includeAandB or possible a,b if the includes were not supported.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 25, 2019
@mbhave
Copy link
Contributor

mbhave commented Mar 26, 2019

Profile expressions (and negated profiles) get processed last, i.e. once we already know the profiles activated and included by the config files. If the YAML document that's activated by a profile expression itself contains a spring.profiles.include, that doesn't get processed at the moment.

We'd have to go over the config files again to look for documents matching the profiles included by the expression. Let's see if the rest of the team thinks this is something we should fix.

@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Mar 26, 2019
@mbhave
Copy link
Contributor

mbhave commented Mar 27, 2019

Based on the complexity of the fix we can decide whether it should go in 2.1.x or 2.2.x.

@mbhave mbhave added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2019
@mbhave mbhave added this to the 2.1.x milestone Mar 27, 2019
@mbhave mbhave self-assigned this Mar 27, 2019
@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Apr 5, 2019
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Apr 5, 2019
@mbhave
Copy link
Contributor

mbhave commented Apr 5, 2019

I have a fix for this here but this is turning out to get a bit complicated because of the way included profiles are supposed to be ordered. For example, look at the configuration below:

spring.profiles: a
spring.profiles.include: c
---
spring.profiles: a & b
spring.profiles.include: d,e
---
spring.profiles: d
spring.profiles.include: f
---

Given that profiles a and b are active, the above configuration will lead to a profile order of a, c, b, d, e, f, whereas one might expect it to be a, c, b, d, f, e. There are a lot of corner cases when it comes to profiles specific files/YAML documents and include profiles. We need to take a step back and redefine the rules, which will lead to a possible overhaul of this part of the code. We can tackle this in 2.3.x once we have a better idea of what it should look like.

@mbhave mbhave modified the milestones: 2.1.x, 2.x Apr 5, 2019
@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Jul 31, 2020
@philwebb philwebb modified the milestones: 2.x, 2.4.x Jul 31, 2020
@philwebb philwebb self-assigned this Jul 31, 2020
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jul 31, 2020
@mbhave mbhave added theme: config-data Issues related to the configuration theme and removed theme: profiles labels Aug 5, 2020
@philwebb
Copy link
Member

Spring Boot 2.4 has overhauled config processing. See this blog post for details. Since the spring.profiles.include property won't be supported going forward you'll need to find a different way to do what you want.

I would suggest using @Profile("a & b") directly in your code or adding an EnvironmentPostProcessor to set new profiles based on the existing ones.

I'm going to close this one for now, but if you find there's an obvious use-case that we're missing from the new code then please comment back here and we can have another look. We'll need a bit more background about what's driving the need for the includeAandB profile in the first place.

@philwebb philwebb added status: declined A suggestion or change that we don't feel we should currently apply and removed theme: config-data Issues related to the configuration theme type: bug A general bug labels Oct 23, 2020
@philwebb philwebb removed this from the 2.4.x milestone Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants