Skip to content

Commit

Permalink
Create custom CloudWatchMetricPublishers for SecretsManager and Param…
Browse files Browse the repository at this point in the history
…eterStore
  • Loading branch information
krimsz committed May 8, 2022
1 parent 5b77aab commit cfc6064
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package io.awspring.cloud.autoconfigure.config;

import io.awspring.cloud.autoconfigure.AwsClientProperties;
import io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStorePropertySources;
import io.awspring.cloud.autoconfigure.core.AwsProperties;
import io.awspring.cloud.autoconfigure.core.CredentialsProperties;
import io.awspring.cloud.autoconfigure.core.CredentialsProviderAutoConfiguration;
import io.awspring.cloud.autoconfigure.core.RegionProperties;
import io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration;
import io.awspring.cloud.core.SpringCloudClientConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.ConfigurableBootstrapContext;
Expand Down Expand Up @@ -160,7 +163,7 @@ else if (awsProperties.getEndpoint() != null) {
Optional<MetricPublisher> metricPublisher;
try {
Class.forName("software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher");
metricPublisher = Optional.of(context.get(CloudWatchMetricPublisher.class));
metricPublisher = Optional.of(context.get(MetricPublisher.class));
}
catch (IllegalStateException | ClassNotFoundException e) {
metricPublisher = Optional.empty();
Expand All @@ -176,4 +179,15 @@ else if (awsProperties.getEndpoint() != null) {
return builder;
}

protected void createMetricPublisher(ConfigDataLocationResolverContext resolverContext) {
try {
Class.forName("software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher");
}
catch (IllegalStateException | ClassNotFoundException ignored) {
// ignored, means that the optional dependency is not in the classpath
return;
}
registerBean(resolverContext, MetricPublisher.class, CloudWatchMetricPublisher.builder().build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<ParameterStoreConfigDataResource> resolveProfileSpecific(
registerBean(resolverContext, CredentialsProperties.class,
loadCredentialsProperties(resolverContext.getBinder()));
registerBean(resolverContext, RegionProperties.class, loadRegionProperties(resolverContext.getBinder()));

createMetricPublisher(resolverContext);
registerAndPromoteBean(resolverContext, SsmClient.class, this::createSimpleSystemManagementClient);

ParameterStorePropertySources sources = new ParameterStorePropertySources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ public List<SecretsManagerConfigDataResource> resolveProfileSpecific(
registerBean(resolverContext, CredentialsProperties.class,
loadCredentialsProperties(resolverContext.getBinder()));
registerBean(resolverContext, RegionProperties.class, loadRegionProperties(resolverContext.getBinder()));

createMetricPublisher(resolverContext);
registerAndPromoteBean(resolverContext, SecretsManagerClient.class, this::createAwsSecretsManagerClient);

SecretsManagerPropertySources propertySources = new SecretsManagerPropertySources();

List<String> contexts = getCustomContexts(location.getNonPrefixedValue(PREFIX));
Expand Down

0 comments on commit cfc6064

Please sign in to comment.