Skip to content

Commit e452e5c

Browse files
authored
SOLR-16458: Bugfix that we don't want to assume everything is a string. (#4330)
1 parent 19bd3d1 commit e452e5c

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

solr/api/src/java/org/apache/solr/client/api/model/NodeSystemResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void setRemoteNodeResponse(String field, Object value) {
6464
@JsonProperty public JVM jvm;
6565
@JsonProperty public Security security;
6666
@JsonProperty public GPU gpu;
67-
@JsonProperty public Map<String, String> system;
67+
@JsonProperty public Map<String, Object> system;
6868

6969
/** /node/system/security */
7070
public static class Security {

solr/core/src/java/org/apache/solr/handler/admin/SystemInfoProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public static SimpleOrderedMap<Object> getCoreInfo(SolrCore core, IndexSchema sc
180180
}
181181

182182
/** Get system info */
183-
public Map<String, String> getSystemInfo() {
184-
Map<String, String> info = new HashMap<>();
183+
public Map<String, Object> getSystemInfo() {
184+
Map<String, Object> info = new HashMap<>();
185185

186186
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
187187
info.put(NAME, os.getName()); // add at least this one
@@ -193,7 +193,7 @@ public Map<String, String> getSystemInfo() {
193193
MetricUtils.OS_MXBEAN_CLASSES,
194194
(name, value) -> {
195195
if (info.get(name) == null) {
196-
info.put(name, String.valueOf(value));
196+
info.put(name, value);
197197
}
198198
});
199199

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.solr.handler.admin;
18+
19+
import static org.apache.solr.SolrTestCaseJ4.assumeWorkingMockito;
20+
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.when;
22+
23+
import java.util.Map;
24+
import org.apache.solr.SolrTestCase;
25+
import org.apache.solr.common.params.ModifiableSolrParams;
26+
import org.apache.solr.request.SolrQueryRequest;
27+
import org.junit.BeforeClass;
28+
import org.junit.Test;
29+
30+
/** Pure unit tests for {@link SystemInfoProvider}. */
31+
public class SystemInfoProviderUnitTest extends SolrTestCase {
32+
33+
@BeforeClass
34+
public static void ensureWorkingMockito() {
35+
assumeWorkingMockito();
36+
}
37+
38+
@Test
39+
public void testNumericOsMetricsArePreservedAsNumbers() {
40+
SolrQueryRequest req = mock(SolrQueryRequest.class);
41+
when(req.getParams()).thenReturn(new ModifiableSolrParams());
42+
when(req.getCoreContainer()).thenReturn(null);
43+
44+
Map<String, Object> info = new SystemInfoProvider(req).getSystemInfo();
45+
46+
// The Admin UI calls .toFixed(2) on systemLoadAverage — must be a Number, not a String.
47+
Object loadAvg = info.get("systemLoadAverage");
48+
if (loadAvg != null) {
49+
assertTrue(
50+
"systemLoadAverage must be a Number, got " + loadAvg.getClass(),
51+
loadAvg instanceof Number);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)