Marvel: Fix NodeStatsRendererTests and NodeStatsTests on Windows

Load average is not available anymore on Windows, the tests should not check the presence of the field. Also, "node_stats.json" file is hard to maintain and quite useless so this commit removes it.

Original commit: elastic/x-pack-elasticsearch@74d2e0dce6
This commit is contained in:
Tanguy Leroux 2016-01-28 16:59:05 +01:00
parent 75894e6b38
commit 19545596cf
3 changed files with 27 additions and 93 deletions

View File

@ -5,16 +5,19 @@
*/
package org.elasticsearch.marvel.agent.renderer.node;
import org.apache.lucene.util.Constants;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsMarvelDoc;
import org.elasticsearch.marvel.agent.renderer.Renderer;
import org.elasticsearch.marvel.agent.renderer.RendererTestUtils;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.StreamsUtils;
import java.util.Map;
public class NodeStatsRendererTests extends ESSingleNodeTestCase {
private static final String SAMPLE_FILE = "/samples/node_stats.json";
public void testNodeStatsRenderer() throws Exception {
createIndex("index-0");
@ -27,13 +30,19 @@ public class NodeStatsRendererTests extends ESSingleNodeTestCase {
"node-0", true, nodeStats, false, 90.0, true);
logger.debug("--> rendering the document");
Renderer renderer = new NodeStatsRenderer();
String result = RendererTestUtils.renderAsJSON(marvelDoc, renderer);
try (BytesStreamOutput os = new BytesStreamOutput()) {
new NodeStatsRenderer().render(marvelDoc, XContentType.JSON, os);
Map<String, Object> result = XContentHelper.convertToMap(os.bytes(), false).v2();
logger.debug("--> loading sample document from file {}", SAMPLE_FILE);
String expected = StreamsUtils.copyToStringFromClasspath(SAMPLE_FILE);
logger.debug("--> comparing both documents, they must have the same structure");
RendererTestUtils.assertJSONStructure(result, expected);
for (String field : NodeStatsRenderer.FILTERS) {
if (Constants.WINDOWS) {
// load average is unavailable on Windows
if ("node_stats.os.cpu.load_average.1m".equals(field)) {
continue;
}
}
assertNotNull("expecting field to be present:" + field, XContentMapValues.extractValue(field, result));
}
}
}
}

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.marvel.agent.renderer.node;
import org.apache.lucene.util.Constants;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector;
@ -66,6 +67,12 @@ public class NodeStatsTests extends MarvelIntegTestCase {
Map<String, Object> fields = searchHit.sourceAsMap();
for (String filter : filters) {
if (Constants.WINDOWS) {
// load average is unavailable on Windows
if ("node_stats.os.cpu.load_average.1m".equals(filter)) {
continue;
}
}
assertContains(filter, fields);
}
}

View File

@ -1,82 +0,0 @@
{
"cluster_uuid": "dsFPzYRyQCe6cq48a0wxkQ",
"timestamp": "2015-07-22T15:54:02.979Z",
"node_stats": {
"node_id": "OB5Mr2NGQe6xYCFvMggReg",
"node_master": true,
"mlockall": false,
"disk_threshold_enabled": true,
"disk_threshold_watermark_high": 90.0,
"indices": {
"docs": {
"count": 0
},
"store": {
"size_in_bytes": 0,
"throttle_time_in_millis": 0
},
"indexing" : {
"index_total" : 1,
"index_time_in_millis" : 60,
"throttle_time_in_millis" : 0
},
"search" : {
"query_total" : 0,
"query_time_in_millis" : 0
},
"segments": {
"count": 0
}
},
"os": {
"cpu": {
"load_average": {
"1m": 0.66
}
}
},
"process": {
"open_file_descriptors": 235,
"max_file_descriptors": 4096,
"cpu": {
"percent": 47
}
},
"jvm": {
"mem": {
"heap_used_in_bytes": 58976328,
"heap_used_percent": 1
},
"gc": {
"collectors": {
"young": {
"collection_count": 4,
"collection_time_in_millis": 50
},
"old": {
"collection_count": 1,
"collection_time_in_millis": 42
}
}
}
},
"thread_pool": {
"bulk": {
"rejected": 0
},
"index": {
"rejected": 0
},
"search": {
"rejected": 0
}
},
"fs": {
"total": {
"total_in_bytes": 486599139328,
"free_in_bytes": 228134465536,
"available_in_bytes": 203393003520
}
}
}
}