SOLR-10823: Add reporting period to SolrMetricReporter base class.

This commit is contained in:
Christine Poerschke 2017-06-26 16:26:37 +01:00
parent 7c448623cc
commit 44860bd48a
10 changed files with 31 additions and 38 deletions

View File

@ -517,6 +517,8 @@ Other Changes
with point fields and provides control over dynamic fields used for the raw amount and currency with point fields and provides control over dynamic fields used for the raw amount and currency
code sub-fields. (hossman, Steve Rowe) code sub-fields. (hossman, Steve Rowe)
* SOLR-10823: Add reporting period to SolrMetricReporter base class. (Christine Poerschke)
================== 6.6.1 ================== ================== 6.6.1 ==================
Bug Fixes Bug Fixes

View File

@ -36,6 +36,7 @@ public abstract class SolrMetricReporter implements Closeable, PluginInfoInitial
protected final SolrMetricManager metricManager; protected final SolrMetricManager metricManager;
protected PluginInfo pluginInfo; protected PluginInfo pluginInfo;
protected boolean enabled = true; protected boolean enabled = true;
protected int period = SolrMetricManager.DEFAULT_CLOUD_REPORTER_PERIOD;
/** /**
* Create a reporter for metrics managed in a named registry. * Create a reporter for metrics managed in a named registry.
@ -85,6 +86,20 @@ public abstract class SolrMetricReporter implements Closeable, PluginInfoInitial
} }
} }
/**
* @param period - in seconds
*/
public void setPeriod(int period) {
this.period = period;
}
/**
* @return period, in seconds
*/
public int getPeriod() {
return period;
}
/** /**
* Get the effective {@link PluginInfo} instance that was used for * Get the effective {@link PluginInfo} instance that was used for
* initialization of this plugin. * initialization of this plugin.

View File

@ -35,7 +35,6 @@ public class SolrGangliaReporter extends SolrMetricReporter {
private String host = null; private String host = null;
private int port = -1; private int port = -1;
private boolean multicast; private boolean multicast;
private int period = 60;
private String instancePrefix = null; private String instancePrefix = null;
private List<String> filters = new ArrayList<>(); private List<String> filters = new ArrayList<>();
private boolean testing; private boolean testing;
@ -88,10 +87,6 @@ public class SolrGangliaReporter extends SolrMetricReporter {
} }
} }
public void setPeriod(int period) {
this.period = period;
}
public void setMulticast(boolean multicast) { public void setMulticast(boolean multicast) {
this.multicast = multicast; this.multicast = multicast;
} }

View File

@ -36,7 +36,6 @@ public class SolrGraphiteReporter extends SolrMetricReporter {
private String host = null; private String host = null;
private int port = -1; private int port = -1;
private int period = 60;
private boolean pickled = false; private boolean pickled = false;
private String instancePrefix = null; private String instancePrefix = null;
private List<String> filters = new ArrayList<>(); private List<String> filters = new ArrayList<>();
@ -90,10 +89,6 @@ public class SolrGraphiteReporter extends SolrMetricReporter {
this.pickled = pickled; this.pickled = pickled;
} }
public void setPeriod(int period) {
this.period = period;
}
@Override @Override
protected void doInit() { protected void doInit() {
if (reporter != null) { if (reporter != null) {

View File

@ -70,6 +70,7 @@ public class SolrJmxReporter extends SolrMetricReporter {
*/ */
public SolrJmxReporter(SolrMetricManager metricManager, String registryName) { public SolrJmxReporter(SolrMetricManager metricManager, String registryName) {
super(metricManager, registryName); super(metricManager, registryName);
period = 0; // setting to zero to indicate not applicable
setDomain(registryName); setDomain(registryName);
} }
@ -151,7 +152,9 @@ public class SolrJmxReporter extends SolrMetricReporter {
*/ */
@Override @Override
protected void validate() throws IllegalStateException { protected void validate() throws IllegalStateException {
// Nothing to validate if (period != 0) {
throw new IllegalStateException("Init argument 'period' is not supported for "+getClass().getCanonicalName());
}
} }

View File

@ -47,7 +47,6 @@ public class SolrSlf4jReporter extends SolrMetricReporter {
@SuppressWarnings("unused") // we need this to pass validate-source-patterns @SuppressWarnings("unused") // we need this to pass validate-source-patterns
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private int period = 60;
private String instancePrefix = null; private String instancePrefix = null;
private String logger = null; private String logger = null;
private List<String> filters = new ArrayList<>(); private List<String> filters = new ArrayList<>();
@ -91,10 +90,6 @@ public class SolrSlf4jReporter extends SolrMetricReporter {
this.logger = logger; this.logger = logger;
} }
public void setPeriod(int period) {
this.period = period;
}
@Override @Override
protected void doInit() { protected void doInit() {
if (instancePrefix == null) { if (instancePrefix == null) {

View File

@ -124,7 +124,6 @@ public class SolrClusterReporter extends SolrMetricReporter {
}}; }};
private String handler = MetricsCollectorHandler.HANDLER_PATH; private String handler = MetricsCollectorHandler.HANDLER_PATH;
private int period = SolrMetricManager.DEFAULT_CLOUD_REPORTER_PERIOD;
private List<SolrReporter.Report> reports = new ArrayList<>(); private List<SolrReporter.Report> reports = new ArrayList<>();
private SolrReporter reporter; private SolrReporter reporter;
@ -143,10 +142,6 @@ public class SolrClusterReporter extends SolrMetricReporter {
this.handler = handler; this.handler = handler;
} }
public void setPeriod(int period) {
this.period = period;
}
public void setReport(List<Map> reportConfig) { public void setReport(List<Map> reportConfig) {
if (reportConfig == null || reportConfig.isEmpty()) { if (reportConfig == null || reportConfig.isEmpty()) {
return; return;
@ -169,11 +164,6 @@ public class SolrClusterReporter extends SolrMetricReporter {
} }
} }
// for unit tests
int getPeriod() {
return period;
}
List<SolrReporter.Report> getReports() { List<SolrReporter.Report> getReports() {
return reports; return reports;
} }
@ -187,7 +177,7 @@ public class SolrClusterReporter extends SolrMetricReporter {
@Override @Override
protected void validate() throws IllegalStateException { protected void validate() throws IllegalStateException {
// Nothing to validate // (period < 1) means "don't start reporter" and so no (period > 0) validation needed
} }
@Override @Override

View File

@ -70,7 +70,6 @@ public class SolrShardReporter extends SolrMetricReporter {
}}; }};
private String handler = MetricsCollectorHandler.HANDLER_PATH; private String handler = MetricsCollectorHandler.HANDLER_PATH;
private int period = SolrMetricManager.DEFAULT_CLOUD_REPORTER_PERIOD;
private List<String> filters = new ArrayList<>(); private List<String> filters = new ArrayList<>();
private SolrReporter reporter; private SolrReporter reporter;
@ -90,10 +89,6 @@ public class SolrShardReporter extends SolrMetricReporter {
this.handler = handler; this.handler = handler;
} }
public void setPeriod(int period) {
this.period = period;
}
public void setFilter(List<String> filterConfig) { public void setFilter(List<String> filterConfig) {
if (filterConfig == null || filterConfig.isEmpty()) { if (filterConfig == null || filterConfig.isEmpty()) {
return; return;
@ -107,11 +102,6 @@ public class SolrShardReporter extends SolrMetricReporter {
} }
} }
// for unit tests
int getPeriod() {
return period;
}
@Override @Override
protected void doInit() { protected void doInit() {
if (filters.isEmpty()) { if (filters.isEmpty()) {
@ -122,7 +112,7 @@ public class SolrShardReporter extends SolrMetricReporter {
@Override @Override
protected void validate() throws IllegalStateException { protected void validate() throws IllegalStateException {
// Nothing to validate // (period < 1) means "don't start reporter" and so no (period > 0) validation needed
} }
@Override @Override

View File

@ -249,6 +249,11 @@ public class SolrMetricManagerTest extends SolrTestCaseJ4 {
} }
@Test
public void testDefaultCloudReporterPeriodUnchanged() throws Exception {
assertEquals(60, SolrMetricManager.DEFAULT_CLOUD_REPORTER_PERIOD);
}
private PluginInfo createPluginInfo(String name, String group, String registry) { private PluginInfo createPluginInfo(String name, String group, String registry) {
Map<String,String> attrs = new HashMap<>(); Map<String,String> attrs = new HashMap<>();
attrs.put("name", name); attrs.put("name", name);

View File

@ -53,6 +53,9 @@ public class MockMetricReporter extends SolrMetricReporter {
if (configurable == null) { if (configurable == null) {
throw new IllegalStateException("MockMetricReporter::configurable not defined."); throw new IllegalStateException("MockMetricReporter::configurable not defined.");
} }
if (period < 1) {
throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
}
} }
public void setConfigurable(String configurable) { public void setConfigurable(String configurable) {