use of software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method closeWaitsForUploadToComplete.
@Test(timeout = 10_000)
public void closeWaitsForUploadToComplete() throws InterruptedException {
CountDownLatch cloudwatchPutCalledLatch = new CountDownLatch(1);
CompletableFuture<PutMetricDataResponse> result = new CompletableFuture<>();
CloudWatchAsyncClient cloudWatch = Mockito.mock(CloudWatchAsyncClient.class);
try (CloudWatchMetricPublisher publisher = CloudWatchMetricPublisher.builder().cloudWatchClient(cloudWatch).uploadFrequency(Duration.ofMinutes(60)).build()) {
MetricCollector collector = newCollector();
collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
publisher.publish(new FixedTimeMetricCollection(collector.collect()));
Mockito.when(cloudWatch.putMetricData(any(PutMetricDataRequest.class))).thenAnswer(x -> {
cloudwatchPutCalledLatch.countDown();
return result;
});
publisher.publish(MetricCollector.create("test").collect());
Thread closeThread = new Thread(publisher::close);
assertThat(publisher.isShutdown()).isFalse();
closeThread.start();
// Wait until cloudwatch is called
cloudwatchPutCalledLatch.await();
// Wait to make sure the close thread seems to be waiting for the cloudwatch call to complete
Thread.sleep(1_000);
assertThat(closeThread.isAlive()).isTrue();
// Complete the cloudwatch call
result.complete(null);
// Make sure the close thread finishes
closeThread.join(5_000);
assertThat(closeThread.isAlive()).isFalse();
}
}
use of software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient in project graylog-plugin-integrations by Graylog2.
the class KinesisConsumer method run.
public void run() {
LOG.debug("Starting the Kinesis Consumer.");
AwsCredentialsProvider credentialsProvider = AWSAuthFactory.create(request.region(), request.awsAccessKeyId(), request.awsSecretAccessKey(), request.assumeRoleArn());
final Region region = Region.of(request.region());
final DynamoDbAsyncClientBuilder dynamoDbClientBuilder = DynamoDbAsyncClient.builder();
AWSClientBuilderUtil.initializeBuilder(dynamoDbClientBuilder, request.dynamodbEndpoint(), region, credentialsProvider);
final DynamoDbAsyncClient dynamoClient = dynamoDbClientBuilder.build();
final CloudWatchAsyncClientBuilder cloudwatchClientBuilder = CloudWatchAsyncClient.builder();
AWSClientBuilderUtil.initializeBuilder(cloudwatchClientBuilder, request.cloudwatchEndpoint(), region, credentialsProvider);
final CloudWatchAsyncClient cloudWatchClient = cloudwatchClientBuilder.build();
final KinesisAsyncClientBuilder kinesisAsyncClientBuilder = KinesisAsyncClient.builder();
AWSClientBuilderUtil.initializeBuilder(kinesisAsyncClientBuilder, request.kinesisEndpoint(), region, credentialsProvider);
final KinesisAsyncClient kinesisAsyncClient = KinesisClientUtil.createKinesisAsyncClient(kinesisAsyncClientBuilder);
final String workerId = String.format(Locale.ENGLISH, "graylog-node-%s", nodeId.anonymize());
LOG.debug("Using workerId [{}].", workerId);
// The application name needs to be unique per input/consumer.
final String applicationName = String.format(Locale.ENGLISH, "graylog-aws-plugin-%s", kinesisStreamName);
LOG.debug("Using Kinesis applicationName [{}].", applicationName);
// The KinesisShardProcessorFactory contains the message processing logic.
final KinesisShardProcessorFactory kinesisShardProcessorFactory = new KinesisShardProcessorFactory(objectMapper, transport, handleMessageCallback, kinesisStreamName, awsMessageType);
ConfigsBuilder configsBuilder = new ConfigsBuilder(kinesisStreamName, applicationName, kinesisAsyncClient, dynamoClient, cloudWatchClient, workerId, kinesisShardProcessorFactory);
final PollingConfig pollingConfig = new PollingConfig(kinesisStreamName, kinesisAsyncClient);
// Default max records per request is 10k.
if (recordBatchSize != null) {
LOG.debug("Using explicit batch size [{}]", recordBatchSize);
pollingConfig.maxRecords(recordBatchSize);
}
this.kinesisScheduler = new Scheduler(configsBuilder.checkpointConfig(), configsBuilder.coordinatorConfig(), configsBuilder.leaseManagementConfig(), configsBuilder.lifecycleConfig(), configsBuilder.metricsConfig(), configsBuilder.processorConfig(), configsBuilder.retrievalConfig().retrievalSpecificConfig(pollingConfig));
LOG.debug("Starting Kinesis scheduler.");
kinesisScheduler.run();
LOG.debug("After Kinesis scheduler stopped.");
}
Aggregations