-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#355 - Solr FilterCache Memory Leak - Replace SolrInfoBean in NRMetric with String
- Loading branch information
Showing
14 changed files
with
392 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...0/src/test/java/com/agent/instrumentation/solr/SolrMetricManagerInstrumentationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.agent.instrumentation.solr; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.agent.bridge.NoOpPrivateApi; | ||
import com.newrelic.agent.introspec.InstrumentationTestConfig; | ||
import com.newrelic.agent.introspec.InstrumentationTestRunner; | ||
|
||
import org.apache.solr.core.SolrInfoBean; | ||
import org.apache.solr.metrics.MetricsMap; | ||
import org.apache.solr.metrics.SolrMetricManager; | ||
import org.apache.solr.store.blockcache.Metrics; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
|
||
@RunWith(InstrumentationTestRunner.class) | ||
@InstrumentationTestConfig(includePrefixes = { "org.apache.solr.metrics" }) | ||
public class SolrMetricManagerInstrumentationTests { | ||
|
||
@Before | ||
public void before() { | ||
MetricUtil.clearRegistry("exampleRegistry"); | ||
MetricUtil.clearRegistry("targetRegistry"); | ||
} | ||
|
||
@Test | ||
public void register() { | ||
//Given | ||
AgentBridge.privateApi = new NoOpPrivateApi(); | ||
SolrMetricManager solrMetricManager = new SolrMetricManager(); | ||
SolrInfoBean solrInfoBean = new Metrics(); | ||
MetricsMap metricsMap = new MetricsMap((detailed, map) -> map.put("exampleMetric", 100)); | ||
|
||
//When | ||
solrMetricManager.register(solrInfoBean, "exampleRegistry", metricsMap, false,"filterCache", "hdfsBlockCache"); | ||
|
||
//Then | ||
int metricsReported = MetricUtil.getMetrics().values().stream().map(NRMetric::reportMetrics).mapToInt(Integer::intValue).sum(); | ||
assertEquals(1, metricsReported); | ||
|
||
String registryName = MetricUtil.getMetrics().values().stream().map(x -> x.registry).collect(Collectors.joining()); | ||
assertEquals("exampleRegistry", registryName); | ||
} | ||
|
||
@Test | ||
public void removeRegistry() { | ||
//Given | ||
AgentBridge.privateApi = new NoOpPrivateApi(); | ||
SolrMetricManager solrMetricManager = new SolrMetricManager(); | ||
SolrInfoBean solrInfoBean = new Metrics(); | ||
MetricsMap metricsMap = new MetricsMap((detailed, map) -> map.put("exampleMetric", 100)); | ||
|
||
//When | ||
solrMetricManager.register(solrInfoBean, "exampleRegistry", metricsMap, false,"filterCache", "hdfsBlockCache"); | ||
solrMetricManager.removeRegistry("exampleRegistry"); | ||
|
||
//Then | ||
int metricsReported = MetricUtil.getMetrics().values().stream().map(NRMetric::reportMetrics).mapToInt(Integer::intValue).sum(); | ||
assertEquals(0, metricsReported); | ||
} | ||
|
||
@Test | ||
public void clearRegistry() { | ||
//Given | ||
AgentBridge.privateApi = new NoOpPrivateApi(); | ||
SolrMetricManager solrMetricManager = new SolrMetricManager(); | ||
SolrInfoBean solrInfoBean = new Metrics(); | ||
MetricsMap metricsMap = new MetricsMap((detailed, map) -> map.put("exampleMetric", 100)); | ||
|
||
//When | ||
solrMetricManager.register(solrInfoBean, "exampleRegistry", metricsMap, false,"filterCache", "hdfsBlockCache"); | ||
solrMetricManager.clearRegistry("exampleRegistry"); | ||
|
||
//Then | ||
int metricsReported = MetricUtil.getMetrics().values().stream().map(NRMetric::reportMetrics).mapToInt(Integer::intValue).sum(); | ||
assertEquals(0, metricsReported); | ||
} | ||
|
||
@Test | ||
public void clearMetrics() { | ||
//Given | ||
AgentBridge.privateApi = new NoOpPrivateApi(); | ||
SolrMetricManager solrMetricManager = new SolrMetricManager(); | ||
SolrInfoBean solrInfoBean = new Metrics(); | ||
MetricsMap metricsMap = new MetricsMap((detailed, map) -> map.put("exampleMetric", 100)); | ||
|
||
//When | ||
solrMetricManager.register(solrInfoBean, "exampleRegistry", metricsMap, false,"filterCache", "hdfsBlockCache"); | ||
solrMetricManager.clearMetrics("exampleRegistry", "hdfsBlockCache"); | ||
|
||
//Then | ||
int metricsReported = MetricUtil.getMetrics().values().stream().map(NRMetric::reportMetrics).mapToInt(Integer::intValue).sum(); | ||
assertEquals(0, metricsReported); | ||
} | ||
|
||
@Test | ||
public void swapRegistries() { | ||
//Given | ||
AgentBridge.privateApi = new NoOpPrivateApi(); | ||
SolrMetricManager solrMetricManager = new SolrMetricManager(); | ||
SolrInfoBean solrInfoBean = new Metrics(); | ||
MetricsMap metricsMap = new MetricsMap((detailed, map) -> map.put("exampleMetric", 100)); | ||
|
||
//When | ||
solrMetricManager.register(solrInfoBean, "exampleRegistry", metricsMap, false,"filterCache", "hdfsBlockCache"); | ||
solrMetricManager.swapRegistries("exampleRegistry", "targetRegistry"); | ||
|
||
//Then | ||
int metricsReported = MetricUtil.getMetrics().values().stream().map(NRMetric::reportMetrics).mapToInt(Integer::intValue).sum(); | ||
assertEquals(1, metricsReported); | ||
|
||
String registryName = MetricUtil.getMetrics().values().stream().map(x -> x.registry).collect(Collectors.joining()); | ||
assertEquals("targetRegistry", registryName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.