Skip to content

Commit ff5e924

Browse files
committed
Tightup implementation.
1 parent 91acdc3 commit ff5e924

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

essentialprogramming-api/src/main/java/com/api/config/MetricsFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public MetricsFilter(ResourceInfo resourceInfo, MeterRegistry meterRegistry) {
2828

2929
counters.put(fullMethodName, Counter
3030
.builder(METRIC_KEY + "." + controllerName + "." + methodName)
31-
.description("count of endpoint calls " + getHttpMethod(resourceInfo) + " : " + endpointPath)
31+
.description("counter of API requests " + getHttpMethod(resourceInfo) + " : " + endpointPath)
3232
.register(meterRegistry));
3333
}
3434

essentialprogramming-api/src/main/java/com/config/MicrometerConfig.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@
1313
import io.micrometer.datadog.DatadogMeterRegistry;
1414
import io.micrometer.jmx.JmxConfig;
1515
import io.micrometer.jmx.JmxMeterRegistry;
16+
import lombok.extern.slf4j.Slf4j;
1617
import org.springframework.context.annotation.Bean;
1718
import org.springframework.context.annotation.Configuration;
1819

1920
import java.security.GeneralSecurityException;
2021
import java.time.Duration;
2122

2223
@Configuration
24+
@Slf4j
2325
public class MicrometerConfig {
2426
private static final String DECRYPTION_KEY = "supercalifragilisticexpialidocious";
2527

2628
@Bean(name = "microMeterRegistry")
2729
public MeterRegistry meterRegistry() {
2830

2931
final CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry();
30-
final SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry();
32+
final MeterRegistry oneSimpleMeter = new SimpleMeterRegistry();
3133
final MeterRegistry jmxRegistry = new JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM);
32-
final DatadogMeterRegistry datadogMeterRegistry = new DatadogMeterRegistry(configureDatadog(), Clock.SYSTEM);
34+
final MeterRegistry datadogMeterRegistry = new DatadogMeterRegistry(configureDatadog(), Clock.SYSTEM);
3335

3436
compositeRegistry.add(oneSimpleMeter);
3537
compositeRegistry.add(jmxRegistry);
@@ -85,14 +87,19 @@ public boolean descriptions() {
8587
};
8688
}
8789

88-
private static String decryptKey(AppResources appResources) {
90+
private static String decryptKey(final AppResources appResources) {
8991
try {
9092
return Crypt.decrypt(appResources.value(), DECRYPTION_KEY);
9193
} catch (GeneralSecurityException e) {
92-
93-
if (appResources.equals(AppResources.DATADOG_API_KEY)) {
94+
if (AppResources.DATADOG_API_KEY.equals(appResources)) {
95+
log.error(ErrorCode.UNABLE_TO_DECRYPT_API_KEY.getCode(), ErrorCode.UNABLE_TO_DECRYPT_API_KEY.getDescription());
9496
throw new ServiceException(ErrorCode.UNABLE_TO_DECRYPT_API_KEY, e);
95-
} else throw new ServiceException(ErrorCode.UNABLE_TO_DECRYPT_APPLICATION_KEY, e);
97+
}
98+
if (AppResources.DATADOG_APPLICATION_KEY.equals(appResources)) {
99+
log.error(ErrorCode.UNABLE_TO_DECRYPT_APPLICATION_KEY.getCode(), ErrorCode.UNABLE_TO_DECRYPT_APPLICATION_KEY.getDescription());
100+
throw new ServiceException(ErrorCode.UNABLE_TO_DECRYPT_APPLICATION_KEY, e);
101+
}
102+
throw new RuntimeException("Wrong argument provided", e);
96103
}
97104
}
98105
}

0 commit comments

Comments
 (0)