|
13 | 13 | import io.micrometer.datadog.DatadogMeterRegistry; |
14 | 14 | import io.micrometer.jmx.JmxConfig; |
15 | 15 | import io.micrometer.jmx.JmxMeterRegistry; |
| 16 | +import lombok.extern.slf4j.Slf4j; |
16 | 17 | import org.springframework.context.annotation.Bean; |
17 | 18 | import org.springframework.context.annotation.Configuration; |
18 | 19 |
|
19 | 20 | import java.security.GeneralSecurityException; |
20 | 21 | import java.time.Duration; |
21 | 22 |
|
22 | 23 | @Configuration |
| 24 | +@Slf4j |
23 | 25 | public class MicrometerConfig { |
24 | 26 | private static final String DECRYPTION_KEY = "supercalifragilisticexpialidocious"; |
25 | 27 |
|
26 | 28 | @Bean(name = "microMeterRegistry") |
27 | 29 | public MeterRegistry meterRegistry() { |
28 | 30 |
|
29 | 31 | final CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry(); |
30 | | - final SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry(); |
| 32 | + final MeterRegistry oneSimpleMeter = new SimpleMeterRegistry(); |
31 | 33 | 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); |
33 | 35 |
|
34 | 36 | compositeRegistry.add(oneSimpleMeter); |
35 | 37 | compositeRegistry.add(jmxRegistry); |
@@ -85,14 +87,19 @@ public boolean descriptions() { |
85 | 87 | }; |
86 | 88 | } |
87 | 89 |
|
88 | | - private static String decryptKey(AppResources appResources) { |
| 90 | + private static String decryptKey(final AppResources appResources) { |
89 | 91 | try { |
90 | 92 | return Crypt.decrypt(appResources.value(), DECRYPTION_KEY); |
91 | 93 | } 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()); |
94 | 96 | 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); |
96 | 103 | } |
97 | 104 | } |
98 | 105 | } |
0 commit comments