diff --git a/src/main/java/hlf/java/rest/client/config/CustomTxnListenerMetricsConfig.java b/src/main/java/hlf/java/rest/client/config/CustomTxnListenerMetricsConfig.java index 24de439..7994b0c 100644 --- a/src/main/java/hlf/java/rest/client/config/CustomTxnListenerMetricsConfig.java +++ b/src/main/java/hlf/java/rest/client/config/CustomTxnListenerMetricsConfig.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration; @Configuration -@ConditionalOnProperty("kafka.event-listener.brokerHost") +@ConditionalOnProperty("kafka.integration-points[0].brokerHost") public class CustomTxnListenerMetricsConfig { @Bean @@ -15,18 +15,18 @@ public Counter customKafkaSuccessCounter(MeterRegistry meterRegistry) { return meterRegistry.counter("kafka.messages.processed.messages"); } - @Bean - public Counter customKafkaFailureCounter(MeterRegistry meterRegistry) { - return meterRegistry.counter("kafka.messages.failed.messages"); - } - @Bean public Counter invalidInboundTransactionMessageCounter(MeterRegistry meterRegistry) { - return meterRegistry.counter("transaction.messages.unrecognized"); + return meterRegistry.counter("transaction.messages.unrecognized.failures"); } @Bean public Counter inboundTxnProcessingFailureCounter(MeterRegistry meterRegistry) { return meterRegistry.counter("transaction.messages.process.failures"); } + + @Bean + public Counter inboundTxnContractExceptionCounter(MeterRegistry meterRegistry) { + return meterRegistry.counter("transaction.messages.contract.failures"); + } } diff --git a/src/main/java/hlf/java/rest/client/metrics/EmitCustomTransactionListenerMetricsAspect.java b/src/main/java/hlf/java/rest/client/metrics/EmitCustomTransactionListenerMetricsAspect.java index 263d85b..e3898e9 100644 --- a/src/main/java/hlf/java/rest/client/metrics/EmitCustomTransactionListenerMetricsAspect.java +++ b/src/main/java/hlf/java/rest/client/metrics/EmitCustomTransactionListenerMetricsAspect.java @@ -5,11 +5,14 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; +import org.hyperledger.fabric.gateway.ContractException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @Aspect @Component +@ConditionalOnProperty("kafka.integration-points[0].brokerHost") public class EmitCustomTransactionListenerMetricsAspect { private static final String ANNOTATION_NAME = @@ -17,12 +20,12 @@ public class EmitCustomTransactionListenerMetricsAspect { @Autowired private Counter customKafkaSuccessCounter; - @Autowired private Counter customKafkaFailureCounter; - @Autowired private Counter invalidInboundTransactionMessageCounter; @Autowired private Counter inboundTxnProcessingFailureCounter; + @Autowired private Counter inboundTxnContractExceptionCounter; + @Around("@annotation(" + ANNOTATION_NAME + ")") public Object interceptedKafkaMetricsEmissionAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { @@ -33,14 +36,15 @@ public Object interceptedKafkaMetricsEmissionAdvice(ProceedingJoinPoint proceedi return returnValue; } catch (Throwable e) { - customKafkaFailureCounter.increment(); - if (e instanceof UnrecognizedTransactionPayloadException) { invalidInboundTransactionMessageCounter.increment(); - } else { - inboundTxnProcessingFailureCounter.increment(); } + if (e instanceof ContractException) { + inboundTxnContractExceptionCounter.increment(); + } + + inboundTxnProcessingFailureCounter.increment(); throw e; } }