Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading AWS Java SDK to v2 #26

Merged
merged 3 commits into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ This is a CloudWatch Reporter for the stable version of Dropwizard Metrics (form

### Summary

- This CloudWatchReporter reports the metric data to CloudWatch asynchronously using the [AmazonCloudWatchAsyncClient (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/AmazonCloudWatchAsyncClient.html) interface
- Each reportable value in CodeHale [Metric](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Metric.html) is reported as a separate [MetricDatum (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/MetricDatum.html)
- This CloudWatchReporter reports the metric data to CloudWatch asynchronously using the [CloudWatchAsyncClient (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/CloudWatchAsyncClient.html) interface
- Each reportable value in CodeHale [Metric](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Metric.html) is reported as a separate [MetricDatum (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/MetricDatum.html)
- When reporting [Meter](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Meter.html), [Counter](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Counter.html), [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html) count metrics (`getCount()`) as [MetricDatum (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/MetricDatum.html), only the count difference since the last report is reported. This way the counters do not require a reset within the application using this reporter.
- If configured, each [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) translated into [StatisticSet (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/StatisticSet.html) in the most direct way possible.
- If configured, each [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) translated into [StatisticSet (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/StatisticSet.html) in the most direct way possible.
- If configured, JVM statistic is reported

### Reportable Metrics
Expand All @@ -37,7 +37,7 @@ Currently the only metric values that are reportable through configuration are:
- Percentiles from [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) in [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html)
- Arithmetic mean & standard deviation of [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) values in [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html)
- Mean rates from [Meter](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Meter.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html)
- Summaries of [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) values in [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html) as [StatisticSet (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/StatisticSet.html)
- Summaries of [Snapshot](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Snapshot.html) values in [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html) as [StatisticSet (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/StatisticSet.html)

__Please note__:

Expand Down Expand Up @@ -94,13 +94,13 @@ Since `DimensionedName` is immutable, the string representation returned by `enc

The Reporter uses the following defaults which can be configured:

- Rate metrics are in `TimeUnit.Seconds`
- Duration metrics are in `TimeUnit.Milliseconds`
- Rate metrics are in `TimeUnit.SECONDS`
- Duration metrics are in `TimeUnit.MILLISECONDS`
- `MetricFilter.ALL` will be used for the Filter
- `Clock.defaultClock()` will be used for the Clock (Unconfigurable)
- Metrics are reported using standard resolution (can be changed to [high resolution](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics))
- Empty global [Dimension (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/Dimension.html) list
- The reporter adds a `Type` [Dimension (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/Dimension.html) to each reported metric, e.g:
- Empty global [Dimension (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/Dimension.html) list
- The reporter adds a `Type` [Dimension (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/Dimension.html) to each reported metric, e.g:

| Type | Metric Name |
| ----------------------------------------- | --------------------------------------------------------------- |
Expand All @@ -117,7 +117,7 @@ The __only__ metrics that are reportable __by default__ are:
- Count values (`getCount()`) from [Meter](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Meter.html), [Counter](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Counter.html), [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html)
- Percentile values (`75%`, `95%`, `99.9%`) from [Histogram](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Histogram.html) and [Timer](https://static.javadoc.io/io.dropwizard.metrics/metrics-core/4.0.2/com/codahale/metrics/Timer.html)

All other metrics have to be confugured for reporting by invoking their respective `withXXXX()` methods on the `CloudWatchReporter.Builder` instance
All other metrics have to be configured for reporting by invoking their respective `withXXXX()` methods on the `CloudWatchReporter.Builder` instance


### Adding cloudwatch reporter to your project
Expand All @@ -143,7 +143,7 @@ The library fetches the following transitive dependencies:
```
io.dropwizard.metrics:metrics-core:4.0.2
io.dropwizard.metrics:metrics-jvm:4.0.2
com.amazonaws:aws-java-sdk-cloudwatch:1.11.179
software.amazon.awssdk:cloudwatch:2.7.19
```


Expand All @@ -154,12 +154,12 @@ The reporter provides a fine-grained configuration options through its builder t


```
final AmazonCloudWatchAsync amazonCloudWatchAsync =
AmazonCloudWatchAsyncClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
final CloudWatchAsyncClient amazonCloudWatchAsync =
CloudWatchAsyncClient
.builder()
.region(Region.US_WEST_2)
.build();

final CloudWatchReporter cloudWatchReporter =
CloudWatchReporter.forRegistry(metricRegistry, amazonCloudWatchAsync, Main.class.getName())
.convertRatesTo(TimeUnit.SECONDS)
Expand All @@ -173,12 +173,12 @@ The reporter provides a fine-grained configuration options through its builder t
.withArithmeticMean()
.withStdDev()
.withStatisticSet()
.withJvmMetrics()
.withGlobalDimensions("Region=us-west-2", "Instance=stage")
.withZeroValuesSubmission()
.withReportRawCountValue()
.withHighResolution()
.withMeterUnitSentToCW(StandardUnit.Bytes)
.withMeterUnitSentToCW(StandardUnit.BYTES)
.withJvmMetrics()
.withGlobalDimensions("Region=us-west-2", "Instance=stage")
.withDryRun()
.build();

Expand All @@ -187,7 +187,7 @@ The reporter provides a fine-grained configuration options through its builder t


#### Dry run
The reporter can be configured to run in `DRY RUN` mode by invoking `.withDryRun()` on the `Builder`. In that case, the reporter will `log.DEBUG` the created instance of [PutMetricDataRequest (AWS)](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/model/PutMetricDataRequest.html), instead of doing a real `POST` to CloudWatch.
The reporter can be configured to run in `DRY RUN` mode by invoking `.withDryRun()` on the `Builder`. In that case, the reporter will `log.DEBUG` the created instance of [PutMetricDataRequest (AWS)](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/cloudwatch/model/PutMetricDataRequest.html), instead of doing a real `POST` to CloudWatch.



Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ allprojects {
dependencies {
compile("io.dropwizard.metrics:metrics-core:4.0.2")
compile("io.dropwizard.metrics:metrics-jvm:4.0.2")
compile("com.amazonaws:aws-java-sdk-cloudwatch:1.11.179")

compile("software.amazon.awssdk:cloudwatch:2.7.19")
compile("org.slf4j:slf4j-api:1.7.25")

testCompile("org.mockito:mockito-core:1.10.19")
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.amazonaws.regions.Regions;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
Expand Down Expand Up @@ -39,10 +38,10 @@ private static final class ReportingApp implements Callable<Void> {
this.metricRegistry = new MetricRegistry();
this.theTimer = metricRegistry.timer("TheTimer");

final AmazonCloudWatchAsync amazonCloudWatchAsync =
AmazonCloudWatchAsyncClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
final CloudWatchAsyncClient amazonCloudWatchAsync =
CloudWatchAsyncClient
.builder()
.region(Region.US_WEST_2)
.build();

final CloudWatchReporter cloudWatchReporter =
Expand Down
Loading