Skip to content

Commit

Permalink
Merge f2561ea into e6d01ee
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Nov 7, 2019
2 parents e6d01ee + f2561ea commit d251107
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

## [1.2.5] - 2019-11-07
### Fixed
- Do nothing if InterceptorContext has no parameters, fixes error output when there are no parameters

### Changed
- Updated to framework parent pom version 1.13.0
- Updated to common-bom version 2.4.0
- Updated to test-utils version 1.24.3

## [1.2.3] - 2017-11-29

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import static uk.gov.justice.metrics.agent.wildfly.util.ReflectionUtil.invokeMethod;

import uk.gov.justice.metrics.agent.artemis.agent.common.TimerContext;
import uk.gov.justice.metrics.agent.wildfly.util.ReflectionUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.function.BiConsumer;

Expand All @@ -27,15 +24,19 @@ public void onExit(Object interceptor, Object interceptorContext) {
}

private void collectMetrics(final Object interceptor, final Object interceptorContext, final BiConsumer<TimerContext, Object> timerContextOperation) {

if (firstInterceptorInChain(interceptor)) {

try {
final Optional<Object> coreMessage = coreMessageFrom(interceptorContext);

if (coreMessage.isPresent()) {
final Object messageId = messageIdOf(coreMessage.get()).get();
final TimerContext timerContext = timerContextOf(coreMessage.get());
timerContextOperation.accept(timerContext, messageId);
}
} catch (Exception e) {

} catch (final Exception e) {
LOGGER.error(INTROSPECTION_ERROR, e);
}
}
Expand All @@ -50,15 +51,21 @@ private Optional<Object> messageIdOf(final Object coreMessage) throws Reflective
}

private TimerContext timerContextOf(final Object coreMessage) throws ReflectiveOperationException {

final Object address = invokeMethod(coreMessage, "getAddress").get();
final Object action = invokeMethod(coreMessage, "getStringProperty", "CPPNAME").get();
return WildflyJmsMetricsTimerContextFactory.timerContextOf(address, action);
}

private Optional<Object> coreMessageFrom(final Object interceptorContext) throws ReflectiveOperationException {
final Object parameters = invokeMethod(interceptorContext, "getParameters").get();
Object amqMessage = ((Object[]) parameters)[0];
return invokeMethod(amqMessage, "getCoreMessage");

final Object[] parameters = (Object[]) invokeMethod(interceptorContext, "getParameters").get();

if (parameters.length > 0) {
return invokeMethod(parameters[0], "getCoreMessage");
}

return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public void shouldNotCollectMetricsIfActiveMQMessageNotInContext() {
assertThat(TimerRegistry.timerOf("wildfly.jms.queue.abc-contextname.actionname").getCount(), is(0L));
}

@Test
public void shouldNotCollectMetricsIfNoParametersInContext() {
agentHelper.onEntry(INITIAL_INTERCEPTOR, new InterceptorContext());
agentHelper.onExit(INITIAL_INTERCEPTOR, new InterceptorContext());
assertThat(TimerRegistry.timerOf("wildfly.jms.queue.abc-contextname.actionname").getCount(), is(0L));
}

@Test
public void shouldNotCollectMetricsIfNotInitialInterceptor() {
final Message message = new ActiveMQTextMessage(new TestClientMessage(127, "jms.queue.abc", "contextname.actionname"), null);
Expand All @@ -73,7 +80,6 @@ public void shouldNotCollectMetricsIfNotInitialInterceptor() {

}


@Test
public void shouldLogErrorInCaseExcpectedMethodNotFoundInPassedObject() {
final TestAppender appender = new TestAppender();
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<parent>
<groupId>uk.gov.justice</groupId>
<artifactId>maven-framework-parent-pom</artifactId>
<version>1.7.0</version>
<version>1.13.0</version>
</parent>
<artifactId>metrics-agent</artifactId>
<version>1.2.4-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<common-bom.version>1.22.0</common-bom.version>
<test-utils.version>1.13.1</test-utils.version>
<common-bom.version>2.4.0</common-bom.version>
<test-utils.version>1.24.3</test-utils.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit d251107

Please sign in to comment.