Skip to content

Commit 4085b0d

Browse files
committed
Fix SonarCube findings.
1 parent 17c865d commit 4085b0d

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspect.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class LambdaMetricsAspect {
3838
public static final String TRACE_ID_PROPERTY = "xray_trace_id";
3939
public static final String REQUEST_ID_PROPERTY = "function_request_id";
40+
private static final String SERVICE_DIMENSION = "Service";
4041

4142
private String functionName(Metrics metrics, Context context) {
4243
if (!"".equals(metrics.functionName())) {
@@ -76,8 +77,8 @@ public Object around(ProceedingJoinPoint pjp,
7677
// default dimension.
7778
if (!"".equals(metrics.service())
7879
&& logger.getDefaultDimensions().getDimensionKeys().size() <= 1
79-
&& logger.getDefaultDimensions().getDimensionKeys().contains("Service")) {
80-
logger.setDefaultDimensions(Map.of("Service", metrics.service()));
80+
&& logger.getDefaultDimensions().getDimensionKeys().contains(SERVICE_DIMENSION)) {
81+
logger.setDefaultDimensions(Map.of(SERVICE_DIMENSION, metrics.service()));
8182
}
8283

8384
logger.setRaiseOnEmptyMetrics(metrics.raiseOnEmptyMetrics());
@@ -98,8 +99,8 @@ public Object around(ProceedingJoinPoint pjp,
9899

99100
// Create dimensions with service and function name
100101
DimensionSet coldStartDimensions = DimensionSet.of(
101-
"Service",
102-
logger.getDefaultDimensions().getDimensions().getOrDefault("Service",
102+
SERVICE_DIMENSION,
103+
logger.getDefaultDimensions().getDimensions().getOrDefault(SERVICE_DIMENSION,
103104
serviceNameWithFallback(metrics)),
104105
"FunctionName", funcName != null ? funcName : extractedContext.getFunctionName());
105106

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/MetricsLoggerFactoryTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MetricsLoggerFactoryTest {
4545
private final ObjectMapper objectMapper = new ObjectMapper();
4646

4747
@BeforeEach
48-
public void setUp() throws Exception {
48+
void setUp() throws Exception {
4949
System.setOut(new PrintStream(outputStreamCaptor));
5050

5151
// Reset LambdaHandlerProcessor's SERVICE_NAME
@@ -60,7 +60,7 @@ public void setUp() throws Exception {
6060
}
6161

6262
@AfterEach
63-
public void tearDown() throws Exception {
63+
void tearDown() throws Exception {
6464
System.setOut(standardOut);
6565

6666
// Reset the singleton state between tests
@@ -74,7 +74,7 @@ public void tearDown() throws Exception {
7474
}
7575

7676
@Test
77-
public void shouldGetMetricsLoggerInstance() {
77+
void shouldGetMetricsLoggerInstance() {
7878
// When
7979
MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
8080

@@ -83,7 +83,7 @@ public void shouldGetMetricsLoggerInstance() {
8383
}
8484

8585
@Test
86-
public void shouldReturnSameInstanceOnMultipleCalls() {
86+
void shouldReturnSameInstanceOnMultipleCalls() {
8787
// When
8888
MetricsLogger firstInstance = MetricsLoggerFactory.getMetricsLogger();
8989
MetricsLogger secondInstance = MetricsLoggerFactory.getMetricsLogger();
@@ -94,7 +94,7 @@ public void shouldReturnSameInstanceOnMultipleCalls() {
9494

9595
@Test
9696
@SetEnvironmentVariable(key = "POWERTOOLS_METRICS_NAMESPACE", value = TEST_NAMESPACE)
97-
public void shouldUseNamespaceFromEnvironmentVariable() throws Exception {
97+
void shouldUseNamespaceFromEnvironmentVariable() throws Exception {
9898
// When
9999
MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
100100
metricsLogger.addMetric("test-metric", 100, MetricUnit.COUNT);
@@ -110,7 +110,7 @@ public void shouldUseNamespaceFromEnvironmentVariable() throws Exception {
110110

111111
@Test
112112
@SetEnvironmentVariable(key = "POWERTOOLS_SERVICE_NAME", value = TEST_SERVICE)
113-
public void shouldUseServiceNameFromEnvironmentVariable() throws Exception {
113+
void shouldUseServiceNameFromEnvironmentVariable() throws Exception {
114114
// When
115115
MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
116116
metricsLogger.addMetric("test-metric", 100, MetricUnit.COUNT);
@@ -125,7 +125,7 @@ public void shouldUseServiceNameFromEnvironmentVariable() throws Exception {
125125
}
126126

127127
@Test
128-
public void shouldSetCustomMetricsProvider() {
128+
void shouldSetCustomMetricsProvider() {
129129
// Given
130130
MetricsProvider testProvider = new TestMetricsProvider();
131131

@@ -138,7 +138,7 @@ public void shouldSetCustomMetricsProvider() {
138138
}
139139

140140
@Test
141-
public void shouldThrowExceptionWhenSettingNullProvider() {
141+
void shouldThrowExceptionWhenSettingNullProvider() {
142142
// When/Then
143143
assertThatThrownBy(() -> MetricsLoggerFactory.setMetricsProvider(null))
144144
.isInstanceOf(IllegalArgumentException.class)

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/EmfMetricsLoggerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19-
import static org.mockito.Mockito.mock;
20-
import static org.mockito.Mockito.when;
2119

2220
import java.io.ByteArrayOutputStream;
2321
import java.io.PrintStream;

0 commit comments

Comments
 (0)