Skip to content

Commit f7d8996

Browse files
committed
Add tests
1 parent 0fcb1fb commit f7d8996

35 files changed

+790
-245
lines changed

core/metrics-spi/pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
<artifactId>metrics-spi</artifactId>
1313
<name>AWS Java SDK :: Metrics SPI</name>
14+
<description> This is the base module for SDK metrics feature. It contains the interfaces used for metrics feature
15+
that are used by other modules in the library.
16+
</description>
1417

1518
<dependencies>
1619
<dependency>
@@ -54,11 +57,6 @@
5457
<artifactId>mockito-core</artifactId>
5558
<scope>test</scope>
5659
</dependency>
57-
<dependency>
58-
<groupId>software.amazon.awssdk</groupId>
59-
<artifactId>utils</artifactId>
60-
<version>2.2.1-SNAPSHOT</version>
61-
</dependency>
6260
</dependencies>
6361

6462

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/MetricCategory.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,43 @@
1616
package software.amazon.awssdk.metrics;
1717

1818
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.metrics.internal.SdkMetric;
1920

2021
/**
2122
* A enum class representing the different types of metric categories in the SDK.
2223
*
2324
* A metric can be tagged with multiple categories. Clients can enable/disable metric collection
24-
* at {@link MetricCategory} level.
25+
* at a {@link MetricCategory} level.
26+
*
27+
* @see SdkMetric
2528
*/
2629
@SdkPublicApi
2730
public enum MetricCategory {
28-
None("none"),
2931

30-
Default("default"),
32+
/**
33+
* All metrics defined by the SDK are classified under this category at a minimum. If the metrics feature is enabled
34+
* but the category to collect is not, only metrics that are classified under this category are collected by the SDK
35+
*/
36+
DEFAULT("default"),
3137

32-
HttpClient("httpclient"),
38+
/**
39+
* Metrics collected at the http client level are classified under this category.
40+
*/
41+
HTTP_CLIENT("httpclient"),
3342

34-
Streaming("streaming"),
43+
/**
44+
* Metrics specific to streaming, eventStream APIs are classified under this category.
45+
*/
46+
STREAMING("streaming"),
3547

36-
All("all")
48+
/**
49+
* This is an umbrella category (provided for convenience) that records metrics belonging to every category
50+
* defined in this enum. Clients who wish to collect lot of SDK metrics data should use this.
51+
*
52+
* Note: Enabling this option is verbose and can be expensive based on the platform the metrics are uploaded to.
53+
* Please make sure you need all this data before using this category.
54+
*/
55+
ALL("all")
3756

3857
;
3958

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/internal/MetricSystemSetting.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626
public enum MetricSystemSetting implements SystemSetting {
2727

2828
/**
29-
* Enable the Java SDK Metrics by setting this property.
30-
*
31-
* Metrics feature is disabled if this feature is not specified or specified to anything other than "true"
29+
* Enable the Java SDK Metrics by setting this property. Metrics feature is disabled if this feature is not specified or
30+
* specified to anything other than "true"
3231
*/
3332
AWS_JAVA_SDK_METRICS_ENABLED("aws.javasdk2x.metrics.enabled", null),
3433

3534
/**
3635
* Specify comma separated {@link MetricCategory} values to enable the categories for metrics collection.
3736
* Only metrics belonging to these categories are collected by the SDK.
3837
*
39-
* This value is defaulted to {@link MetricCategory#Default}. If this property is not set but metrics are enabled,
40-
* then metrics belonging to {@link MetricCategory#Default} category are collected.
38+
* <p>
39+
* This value is defaulted to {@link MetricCategory#DEFAULT}. If this property is not set but metrics are enabled,
40+
* then metrics belonging to {@link MetricCategory#DEFAULT} category are collected.
41+
* </p>
4142
*/
4243
AWS_JAVA_SDK_METRICS_CATEGORY("aws.javasdk2x.metrics.category", "Default")
4344

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/SdkMetrics.java renamed to core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/internal/SdkMetric.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,100 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.metrics;
16+
package software.amazon.awssdk.metrics.internal;
17+
18+
import static software.amazon.awssdk.metrics.MetricCategory.DEFAULT;
19+
import static software.amazon.awssdk.metrics.MetricCategory.HTTP_CLIENT;
1720

1821
import java.util.Arrays;
1922
import java.util.Collections;
2023
import java.util.HashSet;
2124
import java.util.Set;
22-
import software.amazon.awssdk.annotations.SdkProtectedApi;
25+
import software.amazon.awssdk.annotations.SdkInternalApi;
26+
import software.amazon.awssdk.metrics.MetricCategory;
2327
import software.amazon.awssdk.metrics.meter.Metric;
2428

2529
/**
2630
* A enum representing the metrics supported by the SDK. All metrics collected by the SDK will be declared in this
2731
* enum class along with the metric's corresponding {@link MetricCategory}.
2832
*/
2933
// TODO List is not complete
30-
@SdkProtectedApi
31-
public enum SdkMetrics implements Metric {
34+
@SdkInternalApi
35+
public enum SdkMetric implements Metric {
3236

3337
/**
3438
* Service ID of the AWS service that the API request is made against
3539
*/
36-
Service("Service", MetricCategory.Default),
40+
Service("Service", DEFAULT),
3741

3842
/**
3943
* The name of the AWS operation the request is made to
4044
*/
41-
Api("Api", MetricCategory.Default),
45+
Operation("Operation", DEFAULT),
4246

4347
/**
4448
* The total time taken to finish (success or fail) a request (inclusive of all retries)
4549
*/
46-
ApiCallLatency("ApiCallLatency", MetricCategory.Default),
50+
ApiCallLatency("ApiCallLatency", DEFAULT),
4751

4852
/**
4953
* The time taken to marshall the request
5054
*/
51-
MarshallingLatency("MarshallingLatency", MetricCategory.Default),
55+
MarshallingLatency("MarshallingLatency", DEFAULT),
5256

5357
/**
5458
* Total number of attempts that were made by the service client to fulfill this request before succeeding or failing.
5559
* (This value would be 1 if there are no retries)
5660
*/
57-
ApiCallAttemptCount("ApiCallAttemptCount", MetricCategory.Default),
61+
ApiCallAttemptCount("ApiCallAttemptCount", DEFAULT),
5862

5963
/**
6064
* The time taken to sign the request
6165
*/
62-
SigningLatency("SigningLatency", MetricCategory.Default),
66+
SigningLatency("SigningLatency", DEFAULT),
6367

6468
/**
65-
* The time taken by the underlying http client to start the Api call attempt and return the response
69+
* The time taken by the underlying http client to start the Operation call attempt and return the response
6670
*/
67-
HttpRequestRoundTripLatency("HttpRequestRoundTripLatency", MetricCategory.Default),
71+
HttpRequestRoundTripLatency("HttpRequestRoundTripLatency", DEFAULT),
6872

6973
/**
7074
* The time taken to unmarshall the response (either successful and failed response)
7175
*/
72-
UnmarshallingLatency("UnmarshallingLatency", MetricCategory.Default),
76+
UnmarshallingLatency("UnmarshallingLatency", DEFAULT),
7377

7478
/**
75-
* The total time taken for an Api call attempt
79+
* The total time taken for an Operation call attempt
7680
*/
77-
ApiCallAttemptLatency("ApiCallAttemptLatency", MetricCategory.Default),
81+
ApiCallAttemptLatency("ApiCallAttemptLatency", DEFAULT),
7882

7983
/**
8084
* The http status code returned in the response
8185
*/
82-
HttpStatusCode("HttpStatusCode", MetricCategory.Default),
86+
HttpStatusCode("HttpStatusCode", DEFAULT),
8387

8488
/**
8589
* The request Id for the request. Represented by x-amz-request-id header in response
8690
*/
87-
AwsRequestId("AwsRequestId", MetricCategory.Default),
91+
AwsRequestId("AwsRequestId", DEFAULT),
8892

8993
/**
9094
* The extended request Id for the request. Represented by x-amz-id-2 header in response
9195
*/
92-
ExtendedRequestId("ExtendedRequestId", MetricCategory.Default),
96+
ExtendedRequestId("ExtendedRequestId", DEFAULT),
9397

9498
/**
9599
* Maximum number of streams allowed on a http2 connection
96100
*/
97-
MaxStreamCount("MaxStreamCount", MetricCategory.Default, MetricCategory.HttpClient)
101+
MaxStreamCount("MaxStreamCount", DEFAULT, HTTP_CLIENT)
98102

99103
;
100104

101105
private final String value;
102106

103107
private final Set<MetricCategory> categories;
104108

105-
SdkMetrics(String value, MetricCategory... categories) {
109+
SdkMetric(String value, MetricCategory... categories) {
106110
this.value = value;
107111
this.categories = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(categories)));
108112
}

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/meter/DefaultGauge.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.concurrent.atomic.AtomicReference;
2222
import software.amazon.awssdk.annotations.SdkPublicApi;
2323
import software.amazon.awssdk.metrics.MetricCategory;
24-
import software.amazon.awssdk.utils.Validate;
2524

2625
/**
2726
* A basic implementation of {@link Gauge} that has ability to set, update and return a single value.
@@ -35,7 +34,6 @@ public final class DefaultGauge<TypeT> implements Gauge<TypeT> {
3534
private final Set<MetricCategory> categories;
3635

3736
private DefaultGauge(Builder<TypeT> builder) {
38-
Validate.notNull(builder.value, "Value cannot be null");
3937
this.atomicReference = new AtomicReference<>(builder.value);
4038
this.categories = Collections.unmodifiableSet(builder.categories);
4139
}

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/meter/DefaultTimer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public <T> T record(Callable<T> task) {
7676
}
7777
}
7878

79+
@Override
80+
public void start() {
81+
startTime = clock.instant();
82+
}
83+
84+
@Override
85+
public void end() {
86+
endTime = clock.instant();
87+
}
88+
7989
@Override
8090
public Instant startTime() {
8191
return startTime;
@@ -126,7 +136,7 @@ private Builder() {
126136
/**
127137
* Sets the {@link Clock} implementation the timer should use. The default value is {@link Clock#systemUTC()}
128138
*
129-
* @param clock the {@link Clock} implementation used by the time
139+
* @param clock the {@link Clock} implementation used by the timer
130140
* @return This object for method chaining
131141
*/
132142
Builder clock(Clock clock) {

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/meter/NoOpTimer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
* Always returns {@link Duration#ZERO} as the total duration.
2828
*/
2929
@SdkPublicApi
30-
public enum NoOpTimer implements Timer {
30+
public enum NoOpTimer implements Timer {
3131
/** Singleton instance **/
3232
INSTANCE;
3333

3434
@Override
3535
public void record(long duration, TimeUnit timeUnit) {
36-
3736
}
3837

3938
@Override
@@ -50,6 +49,14 @@ public <T> T record(Callable<T> task) {
5049
}
5150
}
5251

52+
@Override
53+
public void start() {
54+
}
55+
56+
@Override
57+
public void end() {
58+
}
59+
5360
@Override
5461
public Instant startTime() {
5562
return Instant.now();

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/meter/Ratio.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)