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

@Gauge and @CachedGauge annotation do not work properly on methods when using JavaConfig #141

Closed
segeon opened this issue Sep 18, 2015 · 2 comments

Comments

@segeon
Copy link

segeon commented Sep 18, 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.

@segeon segeon changed the title @Gauge and @CachedGauge annotation do not work on methods @Gauge and @CachedGauge annotation do not work properly on methods when using JavaConfig Sep 21, 2015
@bwinant
Copy link

bwinant commented Sep 29, 2015

I am also encountering this exact issue. Would be great to see the pull request with the fix accepted

@ryantenney
Copy link
Owner

Tracking in #142

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

No branches or pull requests

3 participants