-
Notifications
You must be signed in to change notification settings - Fork 96
chore(metrics): deprecate withMetricLogger in favor of withMetricsLogger #1060
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
Changes from 4 commits
89f379a
876d17f
8f0105b
508bb7d
bc86d36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||
import java.io.ByteArrayOutputStream; | ||||||
import java.io.PrintStream; | ||||||
import java.util.Map; | ||||||
import java.util.function.Consumer; | ||||||
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|
@@ -12,6 +13,7 @@ | |||||
import org.junit.jupiter.api.Test; | ||||||
import org.mockito.MockedStatic; | ||||||
import software.amazon.cloudwatchlogs.emf.config.SystemWrapper; | ||||||
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger; | ||||||
import software.amazon.cloudwatchlogs.emf.model.DimensionSet; | ||||||
import software.amazon.cloudwatchlogs.emf.model.Unit; | ||||||
|
||||||
|
@@ -124,13 +126,29 @@ void singleMetricsCaptureUtilityWithDefaultNameSpace() { | |||||
|
||||||
@Test | ||||||
void metricsLoggerCaptureUtilityWithDefaultNameSpace() { | ||||||
testWithNewLogger(MetricsUtils::withMetricsLogger); | ||||||
} | ||||||
|
||||||
@Test | ||||||
void deprecatedMetricLoggerCaptureUtilityWithDefaultNameSpace() { | ||||||
testWithNewLogger(MetricsUtils::withMetricLogger); | ||||||
} | ||||||
|
||||||
@Test | ||||||
void shouldThrowExceptionWhenDefaultDimensionIsNull() { | ||||||
assertThatNullPointerException() | ||||||
.isThrownBy(() -> MetricsUtils.defaultDimensionSet(null)) | ||||||
.withMessage("Null dimension set not allowed"); | ||||||
} | ||||||
|
||||||
private void testWithNewLogger(Consumer<Consumer<MetricsLogger>> methodToTest) { | ||||||
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. strange to name it
Suggested change
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. New was as opposed to the default |
||||||
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class); | ||||||
MockedStatic<software.amazon.lambda.powertools.core.internal.SystemWrapper> internalWrapper = mockStatic(software.amazon.lambda.powertools.core.internal.SystemWrapper.class)) { | ||||||
mocked.when(() -> SystemWrapper.getenv("AWS_EMF_ENVIRONMENT")).thenReturn("Lambda"); | ||||||
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_METRICS_NAMESPACE")).thenReturn("GlobalName"); | ||||||
internalWrapper.when(() -> getenv("_X_AMZN_TRACE_ID")).thenReturn("Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1\""); | ||||||
|
||||||
MetricsUtils.withMetricLogger(metricsLogger -> { | ||||||
methodToTest.accept(metricsLogger -> { | ||||||
metricsLogger.setDimensions(DimensionSet.of("Dimension1", "Value1")); | ||||||
metricsLogger.putMetric("Metric1", 1, Unit.COUNT); | ||||||
}); | ||||||
|
@@ -154,13 +172,6 @@ void metricsLoggerCaptureUtilityWithDefaultNameSpace() { | |||||
} | ||||||
} | ||||||
|
||||||
@Test | ||||||
jeromevdl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
void shouldThrowExceptionWhenDefaultDimensionIsNull() { | ||||||
assertThatNullPointerException() | ||||||
.isThrownBy(() -> MetricsUtils.defaultDimensionSet(null)) | ||||||
.withMessage("Null dimension set not allowed"); | ||||||
} | ||||||
|
||||||
private Map<String, Object> readAsJson(String s) { | ||||||
try { | ||||||
return mapper.readValue(s, Map.class); | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.