micronaut-projects / micronaut-discovery-client

Micronaut's Discovery Client
Apache License 2.0
20 stars 18 forks source link

Issue with resolving environment in consul config #536

Closed atrzcinski closed 2 months ago

atrzcinski commented 10 months ago

Expected Behavior

Using consul config (format: FILE), in ConsulConfigurationClient class the resolveEnvironment method should correctly determine the envName variable allowing it to find the appropriate environment configuration.

Running the application with MICRONAUT_ENVIRONMENTS={ENV_NAME} should result in overwriting the default properties with those from the environment file.

I created the Pull Request #532.

Actual Behaviour

Running the application with MICRONAUT_ENVIRONMENTS={ENV_NAME} with the existing code, the value of the envName variable will never be resolved correctly.

For example: if the name of the configuration file is my-service-prod.yaml (where prod is the name of the environment) and we provide fileName as a parameter (value is my-service-prod) instead of finalName (value is my-service[alpha]), then resolveEnvironment method will not be able to find environment.

The effect is that consul will overwrite the environment configuration with the standard configuration (e.g. my-service.yaml), i.e. the environment configuration will not be considered appropriate. If the same properties will be used, then result of that property will be from standard config file, not file with environment.

Steps To Reproduce

  1. Create standard configuration for service (ex. my-service.yaml (! no application.yml)) with value:
    mongodb:
    uri: mongodb://127.0.0.1:27017/standard
  2. Create configuration with environment (ex. my-service-prod.yml)
    mongodb:
    uri: mongodb://127.0.0.1:27017/prod
  3. Run the application with MICRONAUT_ENVIRONMENTS=prod

The environment will not be considered appropriate. If the same properties will be used, then result will be connecting to db named standard instead of prod.

Environment Information

No response

Example Application

No response

Version

3.8.7 - *

atrzcinski commented 2 months ago

Done by: https://github.com/micronaut-projects/micronaut-discovery-client/pull/532