mirror of https://github.com/apache/lucene.git
SOLR-11281: Remove the diagnostic additions and apply a patch from Jason Gerlowski.
This commit is contained in:
parent
f5c2e10222
commit
40f999b08e
|
@ -57,7 +57,6 @@ public class SolrSlf4jReporter extends FilteringSolrMetricReporter {
|
|||
private String logger = null;
|
||||
private Slf4jReporter reporter;
|
||||
private boolean active;
|
||||
private DiagnosticMetricRegistry diagnosticMetricRegistry;
|
||||
|
||||
/**
|
||||
* Create a SLF4J reporter for metrics managed in a named registry.
|
||||
|
@ -85,10 +84,8 @@ public class SolrSlf4jReporter extends FilteringSolrMetricReporter {
|
|||
} else {
|
||||
instancePrefix = instancePrefix + "." + registryName;
|
||||
}
|
||||
MetricRegistry registry = metricManager.registry(registryName);
|
||||
diagnosticMetricRegistry = new DiagnosticMetricRegistry(registry);
|
||||
Slf4jReporter.Builder builder = Slf4jReporter
|
||||
.forRegistry(diagnosticMetricRegistry)
|
||||
.forRegistry(metricManager.registry(registryName))
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.convertDurationsTo(TimeUnit.MILLISECONDS);
|
||||
|
||||
|
@ -133,43 +130,4 @@ public class SolrSlf4jReporter extends FilteringSolrMetricReporter {
|
|||
boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
// for unit tests
|
||||
int getCount() {
|
||||
return diagnosticMetricRegistry != null ? diagnosticMetricRegistry.count : -1;
|
||||
}
|
||||
|
||||
static class DiagnosticMetricRegistry extends MetricRegistry {
|
||||
MetricRegistry delegate;
|
||||
int count = 0;
|
||||
DiagnosticMetricRegistry(MetricRegistry delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, Counter> getCounters(MetricFilter filter) {
|
||||
return delegate.getCounters(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, Histogram> getHistograms(MetricFilter filter) {
|
||||
return delegate.getHistograms(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, Meter> getMeters(MetricFilter filter) {
|
||||
return delegate.getMeters(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, Timer> getTimers(MetricFilter filter) {
|
||||
return delegate.getTimers(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, Gauge> getGauges(MetricFilter filter) {
|
||||
count++;
|
||||
return delegate.getGauges(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.solr.metrics.reporters;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
@ -34,14 +35,18 @@ import org.apache.solr.metrics.SolrMetricManager;
|
|||
import org.apache.solr.metrics.SolrMetricReporter;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SolrSlf4jReporterTest extends SolrTestCaseJ4 {
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
@Test
|
||||
public void testReporter() throws Exception {
|
||||
ensureLoggingConfiguredAppropriately();
|
||||
LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100);
|
||||
LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null);
|
||||
watcher.setThreshold("INFO");
|
||||
|
@ -78,19 +83,20 @@ public class SolrSlf4jReporterTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
Thread.sleep(5000);
|
||||
|
||||
int count1 = ((SolrSlf4jReporter)reporter1).getCount();
|
||||
assertTrue("test1 count should be greater than 0", count1 > 0);
|
||||
int count2 = ((SolrSlf4jReporter)reporter2).getCount();
|
||||
assertTrue("test2 count should be greater than 0", count1 > 0);
|
||||
|
||||
SolrDocumentList history = watcher.getHistory(-1, null);
|
||||
// dot-separated names are treated like class names and collapsed
|
||||
// in regular log output, but here we get the full name
|
||||
if (history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() == 0) {
|
||||
fail("count1=" + count1 + ", count2=" + count2 + " - no 'solr.node' logs in: " + history.toString());
|
||||
fail("No 'solr.node' logs in: " + history.toString());
|
||||
}
|
||||
if (history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() == 0) {
|
||||
fail("count1=" + count1 + ", count2=" + count2 + " - no 'foobar' logs in: " + history.toString());
|
||||
fail("No 'foobar' logs in: " + history.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureLoggingConfiguredAppropriately() throws Exception {
|
||||
if (! log.isInfoEnabled()) {
|
||||
fail("Test requires that log-level is at-least INFO, but INFO is disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue