Skip to content

Commit

Permalink
Merge pull request aws#710 from gauravbrills/master
Browse files Browse the repository at this point in the history
aws#701 Added ClientConfiguration to Cloud Watch Metrics configurations
  • Loading branch information
zhangzhx committed May 31, 2016
2 parents 4a9fe14 + 4047754 commit 7f81841
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.http.annotation.NotThreadSafe;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.metrics.AwsSdkMetrics;

Expand Down Expand Up @@ -78,6 +79,9 @@ public class CloudWatchMetricConfig {

/** Credentials for the uploader to communicate with Amazon CloudWatch */
private AWSCredentialsProvider credentialsProvider;

/** ClientConfiguration for connecting to Amazon CloudWatch */
private ClientConfiguration clientConfiguration;

/**
* Number of milliseconds to wait before the polling of the metrics queue
Expand Down Expand Up @@ -109,7 +113,28 @@ public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
this.credentialsProvider = credentialsProvider;
}

public CloudWatchMetricConfig withCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
/**
* Returns the Client Configuration used to connect to
* Amazon CloudWatch.
*/
public ClientConfiguration getClientConfiguration() {
return clientConfiguration;
}

/**
* Sets the Client Configuration. This client
* configuration is used by the uploader thread to connect to Amazon CloudWatch.
*/
public void setClientConfiguration(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
}

public CloudWatchMetricConfig withClientConfiguration(ClientConfiguration clientConfiguration) {
setClientConfiguration(clientConfiguration);
return this;
}

public CloudWatchMetricConfig withCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
setCredentialsProvider(credentialsProvider);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amazonaws.metrics.internal.cloudwatch;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.SDKGlobalConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.metrics.AwsSdkMetrics;
Expand All @@ -39,6 +40,7 @@ public MetricCollector getInstance() {
Integer qSize = AwsSdkMetrics.getMetricQueueSize();
Long timeoutMilli = AwsSdkMetrics.getQueuePollTimeoutMilli();
CloudWatchMetricConfig config = new CloudWatchMetricConfig();
ClientConfiguration clientConfig = new ClientConfiguration();
if (provider != null)
config.setCredentialsProvider(provider);
if (region != null) {
Expand All @@ -49,6 +51,7 @@ public MetricCollector getInstance() {
config.setMetricQueueSize(qSize.intValue());
if (timeoutMilli != null)
config.setQueuePollTimeoutMilli(timeoutMilli.longValue());
config.setClientConfiguration(clientConfig);
MetricCollectorSupport.startSingleton(config);
return MetricCollectorSupport.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@ class MetricUploaderThread extends Thread {
BlockingQueue<MetricDatum> queue) {
this(config,
queue,
config.getCredentialsProvider() == null
? new AmazonCloudWatchClient()
: new AmazonCloudWatchClient(config.getCredentialsProvider()));
createCloudWatchClient(config));
}

private static AmazonCloudWatchClient createCloudWatchClient(CloudWatchMetricConfig config) {
AmazonCloudWatchClient amazonCloudWatchClient = null;
if (config.getCredentialsProvider() == null && config.getClientConfiguration() == null) {
amazonCloudWatchClient = new AmazonCloudWatchClient();
} else if (config.getCredentialsProvider() != null && config.getClientConfiguration() == null) {
amazonCloudWatchClient = new AmazonCloudWatchClient(config.getCredentialsProvider());
} else if (config.getClientConfiguration() != null && config.getCredentialsProvider() == null) {
amazonCloudWatchClient = new AmazonCloudWatchClient(config.getClientConfiguration());
} else if (config.getClientConfiguration() != null && config.getCredentialsProvider() != null) {
amazonCloudWatchClient = new AmazonCloudWatchClient(config.getCredentialsProvider(),
config.getClientConfiguration());
}
return amazonCloudWatchClient;
}

MetricUploaderThread(CloudWatchMetricConfig config,
BlockingQueue<MetricDatum> queue,
AmazonCloudWatchClient client)
Expand Down

0 comments on commit 7f81841

Please sign in to comment.