mirror of https://github.com/apache/lucene.git
SOLR-12461: Upgrade Dropwizard Metrics to 4.0.5 release.
This commit is contained in:
parent
f46ba5227e
commit
bd8905150d
|
@ -58,13 +58,12 @@ com.sun.jersey.version = 1.19
|
|||
/commons-io/commons-io = 2.5
|
||||
/commons-logging/commons-logging = 1.1.3
|
||||
/de.l3s.boilerpipe/boilerpipe = 1.1.0
|
||||
/info.ganglia.gmetric4j/gmetric4j = 1.0.7
|
||||
|
||||
io.dropwizard.metrics.version = 3.2.6
|
||||
io.dropwizard.metrics.version = 4.0.5
|
||||
/io.dropwizard.metrics/metrics-core = ${io.dropwizard.metrics.version}
|
||||
/io.dropwizard.metrics/metrics-ganglia = ${io.dropwizard.metrics.version}
|
||||
/io.dropwizard.metrics/metrics-graphite = ${io.dropwizard.metrics.version}
|
||||
/io.dropwizard.metrics/metrics-jetty9 = ${io.dropwizard.metrics.version}
|
||||
/io.dropwizard.metrics/metrics-jmx = ${io.dropwizard.metrics.version}
|
||||
/io.dropwizard.metrics/metrics-jvm = ${io.dropwizard.metrics.version}
|
||||
|
||||
io.netty.netty-all.version = 4.0.52.Final
|
||||
|
|
|
@ -98,6 +98,9 @@ Upgrade Notes
|
|||
now Solr followed an obscure convention of updating only the first collection from the list, which usually was not what
|
||||
the user intended. This change explicitly rejects such update requests.
|
||||
|
||||
* SolrGangliaReporter has been removed from Solr because support for Ganglia has been removed from Dropwizard Metrics 4
|
||||
due to a transitive dependency on LGPL.
|
||||
|
||||
|
||||
New Features
|
||||
----------------------
|
||||
|
@ -284,6 +287,8 @@ Other Changes
|
|||
|
||||
* SOLR-13409: Disable HTML directory listings in admin interface to prevent possible security issues (Uwe Schindler)
|
||||
|
||||
* SOLR-12461: Upgrade Dropwizard Metrics to 4.0.5 release. (ab)
|
||||
|
||||
================== 8.0.0 ==================
|
||||
|
||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
# Set to true to activate the JMX RMI connector to allow remote JMX client applications
|
||||
# to monitor the JVM hosting Solr; set to "false" to disable that behavior
|
||||
# (false is recommended in production environments)
|
||||
#ENABLE_REMOTE_JMX_OPTS="false"
|
||||
ENABLE_REMOTE_JMX_OPTS="true"
|
||||
|
||||
# The script will use SOLR_PORT+10000 for the RMI_PORT or you can set it here
|
||||
# RMI_PORT=18983
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.solr.metrics;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.codahale.metrics.Clock;
|
||||
|
@ -58,7 +60,17 @@ public class MetricSuppliers {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Clock CPU_CLOCK = new Clock.CpuTimeClock();
|
||||
// back-compat implementation, no longer present in metrics-4
|
||||
private static final class CpuTimeClock extends Clock {
|
||||
private static final ThreadMXBean THREAD_MX_BEAN = ManagementFactory.getThreadMXBean();
|
||||
|
||||
@Override
|
||||
public long getTick() {
|
||||
return THREAD_MX_BEAN.getCurrentThreadCpuTime();
|
||||
}
|
||||
}
|
||||
|
||||
private static final Clock CPU_CLOCK = new CpuTimeClock();
|
||||
private static final Clock USER_CLOCK = new Clock.UserTimeClock();
|
||||
|
||||
/** Clock type parameter. */
|
||||
|
@ -73,7 +85,7 @@ public class MetricSuppliers {
|
|||
* or initArgs:
|
||||
* <ul>
|
||||
* <li>clock - (string) can be set to {@link #CLOCK_USER} for {@link com.codahale.metrics.Clock.UserTimeClock} or
|
||||
* {@link #CLOCK_CPU} for {@link com.codahale.metrics.Clock.CpuTimeClock}. If not set then the value of
|
||||
* {@link #CLOCK_CPU} for {@link CpuTimeClock}. If not set then the value of
|
||||
* {@link Clock#defaultClock()} will be used.</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.solr.metrics.reporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.codahale.metrics.MetricFilter;
|
||||
import com.codahale.metrics.ganglia.GangliaReporter;
|
||||
import info.ganglia.gmetric4j.gmetric.GMetric;
|
||||
|
||||
import org.apache.solr.metrics.FilteringSolrMetricReporter;
|
||||
import org.apache.solr.metrics.SolrMetricManager;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SolrGangliaReporter extends FilteringSolrMetricReporter {
|
||||
|
||||
private String host = null;
|
||||
private int port = -1;
|
||||
private boolean multicast;
|
||||
private String instancePrefix = null;
|
||||
private boolean testing;
|
||||
private GangliaReporter reporter;
|
||||
|
||||
private static final ReporterClientCache<GMetric> serviceRegistry = new ReporterClientCache<>();
|
||||
|
||||
// for unit tests
|
||||
GMetric ganglia = null;
|
||||
|
||||
/**
|
||||
* Create a Ganglia reporter for metrics managed in a named registry.
|
||||
*
|
||||
* @param metricManager metric manager instance that manages the selected registry
|
||||
* @param registryName registry to use, one of registries managed by
|
||||
* {@link SolrMetricManager}
|
||||
*/
|
||||
public SolrGangliaReporter(SolrMetricManager metricManager, String registryName) {
|
||||
super(metricManager, registryName);
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.instancePrefix = prefix;
|
||||
}
|
||||
|
||||
public void setMulticast(boolean multicast) {
|
||||
this.multicast = multicast;
|
||||
}
|
||||
|
||||
// only for unit tests!
|
||||
public void setTesting(boolean testing) {
|
||||
this.testing = testing;
|
||||
}
|
||||
|
||||
void setGMetric(GMetric ganglia) {
|
||||
this.ganglia = ganglia;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
if (!testing) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate() throws IllegalStateException {
|
||||
if (host == null) {
|
||||
throw new IllegalStateException("Init argument 'host' must be set to a valid Ganglia server name.");
|
||||
}
|
||||
if (port == -1) {
|
||||
throw new IllegalStateException("Init argument 'port' must be set to a valid Ganglia server port.");
|
||||
}
|
||||
if (period < 1) {
|
||||
throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
|
||||
}
|
||||
}
|
||||
|
||||
//this is a separate method for unit tests
|
||||
void start() {
|
||||
if (!testing) {
|
||||
String id = host + ":" + port + ":" + multicast;
|
||||
ganglia = serviceRegistry.getOrCreate(id, () -> new GMetric(host, port,
|
||||
multicast ? GMetric.UDPAddressingMode.MULTICAST : GMetric.UDPAddressingMode.UNICAST,
|
||||
1));
|
||||
if (ganglia == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (instancePrefix == null) {
|
||||
instancePrefix = registryName;
|
||||
} else {
|
||||
instancePrefix = instancePrefix + "." + registryName;
|
||||
}
|
||||
GangliaReporter.Builder builder = GangliaReporter
|
||||
.forRegistry(metricManager.registry(registryName))
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
||||
.prefixedWith(instancePrefix);
|
||||
final MetricFilter filter = newMetricFilter();
|
||||
builder = builder.filter(filter);
|
||||
reporter = builder.build(ganglia);
|
||||
reporter.start(period, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (reporter != null) {
|
||||
reporter.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ import javax.management.MBeanServer;
|
|||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.codahale.metrics.JmxReporter;
|
||||
import com.codahale.metrics.MetricFilter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
|
@ -37,7 +36,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* A {@link SolrMetricReporter} that finds (or creates) a MBeanServer from
|
||||
* the given configuration and registers metrics to it with JMX.
|
||||
* <p>NOTE: {@link JmxReporter} that this class uses exports only newly added metrics (it doesn't
|
||||
* <p>NOTE: {@link com.codahale.metrics.jmx.JmxReporter} that this class uses exports only newly added metrics (it doesn't
|
||||
* process already existing metrics in a registry)</p>
|
||||
*/
|
||||
public class SolrJmxReporter extends FilteringSolrMetricReporter {
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.DefaultObjectNameFactory;
|
||||
import com.codahale.metrics.jmx.DefaultObjectNameFactory;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Meter;
|
||||
|
@ -46,7 +46,7 @@ import com.codahale.metrics.Metric;
|
|||
import com.codahale.metrics.MetricFilter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.MetricRegistryListener;
|
||||
import com.codahale.metrics.ObjectNameFactory;
|
||||
import com.codahale.metrics.jmx.ObjectNameFactory;
|
||||
import com.codahale.metrics.Reporter;
|
||||
import com.codahale.metrics.Timer;
|
||||
import org.apache.solr.metrics.MetricsMap;
|
||||
|
@ -55,7 +55,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This is a modified copy of Dropwizard's {@link com.codahale.metrics.JmxReporter} and classes that it internally uses,
|
||||
* This is a modified copy of Dropwizard's {@link com.codahale.metrics.jmx.JmxReporter} and classes that it internally uses,
|
||||
* with a few important differences:
|
||||
* <ul>
|
||||
* <li>this class knows that it can directly use {@link MetricsMap} as a dynamic MBean.</li>
|
||||
|
|
|
@ -21,7 +21,7 @@ import javax.management.ObjectName;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.codahale.metrics.ObjectNameFactory;
|
||||
import com.codahale.metrics.jmx.ObjectNameFactory;
|
||||
import org.apache.solr.metrics.SolrMetricInfo;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<solr>
|
||||
<metrics>
|
||||
<reporter name="test" group="node" class="org.apache.solr.metrics.reporters.SolrGangliaReporter">
|
||||
<str name="host">localhost</str>
|
||||
<int name="port">10000</int>
|
||||
<!-- for unit tests this is set to 1 second - DO NOT USE THIS VALUE IN PRODUCTION! -->
|
||||
<int name="period">1</int>
|
||||
<str name="prefix">test</str>
|
||||
<str name="filter">CONTAINER.cores</str>
|
||||
<!-- this is only used when unit testing - DO NOT USE otherwise! -->
|
||||
<bool name="testing">true</bool>
|
||||
</reporter>
|
||||
</metrics>
|
||||
</solr>
|
|
@ -134,7 +134,7 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 {
|
|||
assertNotNull(values.get("metrics"));
|
||||
values = (NamedList) values.get("metrics");
|
||||
assertEquals(1, values.size());
|
||||
assertEquals(11, ((NamedList)values.get("solr.node")).size());
|
||||
assertEquals(13, ((NamedList)values.get("solr.node")).size());
|
||||
assertNotNull(values.get("solr.node"));
|
||||
values = (NamedList) values.get("solr.node");
|
||||
assertNotNull(values.get("CONTAINER.cores.lazy")); // this is a gauge node
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.solr.metrics.reporters;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import info.ganglia.gmetric4j.gmetric.GMetric;
|
||||
import info.ganglia.gmetric4j.gmetric.GMetricSlope;
|
||||
import info.ganglia.gmetric4j.gmetric.GMetricType;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.NodeConfig;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
import org.apache.solr.core.SolrXmlConfig;
|
||||
import org.apache.solr.metrics.SolrMetricManager;
|
||||
import org.apache.solr.metrics.SolrMetricReporter;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SolrGangliaReporterTest extends SolrTestCaseJ4 {
|
||||
@Test
|
||||
public void testReporter() throws Exception {
|
||||
assumeWorkingMockito();
|
||||
|
||||
Path home = Paths.get(TEST_HOME());
|
||||
// define these properties, they are used in solrconfig.xml
|
||||
System.setProperty("solr.test.sys.prop1", "propone");
|
||||
System.setProperty("solr.test.sys.prop2", "proptwo");
|
||||
|
||||
GMetric ganglia = mock(GMetric.class);
|
||||
final List<String> names = new ArrayList<>();
|
||||
doAnswer(invocation -> {
|
||||
final Object[] args = invocation.getArguments();
|
||||
names.add((String)args[0]);
|
||||
return null;
|
||||
}).when(ganglia).announce(anyString(), anyString(), any(GMetricType.class), anyString(), any(GMetricSlope.class), anyInt(), anyInt(), anyString());
|
||||
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-gangliareporter.xml").toFile(), "UTF-8");
|
||||
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
|
||||
CoreContainer cc = createCoreContainer(cfg,
|
||||
new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
|
||||
h.coreName = DEFAULT_TEST_CORENAME;
|
||||
SolrMetricManager metricManager = cc.getMetricManager();
|
||||
Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
|
||||
assertTrue(reporters.toString(), reporters.size() >= 1);
|
||||
SolrMetricReporter reporter = reporters.get("test");
|
||||
assertNotNull(reporter);
|
||||
assertTrue(reporter instanceof SolrGangliaReporter);
|
||||
SolrGangliaReporter gangliaReporter = (SolrGangliaReporter)reporter;
|
||||
gangliaReporter.setGMetric(ganglia);
|
||||
gangliaReporter.start();
|
||||
Thread.sleep(5000);
|
||||
assertTrue(names.size() >= 3);
|
||||
String[] frozenNames = (String[])names.toArray(new String[names.size()]);
|
||||
for (String name : frozenNames) {
|
||||
assertTrue(name, name.startsWith("test.solr.node.CONTAINER.cores."));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
62fe170cffeded1cef60e9e3402a93b45ce14327
|
|
@ -0,0 +1 @@
|
|||
b81ef162970cdb9f4512ee2da09715a856ff4c4c
|
|
@ -1 +0,0 @@
|
|||
a44039835eafd2dad8842a9ed16a60c088c5b7ef
|
|
@ -1 +0,0 @@
|
|||
ecbc470e9097bb3d7ff0232cca47f3badde2e20b
|
|
@ -0,0 +1 @@
|
|||
76e8758356373d5aed5abacbda429b38f6e8fa98
|
|
@ -1 +0,0 @@
|
|||
5dae1c13d8607663fbc7b22cf8c05aacd22f802e
|
|
@ -0,0 +1 @@
|
|||
87f3b49a7377e56f62046875d394ed0028b37690
|
|
@ -0,0 +1 @@
|
|||
d7be4ddd7ba674ee8be1d23d883fb3ca68ee1d54
|
|
@ -1 +0,0 @@
|
|||
a7a475393fe47dfee2042415430da3f01d4fe94e
|
|
@ -0,0 +1 @@
|
|||
09f6f1e6c1db440d9ad4c3114f17be40f66bb399
|
|
@ -39,9 +39,8 @@
|
|||
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-core" rev="${/io.dropwizard.metrics/metrics-core}" conf="metrics" />
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-jetty9" rev="${/io.dropwizard.metrics/metrics-jetty9}" conf="metrics" />
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-jmx" rev="${/io.dropwizard.metrics/metrics-jmx}" conf="metrics" />
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-jvm" rev="${/io.dropwizard.metrics/metrics-jvm}" conf="metrics" />
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-ganglia" rev="${/io.dropwizard.metrics/metrics-ganglia}" conf="metrics" />
|
||||
<dependency org="info.ganglia.gmetric4j" name="gmetric4j" rev="${/info.ganglia.gmetric4j/gmetric4j}" conf="metrics" />
|
||||
<dependency org="io.dropwizard.metrics" name="metrics-graphite" rev="${/io.dropwizard.metrics/metrics-graphite}" conf="metrics" />
|
||||
|
||||
<dependency org="org.eclipse.jetty" name="jetty-continuation" rev="${/org.eclipse.jetty/jetty-continuation}" conf="jetty"/>
|
||||
|
|
Loading…
Reference in New Issue