Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

fix @Gauge and @CachedGauge annotation BeanPostProcessor bugs and add more tests #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

segeon
Copy link

@segeon segeon commented Sep 22, 2015

When I try to config metrics-spring using JavaConfig and add @Gauge and @CachedGauge annotation on methods, I can't get their metric info through jmx. Other annotations like @counted, @metered, @timed work well. I looked into the source code, and find some problem that may be bugs.

In GaugeMethodAnnotationBeanPostProcessor line 28, the "return ReflectionUtils.invokeMethod(method, bean); " statement throw out java.lang.IllegalArgumentException: object is not an instance of declaring class. To my understanding, the argument bean is a proxy object, while method is the original Method object of the proxy target. We can't just call method like this. One simple solution is to find out the proxy object's corresponding Method and call it like this:

return ReflectionUtils.invokeMethod(bean.getClass().getMethod(method.getName(), method.parameterTypes), bean);

CachedGaugeAnnotationBeanPostProcessor class has the same problem and can be fixed in the same way.

@ryantenney
Copy link
Owner

Can you help me understand why you're referencing MBeans?

MBeanProxyFactoryBean factoryBean = new MBeanProxyFactoryBean();
    try {
        factoryBean.setObjectName(new ObjectName("metrics", "name", com.ryantenney.metrics.spring.javaconfig.MetricServiceImpl.gaugeValue"));
    }
    …

@segeon
Copy link
Author

segeon commented Nov 18, 2015

By referencing MBeans, I'm trying to ensure that the Metrics can produce right values through JMX reporter.

@ryantenney
Copy link
Owner

Okay, thanks for clarifying. I'd rather not do any JMX testing in this project, as it's already thoroughly tested by JmxReporterTest in Metrics.

The resolution of the issue you're seeing shouldn't be to look up the method on every call to get/loadValue in the Gauge. Perhaps we can to check if the bean is an instance of Advised, and then grab the target object, and invoke the gauged method on that. I'll do some work on this and get back to you.

@selslack
Copy link

Any updates on this?

@madhurir12
Copy link

Any update on this issue? I am seeing the same error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants