Skip to content

fix!: bump metrics version to 4.0.3 #971

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
wants to merge 15 commits into from
Closed
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ Powertools is available in Maven Central. You can use your favourite dependency
<dependency>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-tracing</artifactId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</dependency>
<dependency>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-logging</artifactId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</dependency>
<dependency>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-metrics</artifactId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</dependency>
...
</dependencies>
Expand Down
30 changes: 23 additions & 7 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ You can create metrics using `putMetric`, and manually create dimensions for all
@Override
@Metrics(namespace = "ExampleApplication", service = "booking")
public Object handleRequest(Object input, Context context) {
metricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
try {
metricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
} catch (InvalidDimensionException | InvalidMetricException | DimensionSetExceededException e) {
LOG.error(e);
}
...
}
}
Expand Down Expand Up @@ -173,8 +177,12 @@ You can use `putMetadata` for advanced use cases, where you want to metadata as
@Override
@Metrics(namespace = "ServerlessAirline", service = "payment")
public Object handleRequest(Object input, Context context) {
metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
metricsLogger().putMetadata("booking_id", "1234567890");
try {
metricsLogger().putMetadata("booking_id", "1234567890");
metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
} catch (InvalidMetricException e) {
throw new RuntimeException(e);
}
...
}
}
Expand All @@ -199,7 +207,11 @@ Dimension, it can be done via `#!java MetricsUtils.defaultDimensions()`.
MetricsLogger metricsLogger = MetricsUtils.metricsLogger();

static {
MetricsUtils.defaultDimensions(DimensionSet.of("CustomDimension", "booking"));
try {
MetricsUtils.defaultDimensions(DimensionSet.of("CustomDimension", "booking"));
} catch (InvalidDimensionException | DimensionSetExceededException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down Expand Up @@ -228,8 +240,12 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `withSingle

@Override
public Object handleRequest(Object input, Context context) {
withSingleMetric("CustomMetrics2", 1, Unit.COUNT, "Another", (metric) -> {
metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
withSingleMetric("CustomMetrics2", 1, Unit.COUNT, "Another", (metric) -> {
try {
metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
} catch (InvalidDimensionException | DimensionSetExceededException e) {
throw new RuntimeException(e);
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/sqs_large_message_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ To disable deletion of payloads setting the following annotation parameter:
## Utility

If you want to avoid using annotation and have control over error that can happen during payload enrichment use `SqsUtils.enrichedMessageFromS3()`.
It provides you access with list of `SQSMessage` object enriched from S3 payload.
It provides you access with a list of `SQSMessage` object enriched from S3 payload.

Original `SQSEvent` object is never mutated. You can also control if the S3 payload should be deleted after successful
processing.
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extra_javascript:

extra:
powertools:
version: 1.12.3
version: 2.0.0-beta

repo_url: https://github.com/awslabs/aws-lambda-powertools-java
edit_uri: edit/master/docs
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-parent</artifactId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
<packaging>pom</packaging>

<name>AWS Lambda Powertools for Java library Parent</name>
Expand Down Expand Up @@ -56,13 +56,13 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<log4j.version>2.19.0</log4j.version>
<jackson.version>2.13.4.2</jackson.version>
<jackson.version>2.14.1</jackson.version>
<aspectj.version>1.9.7</aspectj.version>
<aws.sdk.version>2.18.9</aws.sdk.version>
<aws.xray.recorder.version>2.12.0</aws.xray.recorder.version>
<aws.sdk.version>2.18.22</aws.sdk.version>
<aws.xray.recorder.version>2.13.0</aws.xray.recorder.version>
<payloadoffloading-common.version>2.1.2</payloadoffloading-common.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lambda.core.version>1.2.1</lambda.core.version>
<lambda.core.version>1.2.2</lambda.core.version>
<lambda.events.version>3.11.0</lambda.events.version>
<lambda.serial.version>1.0.0</lambda.serial.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
Expand All @@ -75,7 +75,7 @@
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<aws-embedded-metrics.version>1.0.6</aws-embedded-metrics.version>
<aws-embedded-metrics.version>4.0.3</aws-embedded-metrics.version>
<jmespath.version>0.5.1</jmespath.version>
</properties>

Expand Down Expand Up @@ -244,13 +244,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.8.1</version>
<version>4.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.8.1</version>
<version>4.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -457,7 +457,7 @@
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.2.1</version>
<version>4.7.3.0</version>
<executions>
<execution>
<id>test</id>
Expand Down
2 changes: 1 addition & 1 deletion powertools-cloudformation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>powertools-parent</artifactId>
<groupId>software.amazon.lambda</groupId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</parent>

<name>AWS Lambda Powertools for Java library Cloudformation</name>
Expand Down
2 changes: 1 addition & 1 deletion powertools-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>powertools-parent</artifactId>
<groupId>software.amazon.lambda</groupId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</parent>

<name>AWS Lambda Powertools for Java library Core</name>
Expand Down
4 changes: 2 additions & 2 deletions powertools-idempotency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-parent</artifactId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</parent>

<artifactId>powertools-idempotency</artifactId>
Expand Down Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>1.7.1</version>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion powertools-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>powertools-parent</artifactId>
<groupId>software.amazon.lambda</groupId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</parent>

<name>AWS Lambda Powertools for Java library Logging</name>
Expand Down
2 changes: 1 addition & 1 deletion powertools-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>powertools-parent</artifactId>
<groupId>software.amazon.lambda</groupId>
<version>1.12.3</version>
<version>2.0.0-beta</version>
</parent>

<name>AWS Lambda Powertools for Java library Metrics</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package software.amazon.cloudwatchlogs.emf.model;

import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;

import java.lang.reflect.Field;

import static software.amazon.lambda.powertools.metrics.MetricsUtils.metricsLogger;

public final class MetricsLoggerHelper {

private MetricsLoggerHelper() {
}

Expand All @@ -13,7 +16,11 @@ public static boolean hasNoMetrics() {
}

public static long dimensionsCount() {
return metricsContext().getDimensions().size();
try {
return metricsContext().getDimensions().size();
} catch (DimensionSetExceededException e) {
throw new RuntimeException("Too many dimensions defined", e);
}
}

public static MetricsContext metricsContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import software.amazon.cloudwatchlogs.emf.config.SystemWrapper;
import software.amazon.cloudwatchlogs.emf.environment.EnvironmentProvider;
import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException;
import software.amazon.cloudwatchlogs.emf.exception.InvalidNamespaceException;
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
import software.amazon.cloudwatchlogs.emf.model.MetricsContext;
import software.amazon.cloudwatchlogs.emf.model.MetricsLoggerHelper;
import software.amazon.cloudwatchlogs.emf.model.Unit;

import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.getXrayTraceId;
import static software.amazon.lambda.powertools.metrics.internal.LambdaMetricsAspect.REQUEST_ID_PROPERTY;
Expand Down Expand Up @@ -49,23 +50,6 @@ public static void defaultDimensions(final DimensionSet... dimensionSets) {
MetricsUtils.defaultDimensions = dimensionSets;
}

/**
* Configure default dimension to be used by logger.
* By default, @{@link Metrics} annotation captures configured service as a dimension <i>Service</i>
* @param dimensionSet Default value of dimension set for logger
* @deprecated use {@link #defaultDimensions(DimensionSet...)} instead
*
*/
@Deprecated
public static void defaultDimensionSet(final DimensionSet dimensionSet) {
requireNonNull(dimensionSet, "Null dimension set not allowed");

if(dimensionSet.getDimensionKeys().size() > 0) {
defaultDimensions(dimensionSet);
}
}


/**
* Add and immediately flush a single metric. It will use the default namespace
* specified either on {@link Metrics} annotation or via POWERTOOLS_METRICS_NAMESPACE env var.
Expand All @@ -88,6 +72,10 @@ public static void withSingleMetric(final String name,
metricsLogger.putMetric(name, value, unit);
captureRequestAndTraceId(metricsLogger);
logger.accept(metricsLogger);
} catch (InvalidNamespaceException e) {
throw new RuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
} catch (InvalidMetricException e) {
throw new RuntimeException(e);
} finally {
metricsLogger.flush();
}
Expand Down Expand Up @@ -116,6 +104,10 @@ public static void withSingleMetric(final String name,
metricsLogger.putMetric(name, value, unit);
captureRequestAndTraceId(metricsLogger);
logger.accept(metricsLogger);
} catch (InvalidNamespaceException e) {
throw new RuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
} catch (InvalidMetricException e) {
throw new RuntimeException(e);
} finally {
metricsLogger.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;
import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException;
import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException;
import software.amazon.cloudwatchlogs.emf.exception.InvalidNamespaceException;
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
import software.amazon.cloudwatchlogs.emf.model.MetricsContext;
Expand Down Expand Up @@ -83,12 +87,24 @@ private void coldStartSingleMetricIfApplicable(final String awsRequestId,
final Metrics metrics) {
if (metrics.captureColdStart()
&& isColdStart()) {
MetricsLogger metricsLogger = new MetricsLogger();
MetricsLogger metricsLogger = new MetricsLogger();
try {
metricsLogger.setNamespace(namespace(metrics));
} catch (InvalidNamespaceException e) {
throw new RuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
}
try {
metricsLogger.putMetric("ColdStart", 1, Unit.COUNT);
} catch (InvalidMetricException e) {
// should not occur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding sole logs on debug level? Too many times in my live I've seen things that should not occur ;)

}
try {
metricsLogger.setDimensions(DimensionSet.of("Service", service(metrics), "FunctionName", functionName));
metricsLogger.putProperty(REQUEST_ID_PROPERTY, awsRequestId);
metricsLogger.flush();
} catch (InvalidDimensionException | DimensionSetExceededException e) {
throw new RuntimeException("A valid service is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_SERVICE_NAME", e);
}
metricsLogger.putProperty(REQUEST_ID_PROPERTY, awsRequestId);
metricsLogger.flush();
}

}
Expand Down Expand Up @@ -136,6 +152,8 @@ public static void refreshMetricsContext(Metrics metrics) {
f.set(metricsLogger(), context);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvalidDimensionException | DimensionSetExceededException e) {
throw new RuntimeException("A valid service is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_SERVICE_NAME", e);
}
}
}
Loading