Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Feature/AppConfig as PropertySource #652

Open
wants to merge 74 commits into
base: 2.3.x
Choose a base branch
from

Conversation

jarpz
Copy link

@jarpz jarpz commented Sep 7, 2020

Enable to use of AppConfig as PropertySource supporting Yaml & Json content-types.

sixcorners and others added 30 commits August 20, 2019 10:56
Fix AwsSecretsManagerProperties.prefix javadoc
Closes spring-atticgh-529
Fixes spring-atticgh-509
Fixes spring-atticgh-527

Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
…istener.

This commit fixes this issue by delegating exception processing to
AbstractMethodMessageHandler only when there is a configured handler.
If there is none, exception is logged.

Fixes spring-atticgh-394
Closes spring-atticgh-465

Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
Spring Boot 2.4 has moved from providing automatic support for JUnit 4.
For now we must declare it explicitly and in the future migrate to JUnit 5.
@jarpz
Copy link
Author

jarpz commented Sep 15, 2020

just in case there is no need to create another PR. Make sure your new local branch is base on 2.3.x and before to push --force change the base brach in this PR to 2.3.x too

@jarpz jarpz closed this Sep 15, 2020
@jarpz jarpz reopened this Sep 15, 2020
Copy link
Contributor

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

@jarpz thank you! looks amazing! it is almost done :)

spring-cloud-aws-appconfig/pom.xml Outdated Show resolved Hide resolved
spring-cloud-aws-appconfig/pom.xml Outdated Show resolved Hide resolved
@eddumelendez eddumelendez added this to the 2.3 milestone Sep 22, 2020
Copy link
Contributor

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

add few comments in order to improve the code. Also, spring.cloud.aws.appconfig.enabled should be added in spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json. You can take a look into #682

@@ -9,4 +9,5 @@ org.springframework.cloud.aws.autoconfigure.cache.ElastiCacheAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.messaging.SqsAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.messaging.SnsAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration
org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

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

this one should be in another property

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.aws.autoconfigure.appconfig.AwsAppConfigBootstrapConfiguration

assertThat(errors.getAllErrors()).isEmpty();
}

private static class AwsAppConfigPropertiesBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

builder is not needed, objects can be created inside of invalidProperties

"aws.appconfig.environment=dev" };

@Test
void testWithStaticRegion() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be like this

@Test
void testWithStaticRegion() {
	this.contextRunner
			.withPropertyValues("spring.cloud.aws.parameterstore.region:us-east-1")
			.run(context -> {
				AWSSimpleSystemsManagementClient client = context
						.getBean(AWSSimpleSystemsManagementClient.class);
				Object region = ReflectionTestUtils.getField(client, "signingRegion");
				assertThat(region).isEqualTo("us-east-1");
			});
}

@ConditionalOnClass({ AmazonAppConfigAsync.class,
AwsAppConfigPropertySourceLocator.class })
@ConditionalOnProperty(prefix = "aws.appconfig", name = "enabled", matchIfMissing = true)
public class AwsAppConfigBootstrapConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a constructor, similar to this one

public AwsParameterStoreBootstrapConfiguration(ParameterStoreProperties properties,
		ObjectProvider<RegionProvider> regionProvider) {
	this.regionProvider = properties.getRegion() == null
			? regionProvider.getIfAvailable()
			: new StaticRegionProvider(properties.getRegion());
	this.properties = properties;
}


@Bean
@ConditionalOnMissingBean
public AmazonAppConfig appConfigClient(
Copy link
Contributor

Choose a reason for hiding this comment

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

client should look like this

@Bean
@ConditionalOnMissingBean
public AmazonWebserviceClientFactoryBean<AWSSimpleSystemsManagementClient> ssmClient() {
	return new AmazonWebserviceClientFactoryBean<>(
			AWSSimpleSystemsManagementClient.class, null, this.regionProvider);
}

/**
* Configuration prefix.
*/
public static final String CONFIG_PREFIX = "aws.appconfig";
Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove this

/**
* @author jarpz
*/
@ConfigurationProperties(AwsAppConfigProperties.CONFIG_PREFIX)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ConfigurationProperties(prefix = "spring.cloud.aws.appconfig")

@EnableConfigurationProperties(AwsAppConfigProperties.class)
@ConditionalOnClass({ AmazonAppConfigAsync.class,
AwsAppConfigPropertySourceLocator.class })
@ConditionalOnProperty(prefix = "aws.appconfig", name = "enabled", matchIfMissing = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ConditionalOnProperty(prefix = ""spring.cloud.aws.appconfig"", name = "enabled", matchIfMissing = true)

@jarpz jarpz requested a review from eddumelendez September 29, 2020 16:04
@jarpz
Copy link
Author

jarpz commented Oct 4, 2020

add few comments in order to improve the code. Also, spring.cloud.aws.appconfig.enabled should be added in spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json. You can take a look into #682

Hi @eddumelendez , I applied last comments you made. Have you seen them?

@eddumelendez
Copy link
Contributor

@jarpz sorry for the delay and thanks for your patience. The code looks good to me but unfortunately we are still figuring out few things. there are also some prs in progress for new modules related to parameter store and secrets manager and since this is a new one we want to make it right.

The issue is this

@jarpz
Copy link
Author

jarpz commented Oct 19, 2020

@jarpz sorry for the delay and thanks for your patience. The code looks good to me but unfortunately we are still figuring out few things. there are also some prs in progress for new modules related to parameter store and secrets manager and since this is a new one we want to make it right.

The issue is this

I understand. It's ok.

Anything else can I help with?

Regards

@eddumelendez
Copy link
Contributor

I would like to see this one for 2.3 since it has many sources such as s3, ssm document, ssm parameter. The only missing part is adding the support for the new Config Data API with prefix aws-appconfig: from spring-boot 2.4 which is already in progress for Parameter Store #723 and Secrets Manager #721. I can work on this the next days because @jarpz has already done many things already fixing all the comments submitted previously. We can add the module as an experimental module. @maciejwalkowiak wdyt?

@maciejwalkowiak maciejwalkowiak modified the milestones: 2.3, 2.4 Nov 25, 2020
Copy link
Contributor

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

just left questions to understand more now that I have read some docs. Changes are not needed.

@ConfigurationProperties(prefix = "spring.cloud.aws.appconfig")
public class AwsAppConfigProperties implements Validator {

private String accountId;
Copy link
Contributor

@eddumelendez eddumelendez Nov 25, 2020

Choose a reason for hiding this comment

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

this is the client-id right? By reading the docs this would be each instance? Saying that because says unique. So, if I have two VMs then client-id for one should be my-app-1 and the other one my-app-2. Is that right @jarpz ?

I don't think so it would be like that but let me know if I am wrong. I think that here we should use the spring.application.name or application

Copy link
Author

Choose a reason for hiding this comment

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

Hi, well accountId do reference to the was account subscription id, this value es required by aws-sdk. The "application" you means yes is "configurationProfile", We could have 2 VM with same accountId and differents "configurationProfile" names which make reference by the spring.application.name

If you check the class: AwsAppConfigPropertySourceLocator we check for null configurationProfile and use spring.application.name in that case

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
Author

Choose a reason for hiding this comment

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

Sorry, I misunderstand.. "clientId" could be any value.. You are right- but is a required field. I'm gonna to change it

Copy link
Author

@jarpz jarpz Nov 30, 2020

Choose a reason for hiding this comment

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

Sorry, you are right.. we can use a random value for "clientId".. but is required, I'm gonna change it


private String accountId;

private String application;
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be by default the spring.application.name or if the previous one is not defined just application


private String environment;

private String configurationProfile;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not using in the request to the api, why do we need it?

Copy link
Author

@jarpz jarpz Nov 26, 2020

Choose a reason for hiding this comment

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

to create the GetConfigurationRequest we use:

new GetConfigurationRequest()
	.withClientId(accountId) // aws client Id is required.. we can use a random value
         .withApplication(application) // appConfig ApplicationName
	.withConfiguration(name) // configurationProfile or "spring.application.name" when is null *
	.withClientConfigurationVersion(configurationVersion) //last version if null
        .withEnvironment(environment); //environment 

I tried to use the same names which aws app-config use.

Regards

…dom clientId + use first profile name as environment if it is null
@cmboult
Copy link

cmboult commented Nov 5, 2021

Hi, any idea on when this will get released? Have been waiting for something like this for a while!

@github-actions github-actions bot added component: core An issue related to core functionality - credentials, region resolution component: parameter-store Parameter Store integration related issue component: rds RDS integration related issue component: secrets-manager Secrets Manager integration related issue type: dependency-upgrade A dependency upgrade type: documentation A documentation update labels Nov 5, 2021
@khanhcd92
Copy link

Hi, this will get released? Have been waiting for something like this for a while!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: appconfig AppConfig integration related issue component: core An issue related to core functionality - credentials, region resolution component: parameter-store Parameter Store integration related issue component: rds RDS integration related issue component: secrets-manager Secrets Manager integration related issue type: dependency-upgrade A dependency upgrade type: documentation A documentation update type: feature A new feature
Development

Successfully merging this pull request may close these issues.