-
Notifications
You must be signed in to change notification settings - Fork 916
Full POC for metrics system #1844
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>core</artifactId> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<version>2.13.18-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>metrics-spi</artifactId> | ||
<name>AWS Java SDK :: Metrics SPI</name> | ||
<description> This is the base module for SDK metrics feature. It contains the interfaces used for metrics feature | ||
that are used by other modules in the library. | ||
</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.11.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>test-utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.metrics</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/DefaultMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package software.amazon.awssdk.metrics; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* The set of metrics collected by default by the SDK. | ||
*/ | ||
public final class DefaultMetrics { | ||
/** | ||
* The duration of time it took to marshall an SDK request object to an HTTP request object. | ||
*/ | ||
public static final SdkMetric<Duration> REQUEST_MARSHALLING_TIME = SdkMetric.of("RequestMarshallingTime", Duration.class, MetricCategory.DEFAULT); | ||
|
||
/** | ||
* The duration of time it took to sign a request. | ||
* <p> | ||
* Note: this metric is only present if the SDK client is configured to sign requests. | ||
*/ | ||
public static final SdkMetric<Duration> REQUEST_SIGNING_TIME = SdkMetric.of("RequestSigningTime", Duration.class, MetricCategory.DEFAULT); | ||
|
||
/** | ||
* The duration of time between sending the HTTP request and when the HTTP response is received. | ||
*/ | ||
public static final SdkMetric<Duration> REQUEST_EXECUTION_TIME = SdkMetric.of("RequestExecutionTime", Duration.class, MetricCategory.DEFAULT); | ||
|
||
private DefaultMetrics() { | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/MetricCategory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.metrics; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
|
||
/** | ||
* A enum class representing the different types of metric categories in the SDK. | ||
* <p> | ||
* A metric can be tagged with multiple categories. Clients can enable/disable metric collection | ||
* at a {@link MetricCategory} level. | ||
*/ | ||
@SdkPublicApi | ||
public enum MetricCategory { | ||
|
||
/** | ||
* All metrics defined by the SDK are classified under this category at a minimum. If the metrics feature is enabled | ||
* but the category to collect is not, only metrics that are classified under this category are collected by the SDK | ||
*/ | ||
DEFAULT("default"), | ||
|
||
/** | ||
* Metrics collected at the http client level are classified under this category. | ||
*/ | ||
HTTP_CLIENT("httpclient"), | ||
|
||
/** | ||
* Metrics specific to streaming, eventStream APIs are classified under this category. | ||
*/ | ||
STREAMING("streaming"), | ||
|
||
/** | ||
* This is an umbrella category (provided for convenience) that records metrics belonging to every category | ||
* defined in this enum. Clients who wish to collect lot of SDK metrics data should use this. | ||
* <p> | ||
* Note: Enabling this option is verbose and can be expensive based on the platform the metrics are uploaded to. | ||
* Please make sure you need all this data before using this category. | ||
*/ | ||
ALL("all") | ||
|
||
; | ||
|
||
private final String value; | ||
|
||
MetricCategory(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Create a {@link MetricCategory} from the given String value. This method is case insensitive. | ||
* | ||
* @param value the value to create the {@link MetricCategory} from | ||
* @return A {@link MetricCategory} if the given {@link #value} matches one of the enum values. | ||
* Otherwise throws {@link IllegalArgumentException} | ||
*/ | ||
public static MetricCategory fromString(String value) { | ||
for (MetricCategory mc : MetricCategory.values()) { | ||
if (mc.value.equalsIgnoreCase(value)) { | ||
return mc; | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("MetricCategory cannot be created from value: " + value); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/MetricCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package software.amazon.awssdk.metrics; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* An immutable collection of metrics. | ||
*/ | ||
public interface MetricCollection extends Iterable<MetricRecord<?>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SdkIterable? |
||
/** | ||
* @return The name of this metric collection. | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Return all the values of the given metric. | ||
* | ||
* @param metric The metric. | ||
* @param <T> The type of the value. | ||
* @return All of the values of this metric. | ||
*/ | ||
<T> List<T> getAllMetricValues(SdkMetric<T> metric); | ||
|
||
/** | ||
* Return the values of the given metric. | ||
* | ||
* @param metric The metric. | ||
* @param <T> The type of the value. | ||
* @return The value of this metric. | ||
*/ | ||
<T> Optional<T> getMetricValue(SdkMetric<T> metric); | ||
dagnir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @return The child metric collections. | ||
*/ | ||
Collection<MetricCollection> children(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we have to treat "all" magically. Can't we just do MetricCategory.values() to get all of them?