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

chore(v2): remove deprecated code #1624

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ public static Builder builder() {
return new Builder();
}

/**
* Creates a failed Response with no physicalResourceId set. Powertools for AWS Lambda (Java) will set the physicalResourceId to the
* Lambda LogStreamName
* <p>
* The value returned for a PhysicalResourceId can change custom resource update operations. If the value returned
* is the same, it is considered a normal update. If the value returned is different, AWS CloudFormation recognizes
* the update as a replacement and sends a delete request to the old resource. For more information,
* see AWS::CloudFormation::CustomResource.
*
* @return a failed Response with no value.
* @deprecated this method is not safe. Provide a physicalResourceId.
*/
@Deprecated
public static Response failed() {
return new Response(null, Status.FAILED, null, false);
}

/**
* Creates a failed Response with a given physicalResourceId.
*
Expand All @@ -80,23 +63,6 @@ public static Response failed(String physicalResourceId) {
return new Response(null, Status.FAILED, physicalResourceId, false);
}

/**
* Creates a successful Response with no physicalResourceId set. Powertools for AWS Lambda (Java) will set the physicalResourceId to the
* Lambda LogStreamName
* <p>
* The value returned for a PhysicalResourceId can change custom resource update operations. If the value returned
* is the same, it is considered a normal update. If the value returned is different, AWS CloudFormation recognizes
* the update as a replacement and sends a delete request to the old resource. For more information,
* see AWS::CloudFormation::CustomResource.
*
* @return a success Response with no physicalResourceId value.
* @deprecated this method is not safe. Provide a physicalResourceId.
*/
@Deprecated
public static Response success() {
return new Response(null, Status.SUCCESS, null, false);
}

/**
* Creates a successful Response with a given physicalResourceId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import software.amazon.awssdk.utils.StringInputStream;
import software.amazon.lambda.powertools.cloudformation.CloudFormationResponse.ResponseBody;

public class CloudFormationResponseTest {
class CloudFormationResponseTest {

/**
* Creates a mock CloudFormationCustomResourceEvent with a non-null response URL.
Expand Down Expand Up @@ -215,7 +215,7 @@ void reasonIncludesLogStreamName() {
}

@Test
public void sendWithNoResponseData() throws Exception {
void sendWithNoResponseData() throws Exception {
CloudFormationCustomResourceEvent event = mockCloudFormationCustomResourceEvent();
Context context = mock(Context.class);
CloudFormationResponse cfnResponse = testableCloudFormationResponse();
Expand All @@ -237,7 +237,7 @@ public void sendWithNoResponseData() throws Exception {
}

@Test
public void sendWithNonNullResponseData() throws Exception {
void sendWithNonNullResponseData() throws Exception {
CloudFormationCustomResourceEvent event = mockCloudFormationCustomResourceEvent();
Context context = mock(Context.class);
CloudFormationResponse cfnResponse = testableCloudFormationResponse();
Expand Down Expand Up @@ -289,7 +289,7 @@ void responseBodyStreamSuccessResponse() throws Exception {
Context context = mock(Context.class);
CloudFormationResponse cfnResponse = testableCloudFormationResponse();

StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.success());
StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.success(null));

String expectedJson = "{" +
"\"Status\":\"SUCCESS\"," +
Expand All @@ -310,7 +310,7 @@ void responseBodyStreamFailedResponse() throws Exception {
Context context = mock(Context.class);
CloudFormationResponse cfnResponse = testableCloudFormationResponse();

StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.failed());
StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.failed(null));

String expectedJson = "{" +
"\"Status\":\"FAILED\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Map;
import org.junit.jupiter.api.Test;

public class ResponseTest {
class ResponseTest {

@Test
void defaultValues() {
Expand Down Expand Up @@ -92,7 +92,7 @@ void jsonMapValueWithDefaultObjectMapper() {

String expected = "{\"foo\":\"bar\"}";
assertThat(response.getJsonNode()).isNotNull();
assertThat(response.getJsonNode().toString()).isEqualTo(expected);
assertThat(response.getJsonNode()).hasToString(expected);
assertThat(response.toString()).contains("JSON = " + expected);
}

Expand All @@ -105,7 +105,7 @@ void jsonObjectValueWithDefaultObjectMapper() {
.build();

String expected = "{\"PropertyWithLongName\":\"test\"}";
assertThat(response.getJsonNode().toString()).isEqualTo(expected);
assertThat(response.getJsonNode()).hasToString(expected);
assertThat(response.toString()).contains("JSON = " + expected);
}

Expand All @@ -119,7 +119,7 @@ void jsonObjectValueWithNullObjectMapper() {
.build();

String expected = "{\"PropertyWithLongName\":\"test\"}";
assertThat(response.getJsonNode().toString()).isEqualTo(expected);
assertThat(response.getJsonNode()).hasToString(expected);
assertThat(response.toString()).contains("JSON = " + expected);
}

Expand All @@ -135,7 +135,7 @@ void jsonObjectValueWithCustomObjectMapper() {
.build();

String expected = "{\"property-with-long-name\":10}";
assertThat(response.getJsonNode().toString()).isEqualTo(expected);
assertThat(response.getJsonNode()).hasToString(expected);
assertThat(response.toString()).contains("JSON = " + expected);
}

Expand All @@ -154,21 +154,21 @@ void jsonObjectValueWithPostConfiguredObjectMapper() {
customMapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);

String expected = "{\"property-with-long-name\":10}";
assertThat(response.getJsonNode().toString()).isEqualTo(expected);
assertThat(response.getJsonNode()).hasToString(expected);
assertThat(response.toString()).contains("JSON = " + expected);
}

@Test
void successFactoryMethod() {
Response response = Response.success();
Response response = Response.success(null);

assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(Response.Status.SUCCESS);
}

@Test
void failedFactoryMethod() {
Response response = Response.failed();
Response response = Response.failed(null);

assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(Response.Status.FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public class NoPhysicalResourceIdSetHandler extends AbstractCustomResourceHandle

@Override
protected Response create(CloudFormationCustomResourceEvent event, Context context) {
return Response.success();
return Response.success(null);
}

@Override
protected Response update(CloudFormationCustomResourceEvent event, Context context) {
return Response.success();
return Response.success(null);
}

@Override
protected Response delete(CloudFormationCustomResourceEvent event, Context context) {
return Response.success();
return Response.success(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,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 Down Expand Up @@ -146,20 +129,6 @@ public static void withMetricsLogger(final Consumer<MetricsLogger> logger) {
}
}

/**
* Provide and immediately flush a {@link MetricsLogger}. It uses the default namespace
* specified either on {@link Metrics} annotation or via POWERTOOLS_METRICS_NAMESPACE env var.
* It by default captures function_request_id as property if used together with {@link Metrics} annotation. It will also
* capture xray_trace_id as property if tracing is enabled.
*
* @param logger the MetricsLogger
* @deprecated use {@link MetricsUtils#withMetricsLogger} instead
*/
@Deprecated
public static void withMetricLogger(final Consumer<MetricsLogger> logger) {
withMetricsLogger(logger);
}

public static DimensionSet[] getDefaultDimensions() {
return Arrays.copyOf(defaultDimensions, defaultDimensions.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,6 @@ void metricsLoggerCaptureUtilityWithDefaultNameSpace() {
testLogger(MetricsUtils::withMetricsLogger);
}

@Test
void deprecatedMetricLoggerCaptureUtilityWithDefaultNameSpace() {
testLogger(MetricsUtils::withMetricLogger);
}

@Test
void shouldThrowExceptionWhenDefaultDimensionIsNull() {
assertThatNullPointerException()
.isThrownBy(() -> MetricsUtils.defaultDimensionSet(null))
.withMessage("Null dimension set not allowed");
}

@Test
void shouldUseTraceIdFromSystemPropertyIfEnvVarNotPresent() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@
public @interface Tracing {
String namespace() default "";

/**
* @deprecated As of release 1.2.0, replaced by captureMode()
* in order to support different modes and support via
* environment variables
*/
@Deprecated
boolean captureResponse() default true;

/**
* @deprecated As of release 1.2.0, replaced by captureMode()
* in order to support different modes and support via
* environment variables
*/
@Deprecated
boolean captureError() default true;

String segmentName() default "";

CaptureMode captureMode() default CaptureMode.ENVIRONMENT_VAR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public Object around(ProceedingJoinPoint pjp,
private boolean captureResponse(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
boolean captureResponse = environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE") ? captureResponse :
powerToolsTracing.captureResponse();
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE")
&& environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
case RESPONSE:
case RESPONSE_AND_ERROR:
return true;
Expand All @@ -98,9 +97,8 @@ private boolean captureResponse(Tracing powerToolsTracing) {
private boolean captureError(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
boolean captureError = environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR") ? captureError :
powerToolsTracing.captureError();
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR")
&& environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
case ERROR:
case RESPONSE_AND_ERROR:
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledForStreamWithNoMetaData;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithException;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaData;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaDataDeprecated;
import software.amazon.lambda.powertools.tracing.nonhandler.PowerToolNonHandler;

class LambdaTracingAspectTest {
Expand Down Expand Up @@ -246,29 +245,6 @@ void shouldCaptureTracesForStreamWithNoMetadata() throws IOException {
});
}

@Test
void shouldCaptureTracesWithNoMetadataDeprecated() {
requestHandler = new PowerTracerToolEnabledWithNoMetaDataDeprecated();

requestHandler.handleRequest(new Object(), context);

assertThat(AWSXRay.getTraceEntity())
.isNotNull();

assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
.hasSize(1)
.allSatisfy(subsegment ->
{
assertThat(subsegment.getAnnotations())
.hasSize(2)
.containsEntry("ColdStart", true)
.containsEntry("Service", "service_undefined");

assertThat(subsegment.getMetadata())
.isEmpty();
});
}

@Test
void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
Expand Down
Loading