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

Do not fail completely when re-registering metrics with the same name #54

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

celandro
Copy link

Due to the way one of our legacy webapps integrates with spring, the spring context file is loaded 2 times instead of one. On the second time, it fails due to an IllegalArgumentException. This bug may be related to the other spring life cycle bug. This fix allows the reload to occur properly. This also handles more graceful accidental double registration of the same metrics.

My apologies for the long list of commits. I'm not sure how to reset my fork to your base

rbarker added 8 commits October 23, 2013 17:20
Conflicts:
	pom.xml
	src/main/java/com/ryantenney/metrics/spring/config/MetricsNamespaceHandler.java
	src/main/java/com/ryantenney/metrics/spring/reporter/GraphiteReporterElementParser.java
	src/main/resources/com/ryantenney/metrics/spring/config/metrics-3.0.xsd
@ryantenney
Copy link
Owner

Would it be alright to simply not register the metrics the second time?

@celandro
Copy link
Author

In theory yes. The real problem seems to be that the metrics registry is
not being recreated. If you provide me a proposed fix I can test it quickly.
On Dec 12, 2013 10:12 AM, "Ryan Tenney" [email protected] wrote:

Would it be alright to simply not register the metrics the second time?


Reply to this email directly or view it on GitHubhttps://github.com//pull/54#issuecomment-30446879
.

@ryantenney
Copy link
Owner

So the metric registry mostly likely isn't being recreated because of the name attribute. If you provide a name to metric-registry it calls SharedMetricRegistries.getOrCreate(name) which persists the MetricRegistry outside of the Spring lifecycle. I did that so it would be easier to access the metric registry from outside of Spring (in a servlet or servlet filter for example) If you don't need that, removing the name attribute would ensure the registry is re-created when the spring context reloads.

@davidkarlsen
Copy link
Contributor

I figured out some more, it only happens when I register the registry with a name like you say:
<metrics:metric-registry id="metricsRegistry" name="${metrics.registry.prefix}" />

But only when I have these added:

  <metrics:register metric-registry="metricsRegistry">
      <bean metrics:name="jvm.gc" class="com.codahale.metrics.jvm.GarbageCollectorMetricSet" />
      <bean metrics:name="jvm.classloading" class="com.codahale.metrics.jvm.ClassLoadingGaugeSet" />
      <bean metrics:name="jvm.memory" class="com.codahale.metrics.jvm.MemoryUsageGaugeSet" />
      <bean metrics:name="jvm.thread-states" class="com.codahale.metrics.jvm.ThreadStatesGaugeSet" />
      <bean metrics:name="jvm.fd.usage" class="com.codahale.metrics.jvm.FileDescriptorRatioGauge" />
  </metrics:register>

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.

3 participants