forked from zhynwng/hadoop-MLEC
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HADOOP-18954. Filter NaN values from JMX json interface. (apache#6229).
Reviewed-by: Ferenc Erdelyi Signed-off-by: He Xiaoqiao <[email protected]>
- Loading branch information
Showing
8 changed files
with
190 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServletNaNFiltered.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 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.hadoop.jmx; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* For example in case of MutableGauge we are using numbers, | ||
* but not implementing Number interface, | ||
* so we skip class check here because we can not be sure NaN values are wrapped | ||
* with classes which implements the Number interface | ||
*/ | ||
public class JMXJsonServletNaNFiltered extends JMXJsonServlet { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(JMXJsonServletNaNFiltered.class); | ||
|
||
@Override | ||
protected boolean extraCheck(Object value) { | ||
return Objects.equals("NaN", Objects.toString(value).trim()); | ||
} | ||
|
||
@Override | ||
protected void extraWrite(Object value, String attName, JsonGenerator jg) throws IOException { | ||
LOG.debug("The {} attribute with value: {} was identified as NaN " | ||
+ "and will be replaced with 0.0", attName, value); | ||
jg.writeNumber(0.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ject/hadoop-common/src/test/java/org/apache/hadoop/jmx/TestJMXJsonServletNaNFiltered.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* 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.hadoop.jmx; | ||
|
||
import java.net.URL; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.http.HttpServer2; | ||
import org.apache.hadoop.http.HttpServerFunctionalTest; | ||
|
||
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.JMX_NAN_FILTER; | ||
|
||
public class TestJMXJsonServletNaNFiltered extends HttpServerFunctionalTest { | ||
private static HttpServer2 server; | ||
private static URL baseUrl; | ||
|
||
@BeforeClass public static void setup() throws Exception { | ||
Configuration configuration = new Configuration(); | ||
configuration.setBoolean(JMX_NAN_FILTER, true); | ||
server = createTestServer(configuration); | ||
server.start(); | ||
baseUrl = getServerURL(server); | ||
} | ||
|
||
@AfterClass public static void cleanup() throws Exception { | ||
server.stop(); | ||
} | ||
|
||
public static void assertReFind(String re, String value) { | ||
Pattern p = Pattern.compile(re); | ||
Matcher m = p.matcher(value); | ||
assertTrue("'"+p+"' does not match "+value, m.find()); | ||
} | ||
|
||
@Test public void testQuery() throws Exception { | ||
System.setProperty("THE_TEST_OF_THE_NAN_VALUES", String.valueOf(Float.NaN)); | ||
String result = readOutput(new URL(baseUrl, "/jmx")); | ||
assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result); | ||
assertReFind( | ||
"\"key\"\\s*:\\s*\"THE_TEST_OF_THE_NAN_VALUES\"\\s*,\\s*\"value\"\\s*:\\s*0.0", | ||
result | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters