Skip to content

Commit d5241e3

Browse files
committed
Add interfaces and basic implementations
1 parent 02e8d18 commit d5241e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2402
-2
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/client/handler/AwsClientHandlerUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
3333
import software.amazon.awssdk.core.SdkRequest;
3434
import software.amazon.awssdk.core.SdkResponse;
35+
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
3536
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
3637
import software.amazon.awssdk.core.client.config.SdkClientOption;
3738
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
3839
import software.amazon.awssdk.core.http.ExecutionContext;
3940
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
4041
import software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain;
4142
import software.amazon.awssdk.core.interceptor.InterceptorContext;
43+
import software.amazon.awssdk.core.interceptor.MetricExecutionAttribute;
4244
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
4345
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
4446
import software.amazon.awssdk.core.signer.Signer;
@@ -81,7 +83,12 @@ static <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext
8183
.putAttribute(SdkInternalExecutionAttribute.IS_FULL_DUPLEX, executionParams.isFullDuplex())
8284
.putAttribute(SdkExecutionAttribute.CLIENT_TYPE, clientConfig.option(SdkClientOption.CLIENT_TYPE))
8385
.putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME))
84-
.putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName());
86+
.putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName())
87+
.putAttribute(MetricExecutionAttribute.METRIC_CONFIGURATION_PROVIDER,
88+
clientConfig.option(SdkAdvancedClientOption.METRIC_CONFIGURATION_PROVIDER))
89+
.putAttribute(MetricExecutionAttribute.METRIC_PUBLISHER_CONFIGURATION,
90+
clientConfig.option(SdkAdvancedClientOption.METRIC_PUBLISHER_CONFIGURATION))
91+
;
8592

8693
ExecutionInterceptorChain executionInterceptorChain =
8794
new ExecutionInterceptorChain(clientConfig.option(SdkClientOption.EXECUTION_INTERCEPTORS));

core/metrics-spi/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>core</artifactId>
7+
<groupId>software.amazon.awssdk</groupId>
8+
<version>2.5.70-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>metrics-spi</artifactId>
13+
<name>AWS Java SDK :: Metrics SPI</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>software.amazon.awssdk</groupId>
18+
<artifactId>annotations</artifactId>
19+
<version>${awsjavasdk.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>utils</artifactId>
24+
<version>${awsjavasdk.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.slf4j</groupId>
28+
<artifactId>slf4j-api</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>software.amazon.awssdk</groupId>
33+
<artifactId>test-utils</artifactId>
34+
<version>${awsjavasdk.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>junit</groupId>
39+
<artifactId>junit</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.github.tomakehurst</groupId>
44+
<artifactId>wiremock</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.assertj</groupId>
49+
<artifactId>assertj-core</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.mockito</groupId>
54+
<artifactId>mockito-core</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>software.amazon.awssdk</groupId>
59+
<artifactId>utils</artifactId>
60+
<version>2.2.1-SNAPSHOT</version>
61+
</dependency>
62+
</dependencies>
63+
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-jar-plugin</artifactId>
70+
<configuration>
71+
<archive>
72+
<manifestEntries>
73+
<Automatic-Module-Name>software.amazon.awssdk.metrics</Automatic-Module-Name>
74+
</manifestEntries>
75+
</archive>
76+
</configuration>
77+
</plugin>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-compiler-plugin</artifactId>
81+
<configuration>
82+
<source>1.8</source>
83+
<target>1.8</target>
84+
</configuration>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
</project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.metrics;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
20+
/**
21+
* A enum class representing the different types of metric categories in the SDK.
22+
*
23+
* A metric can be tagged with multiple categories. Clients can enable/disable metric collection
24+
* at {@link MetricCategory} level.
25+
*/
26+
@SdkPublicApi
27+
public enum MetricCategory {
28+
None("none"),
29+
30+
Default("default"),
31+
32+
HttpClient("httpclient"),
33+
34+
Streaming("streaming"),
35+
36+
All("all")
37+
38+
;
39+
40+
private final String value;
41+
42+
MetricCategory(String value) {
43+
this.value = value;
44+
}
45+
46+
public String getValue() {
47+
return value;
48+
}
49+
50+
/**
51+
* Create a {@link MetricCategory} from the given String value. This method is case insensitive.
52+
*
53+
* @param value the value to create the {@link MetricCategory} from
54+
* @return A {@link MetricCategory} if the given {@link #value} matches one of the enum values.
55+
* Otherwise throws {@link IllegalArgumentException}
56+
*/
57+
public static MetricCategory fromString(String value) {
58+
for (MetricCategory mc : MetricCategory.values()) {
59+
if (mc.value.equalsIgnoreCase(value)) {
60+
return mc;
61+
}
62+
}
63+
64+
throw new IllegalArgumentException("MetricCategory cannot be created from value: " + value);
65+
}
66+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.metrics;
17+
18+
import java.util.Arrays;
19+
import java.util.HashSet;
20+
import java.util.Set;
21+
import software.amazon.awssdk.annotations.SdkProtectedApi;
22+
import software.amazon.awssdk.metrics.meter.Metric;
23+
24+
/**
25+
* A enum representing the metrics supported by the SDK. All metrics collected by the SDK will be declared in this
26+
* enum class along with the metric's corresponding {@link MetricCategory}.
27+
*/
28+
// TODO List is not complete
29+
@SdkProtectedApi
30+
public enum SdkMetrics implements Metric {
31+
32+
/**
33+
* Service ID of the AWS service that the API request is made against
34+
*/
35+
Service("Service", MetricCategory.Default),
36+
37+
/**
38+
* The name of the AWS operation the request is made to
39+
*/
40+
Api("Api", MetricCategory.Default),
41+
42+
/**
43+
* The http status code returned in the response
44+
*/
45+
HttpStatusCode("HttpStatusCode", MetricCategory.Default),
46+
47+
/**
48+
* The time taken to marshall the request
49+
*/
50+
MarshallingLatency("MarshallingLatency", MetricCategory.Default),
51+
52+
/**
53+
* Total number of attempts that were made by the service client to fulfill this request before succeeding or failing.
54+
* (This value would be 1 if there are no retries)
55+
*/
56+
ApiCallAttemptCount("ApiCallAttemptCount", MetricCategory.Default),
57+
58+
/**
59+
* Maximum number of streams allowed on a http2 connection
60+
*/
61+
MaxStreamCount("MaxStreamCount", MetricCategory.Default, MetricCategory.HttpClient)
62+
63+
;
64+
65+
private final String value;
66+
67+
private final Set<MetricCategory> tags;
68+
69+
SdkMetrics(String value, MetricCategory... tags) {
70+
this.value = value;
71+
this.tags = new HashSet<>(Arrays.asList(tags));
72+
}
73+
74+
public String value() {
75+
return value;
76+
}
77+
78+
@Override
79+
public Set<MetricCategory> tags() {
80+
return tags;
81+
}
82+
83+
@Override
84+
public String toString() {
85+
return "{" +
86+
"value='" + value + '\'' +
87+
", tags=" + tags +
88+
'}';
89+
}
90+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.metrics.internal;
17+
18+
import software.amazon.awssdk.annotations.SdkInternalApi;
19+
import software.amazon.awssdk.metrics.MetricCategory;
20+
import software.amazon.awssdk.utils.SystemSetting;
21+
22+
/**
23+
* System properties to configure metrics options in the SDK.
24+
*/
25+
@SdkInternalApi
26+
public enum MetricSystemSetting implements SystemSetting {
27+
28+
/**
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"
32+
*/
33+
AWS_JAVA_SDK_METRICS_ENABLED("aws.javasdk2x.metrics.enabled", null),
34+
35+
/**
36+
* Specify comma separated {@link MetricCategory} values to enable the categories for metrics collection.
37+
* Only metrics belonging to these categories are collected by the SDK.
38+
*
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+
*/
42+
AWS_JAVA_SDK_METRICS_CATEGORY("aws.javasdk2x.metrics.category", "Default")
43+
44+
;
45+
46+
private final String systemProperty;
47+
private final String defaultValue;
48+
49+
MetricSystemSetting(String systemProperty, String defaultValue) {
50+
this.systemProperty = systemProperty;
51+
this.defaultValue = defaultValue;
52+
}
53+
54+
@Override
55+
public String property() {
56+
return systemProperty;
57+
}
58+
59+
@Override
60+
public String environmentVariable() {
61+
return name();
62+
}
63+
64+
@Override
65+
public String defaultValue() {
66+
return defaultValue;
67+
}
68+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.metrics.meter;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
20+
/**
21+
* A {@link Gauge} implementation that stores a constant value for a metric.
22+
* The value stored cannot be changed after object creation
23+
*
24+
* @param <TypeT> the type of the value recorded in the Gauge
25+
*/
26+
@SdkPublicApi
27+
public final class ConstantGauge<TypeT> implements Gauge<TypeT> {
28+
29+
private final TypeT value;
30+
31+
private ConstantGauge(TypeT value) {
32+
this.value = value;
33+
}
34+
35+
/**
36+
* @param value the value to store in the guage
37+
* @param <T> type of the value
38+
* @return An instance of {@link ConstantGauge} with the given {@link #value} stored in the gauge.
39+
*/
40+
public static <T> ConstantGauge<T> create(T value) {
41+
return new ConstantGauge<>(value);
42+
}
43+
44+
@Override
45+
public TypeT value() {
46+
return value;
47+
}
48+
}

0 commit comments

Comments
 (0)