Skip to content

Commit

Permalink
Update counter metrics for Txn handling
Browse files Browse the repository at this point in the history
Signed-off-by: “Nithin <[email protected]>
  • Loading branch information
“Nithin committed Mar 13, 2024
1 parent ffc3866 commit e6d109b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty("kafka.event-listener.brokerHost")
@ConditionalOnProperty("kafka.integration-points[0].brokerHost")
public class CustomTxnListenerMetricsConfig {

@Bean
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
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 =
"hlf.java.rest.client.metrics.EmitCustomTransactionListenerMetrics";

@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 {
Expand All @@ -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;
}
}
Expand Down

0 comments on commit e6d109b

Please sign in to comment.