igiguere commented on code in PR #4078:
URL: https://github.com/apache/solr/pull/4078#discussion_r2907251133
##########
solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java:
##########
@@ -72,181 +38,28 @@
public class SystemInfoHandler extends RequestHandlerBase {
private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- /**
- * Expert level system property to prevent doing a reverse lookup of our
hostname. This property
- * will be logged as a suggested workaround if any problems are noticed when
doing reverse lookup.
- *
- * <p>TODO: should we refactor this (and the associated logic) into a helper
method for any other
- * places where DNS is used?
- *
- * @see #initHostname
- */
- private static final String REVERSE_DNS_OF_LOCALHOST_SYSPROP =
- "solr.admin.handler.systeminfo.dns.reverse.lookup.enabled";
-
- /**
- * Local cache for BeanInfo instances that are created to scan for system
metrics. List of
- * properties is not supposed to change for the JVM lifespan, so we can keep
already create
- * BeanInfo instance for future calls.
- */
- private static final ConcurrentMap<Class<?>, BeanInfo> beanInfos = new
ConcurrentHashMap<>();
-
- // on some platforms, resolving canonical hostname can cause the thread
- // to block for several seconds if name services aren't available
- // so resolve this once per handler instance
- // (ie: not static, so core reload will refresh)
- private String hostname = null;
-
private CoreContainer cc;
public SystemInfoHandler(CoreContainer cc) {
super();
this.cc = cc;
- initHostname();
- }
-
- /**
- * Iterates over properties of the given MXBean and invokes the provided
consumer with each
- * property name and its current value.
- *
- * @param obj an instance of MXBean
- * @param interfaces interfaces that it may implement. Each interface will
be tried in turn, and
- * only if it exists and if it contains unique properties then they will
be added as metrics.
- * @param consumer consumer for each property name and value
- * @param <T> formal type
- */
- public static <T extends PlatformManagedObject> void forEachGetterValue(
- T obj, String[] interfaces, BiConsumer<String, Object> consumer) {
- for (String clazz : interfaces) {
- try {
- final Class<? extends PlatformManagedObject> intf =
- Class.forName(clazz).asSubclass(PlatformManagedObject.class);
- forEachGetterValue(obj, intf, consumer);
- } catch (ClassNotFoundException e) {
- // ignore
- }
- }
- }
-
- /**
- * Iterates over properties of the given MXBean and invokes the provided
consumer with each
- * property name and its current value.
- *
- * @param obj an instance of MXBean
- * @param intf MXBean interface, one of {@link PlatformManagedObject}-s
- * @param consumer consumer for each property name and value
- * @param <T> formal type
- */
- public static <T extends PlatformManagedObject> void forEachGetterValue(
- T obj, Class<? extends T> intf, BiConsumer<String, Object> consumer) {
- if (intf.isInstance(obj)) {
- BeanInfo beanInfo =
- beanInfos.computeIfAbsent(
- intf,
- clazz -> {
- try {
- return Introspector.getBeanInfo(
- clazz, clazz.getSuperclass(),
Introspector.IGNORE_ALL_BEANINFO);
-
- } catch (IntrospectionException e) {
- log.warn("Unable to fetch properties of MXBean {}",
obj.getClass().getName());
- return null;
- }
- });
-
- // if BeanInfo retrieval failed, return early
- if (beanInfo == null) {
- return;
- }
- for (final PropertyDescriptor desc : beanInfo.getPropertyDescriptors()) {
- try {
- Method readMethod = desc.getReadMethod();
- if (readMethod == null) {
- continue; // skip properties without a read method
- }
-
- final String name = desc.getName();
- Object value = readMethod.invoke(obj);
- consumer.accept(name, value);
- } catch (Exception e) {
- // didn't work, skip it...
- }
- }
- }
- }
-
- private void initHostname() {
- if (!EnvUtils.getPropertyAsBool(REVERSE_DNS_OF_LOCALHOST_SYSPROP, true)) {
- log.info(
- "Resolving canonical hostname for local host prevented due to '{}'
sysprop",
- REVERSE_DNS_OF_LOCALHOST_SYSPROP);
- hostname = null;
- return;
- }
-
- RTimer timer = new RTimer();
- try {
- InetAddress addr = InetAddress.getLocalHost();
- hostname = addr.getCanonicalHostName();
- } catch (Exception e) {
- log.warn(
- "Unable to resolve canonical hostname for local host, possible DNS
misconfiguration. Set the '{}' sysprop to false on startup to prevent future
lookups if DNS can not be fixed.",
- REVERSE_DNS_OF_LOCALHOST_SYSPROP,
- e);
- hostname = null;
- return;
- }
- timer.stop();
-
- if (15000D < timer.getTime()) {
- String readableTime = String.format(Locale.ROOT, "%.3f",
(timer.getTime() / 1000));
- log.warn(
- "Resolving canonical hostname for local host took {} seconds,
possible DNS misconfiguration. Set the '{}' sysprop to false on startup to
prevent future lookups if DNS can not be fixed.",
- readableTime,
- REVERSE_DNS_OF_LOCALHOST_SYSPROP);
- }
}
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
throws Exception {
rsp.setHttpCaching(false);
+
if (AdminHandlersProxy.maybeProxyToNodes(req, rsp, getCoreContainer(req)))
{
return; // Request was proxied to other node
}
- boolean solrCloudMode = getCoreContainer(req).isZooKeeperAware();
- rsp.add("mode", solrCloudMode ? "solrcloud" : "std");
- rsp.add("host", hostname);
+ SystemInfoProvider provider = new SystemInfoProvider(req);
+ NodeSystemResponse response = provider.getNodeSystemInfo(new
NodeSystemResponse());
+ V2ApiUtils.squashIntoSolrResponseWithoutHeader(rsp, response);
- if (solrCloudMode) {
- rsp.add("zkHost",
getCoreContainer(req).getZkController().getZkServerAddress());
- }
- if (cc != null) {
- rsp.add("solr_home", cc.getSolrHome());
- rsp.add("core_root", cc.getCoreRootDirectory());
- }
-
- rsp.add("lucene", getLuceneInfo());
- NodeConfig nodeConfig = getCoreContainer(req).getNodeConfig();
- rsp.add("jvm", getJvmInfo(nodeConfig));
- rsp.add("security", getSecurityInfo(req));
- rsp.add("system", getSystemInfo());
-
- rsp.add("gpu", getGpuInfo(req));
- if (solrCloudMode) {
- rsp.add("node", getCoreContainer(req).getZkController().getNodeName());
- }
- SolrEnvironment env =
- SolrEnvironment.getFromSyspropOrClusterprop(
- solrCloudMode ?
getCoreContainer(req).getZkController().zkStateReader : null);
- if (env.isDefined()) {
- rsp.add("environment", env.getCode());
- if (env.getLabel() != null) {
- rsp.add("environment_label", env.getLabel());
- }
- if (env.getColor() != null) {
- rsp.add("environment_color", env.getColor());
- }
+ // back-compatible response with core info if available
+ if (req.getCore() != null) {
Review Comment:
@gerlowskija
That was there to ensure back-compatibility of the V1 response, with
previous version. Ref: your comment
https://github.com/apache/solr/pull/4078#issuecomment-3825046198
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]