PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/elasticsearch_node_status/test.rb

https://gitlab.com/sgruhier/scout-plugins
Ruby | 575 lines | 556 code | 11 blank | 8 comment | 1 complexity | b6794d44132e192582fa97f26e68408c MD5 | raw file
  1. require File.expand_path('../../test_helper.rb', __FILE__)
  2. require File.expand_path('../elasticsearch_node_status.rb', __FILE__)
  3. require 'open-uri'
  4. class ElasticsearchClusterNodeStatusTest < Test::Unit::TestCase
  5. def setup
  6. @node_name = 'es_db0'
  7. @options=parse_defaults("elasticsearch_node_status")
  8. setup_urls
  9. end
  10. def teardown
  11. FakeWeb.clean_registry
  12. end
  13. def test_bad_host
  14. plugin = ElasticsearchClusterNodeStatus.new(nil,{},@options.merge(:elasticsearch_host=>'bad'))
  15. res = plugin.run
  16. e = res[:errors].first
  17. assert e[:body].include?("bad")
  18. end
  19. def test_initial_run
  20. @plugin = ElasticsearchClusterNodeStatus.new(nil,{},@options.merge(:node_name=>@node_name))
  21. @res = @plugin.run
  22. assert @res[:errors].empty?, "Error: #{@res[:errors].inspect}"
  23. assert_not_nil @res[:memory]["gc_collection_time"]
  24. assert_not_nil @res[:memory]["gc_collection_count"]
  25. assert_not_nil @res[:memory]["gc_parnew_collection_time"]
  26. assert_not_nil @res[:memory]["gc_parnew_collection_count"]
  27. assert_not_nil @res[:memory]["gc_cms_collection_time"]
  28. assert_not_nil @res[:memory]["gc_cms_collection_count"]
  29. end
  30. def test_second_run
  31. test_initial_run
  32. @plugin = ElasticsearchClusterNodeStatus.new(nil,@res[:memory],@options.merge(:node_name=>@node_name))
  33. res = @plugin.run
  34. # should report gc time now
  35. assert_equal 3, res[:reports].size - @res[:reports].size
  36. end
  37. def test_node_name_default
  38. @plugin = ElasticsearchClusterNodeStatus.new(nil,{},@options.merge(:node_name => nil))
  39. assert_equal '_local', @plugin.node_name
  40. end
  41. ###############
  42. ### Helpers ###
  43. ###############
  44. def setup_urls
  45. uri="http://127.0.0.1:9200/_nodes/#{@node_name}/stats?all=true"
  46. FakeWeb.register_uri(:get, uri,
  47. [
  48. {:body => FIXTURES[:initial]},
  49. {:body => FIXTURES[:second_run]}
  50. ]
  51. )
  52. uri="http://127.0.0.1:9200/"
  53. FakeWeb.register_uri(:get, uri,
  54. [
  55. {:body => FIXTURES[:version]}
  56. ]
  57. )
  58. end
  59. ################
  60. ### Fixtures ###
  61. ################
  62. FIXTURES=YAML.load(<<-EOS)
  63. :version: |
  64. {
  65. "status" : 200,
  66. "name" : "Crimson Cowl",
  67. "version" : {
  68. "number" : "1.3.2",
  69. "build_hash" : "dee175dbe2f254f3f26992f5d7591939aaefd12f",
  70. "build_timestamp" : "2014-08-13T14:29:30Z",
  71. "build_snapshot" : false,
  72. "lucene_version" : "4.9"
  73. },
  74. "tagline" : "You Know, for Search"
  75. }
  76. :initial: |
  77. {
  78. "cluster_name" : "elasticsearch",
  79. "nodes" : {
  80. "K394ZLaSQFaPBzb_AYq2pg" : {
  81. "name" : "es_db0",
  82. "indices" : {
  83. "size" : "502b",
  84. "size_in_bytes" : 502,
  85. "docs" : {
  86. "num_docs" : 0
  87. },
  88. "cache" : {
  89. "field_evictions" : 0,
  90. "field_size" : "0b",
  91. "field_size_in_bytes" : 0,
  92. "filter_count" : 0,
  93. "filter_evictions" : 0,
  94. "filter_size" : "0b",
  95. "filter_size_in_bytes" : 0
  96. },
  97. "merges" : {
  98. "current" : 0,
  99. "total" : 0,
  100. "total_time" : "0s",
  101. "total_time_in_millis" : 0
  102. }
  103. },
  104. "os" : {
  105. "timestamp" : 1313616315994,
  106. "uptime" : "-1 seconds",
  107. "uptime_in_millis" : -1000,
  108. "load_average" : [ ]
  109. },
  110. "process" : {
  111. "timestamp" : 1313616315994,
  112. "open_file_descriptors" : 153
  113. },
  114. "jvm" : {
  115. "timestamp" : 1313616315994,
  116. "uptime" : "1 hour, 28 minutes, 26 seconds and 609 milliseconds",
  117. "uptime_in_millis" : 5306609,
  118. "mem" : {
  119. "heap_used" : "38.1mb",
  120. "heap_used_in_bytes" : 40028712,
  121. "heap_committed" : "265.5mb",
  122. "heap_committed_in_bytes" : 278462464,
  123. "non_heap_used" : "32mb",
  124. "non_heap_used_in_bytes" : 33599624,
  125. "non_heap_committed" : "36.9mb",
  126. "non_heap_committed_in_bytes" : 38789120
  127. },
  128. "threads" : {
  129. "count" : 41,
  130. "peak_count" : 61
  131. },
  132. "gc" : {
  133. "collection_count" : 30,
  134. "collection_time" : "380 milliseconds",
  135. "collection_time_in_millis" : 380,
  136. "collectors" : {
  137. "ParNew" : {
  138. "collection_count" : 29,
  139. "collection_time" : "221 milliseconds",
  140. "collection_time_in_millis" : 221
  141. },
  142. "ConcurrentMarkSweep" : {
  143. "collection_count" : 1,
  144. "collection_time" : "159 milliseconds",
  145. "collection_time_in_millis" : 159
  146. }
  147. }
  148. }
  149. },
  150. "network" : {
  151. },
  152. "transport" : {
  153. "server_open" : 21
  154. },
  155. "http" : {
  156. "server_open" : 1
  157. }
  158. },
  159. "zT0BOTMhQGOBmXcklNqjIA" : {
  160. "name" : "es_db1",
  161. "indices" : {
  162. "size" : "1.1kb",
  163. "size_in_bytes" : 1139,
  164. "docs" : {
  165. "num_docs" : 1
  166. },
  167. "cache" : {
  168. "field_evictions" : 0,
  169. "field_size" : "0b",
  170. "field_size_in_bytes" : 0,
  171. "filter_count" : 0,
  172. "filter_evictions" : 0,
  173. "filter_size" : "0b",
  174. "filter_size_in_bytes" : 0
  175. },
  176. "merges" : {
  177. "current" : 0,
  178. "total" : 0,
  179. "total_time" : "0s",
  180. "total_time_in_millis" : 0
  181. }
  182. },
  183. "os" : {
  184. "timestamp" : 1313616315994,
  185. "uptime" : "-1 seconds",
  186. "uptime_in_millis" : -1000,
  187. "load_average" : [ ]
  188. },
  189. "process" : {
  190. "timestamp" : 1313616315994,
  191. "open_file_descriptors" : 167
  192. },
  193. "jvm" : {
  194. "timestamp" : 1313616315994,
  195. "uptime" : "1 hour, 28 minutes, 4 seconds and 305 milliseconds",
  196. "uptime_in_millis" : 5284305,
  197. "mem" : {
  198. "heap_used" : "25.9mb",
  199. "heap_used_in_bytes" : 27254904,
  200. "heap_committed" : "265.5mb",
  201. "heap_committed_in_bytes" : 278462464,
  202. "non_heap_used" : "30.3mb",
  203. "non_heap_used_in_bytes" : 31796400,
  204. "non_heap_committed" : "36.9mb",
  205. "non_heap_committed_in_bytes" : 38789120
  206. },
  207. "threads" : {
  208. "count" : 43,
  209. "peak_count" : 54
  210. },
  211. "gc" : {
  212. "collection_count" : 12,
  213. "collection_time" : "270 milliseconds",
  214. "collection_time_in_millis" : 270,
  215. "collectors" : {
  216. "ParNew" : {
  217. "collection_count" : 11,
  218. "collection_time" : "89 milliseconds",
  219. "collection_time_in_millis" : 89
  220. },
  221. "ConcurrentMarkSweep" : {
  222. "collection_count" : 1,
  223. "collection_time" : "181 milliseconds",
  224. "collection_time_in_millis" : 181
  225. }
  226. }
  227. }
  228. },
  229. "network" : {
  230. },
  231. "transport" : {
  232. "server_open" : 21
  233. },
  234. "http" : {
  235. "server_open" : 0
  236. }
  237. },
  238. "FP0mHgloR2alksR1yVFvuw" : {
  239. "name" : "es_db3",
  240. "indices" : {
  241. "size" : "1kb",
  242. "size_in_bytes" : 1093,
  243. "docs" : {
  244. "num_docs" : 1
  245. },
  246. "cache" : {
  247. "field_evictions" : 0,
  248. "field_size" : "0b",
  249. "field_size_in_bytes" : 0,
  250. "filter_count" : 0,
  251. "filter_evictions" : 0,
  252. "filter_size" : "0b",
  253. "filter_size_in_bytes" : 0
  254. },
  255. "merges" : {
  256. "current" : 0,
  257. "total" : 0,
  258. "total_time" : "0s",
  259. "total_time_in_millis" : 0
  260. }
  261. },
  262. "os" : {
  263. "timestamp" : 1313616315994,
  264. "uptime" : "-1 seconds",
  265. "uptime_in_millis" : -1000,
  266. "load_average" : [ ]
  267. },
  268. "process" : {
  269. "timestamp" : 1313616315994,
  270. "open_file_descriptors" : 185
  271. },
  272. "jvm" : {
  273. "timestamp" : 1313616315994,
  274. "uptime" : "56 minutes, 38 seconds and 492 milliseconds",
  275. "uptime_in_millis" : 3398492,
  276. "mem" : {
  277. "heap_used" : "13.8mb",
  278. "heap_used_in_bytes" : 14474688,
  279. "heap_committed" : "265.5mb",
  280. "heap_committed_in_bytes" : 278462464,
  281. "non_heap_used" : "29.7mb",
  282. "non_heap_used_in_bytes" : 31195192,
  283. "non_heap_committed" : "36.9mb",
  284. "non_heap_committed_in_bytes" : 38793216
  285. },
  286. "threads" : {
  287. "count" : 48,
  288. "peak_count" : 53
  289. },
  290. "gc" : {
  291. "collection_count" : 10,
  292. "collection_time" : "225 milliseconds",
  293. "collection_time_in_millis" : 225,
  294. "collectors" : {
  295. "ParNew" : {
  296. "collection_count" : 9,
  297. "collection_time" : "60 milliseconds",
  298. "collection_time_in_millis" : 60
  299. },
  300. "ConcurrentMarkSweep" : {
  301. "collection_count" : 1,
  302. "collection_time" : "165 milliseconds",
  303. "collection_time_in_millis" : 165
  304. }
  305. }
  306. }
  307. },
  308. "network" : {
  309. },
  310. "transport" : {
  311. "server_open" : 21
  312. },
  313. "http" : {
  314. "server_open" : 0
  315. }
  316. }
  317. }
  318. }
  319. # values for times and counts are 2x the initial run
  320. :second_run: |
  321. {
  322. "cluster_name" : "elasticsearch",
  323. "nodes" : {
  324. "K394ZLaSQFaPBzb_AYq2pg" : {
  325. "name" : "es_db0",
  326. "indices" : {
  327. "size" : "502b",
  328. "size_in_bytes" : 502,
  329. "docs" : {
  330. "num_docs" : 0
  331. },
  332. "cache" : {
  333. "field_evictions" : 0,
  334. "field_size" : "0b",
  335. "field_size_in_bytes" : 0,
  336. "filter_count" : 0,
  337. "filter_evictions" : 0,
  338. "filter_size" : "0b",
  339. "filter_size_in_bytes" : 0
  340. },
  341. "merges" : {
  342. "current" : 0,
  343. "total" : 0,
  344. "total_time" : "0s",
  345. "total_time_in_millis" : 0
  346. }
  347. },
  348. "os" : {
  349. "timestamp" : 1313616315994,
  350. "uptime" : "-1 seconds",
  351. "uptime_in_millis" : -1000,
  352. "load_average" : [ ]
  353. },
  354. "process" : {
  355. "timestamp" : 1313616315994,
  356. "open_file_descriptors" : 153
  357. },
  358. "jvm" : {
  359. "timestamp" : 1313616315994,
  360. "uptime" : "1 hour, 28 minutes, 26 seconds and 609 milliseconds",
  361. "uptime_in_millis" : 5306609,
  362. "mem" : {
  363. "heap_used" : "38.1mb",
  364. "heap_used_in_bytes" : 40028712,
  365. "heap_committed" : "265.5mb",
  366. "heap_committed_in_bytes" : 278462464,
  367. "non_heap_used" : "32mb",
  368. "non_heap_used_in_bytes" : 33599624,
  369. "non_heap_committed" : "36.9mb",
  370. "non_heap_committed_in_bytes" : 38789120
  371. },
  372. "threads" : {
  373. "count" : 41,
  374. "peak_count" : 61
  375. },
  376. "gc" : {
  377. "collection_count" : 30,
  378. "collection_time" : "380 milliseconds",
  379. "collection_time_in_millis" : 380,
  380. "collectors" : {
  381. "ParNew" : {
  382. "collection_count" : 29,
  383. "collection_time" : "221 milliseconds",
  384. "collection_time_in_millis" : 221
  385. },
  386. "ConcurrentMarkSweep" : {
  387. "collection_count" : 1,
  388. "collection_time" : "159 milliseconds",
  389. "collection_time_in_millis" : 159
  390. }
  391. }
  392. }
  393. },
  394. "network" : {
  395. },
  396. "transport" : {
  397. "server_open" : 21
  398. },
  399. "http" : {
  400. "server_open" : 1
  401. }
  402. },
  403. "zT0BOTMhQGOBmXcklNqjIA" : {
  404. "name" : "es_db1",
  405. "indices" : {
  406. "size" : "1.1kb",
  407. "size_in_bytes" : 1139,
  408. "docs" : {
  409. "num_docs" : 1
  410. },
  411. "cache" : {
  412. "field_evictions" : 0,
  413. "field_size" : "0b",
  414. "field_size_in_bytes" : 0,
  415. "filter_count" : 0,
  416. "filter_evictions" : 0,
  417. "filter_size" : "0b",
  418. "filter_size_in_bytes" : 0
  419. },
  420. "merges" : {
  421. "current" : 0,
  422. "total" : 0,
  423. "total_time" : "0s",
  424. "total_time_in_millis" : 0
  425. }
  426. },
  427. "os" : {
  428. "timestamp" : 1313616315994,
  429. "uptime" : "-1 seconds",
  430. "uptime_in_millis" : -1000,
  431. "load_average" : [ ]
  432. },
  433. "process" : {
  434. "timestamp" : 1313616315994,
  435. "open_file_descriptors" : 167
  436. },
  437. "jvm" : {
  438. "timestamp" : 1313616315994,
  439. "uptime" : "1 hour, 28 minutes, 4 seconds and 305 milliseconds",
  440. "uptime_in_millis" : 5284305,
  441. "mem" : {
  442. "heap_used" : "25.9mb",
  443. "heap_used_in_bytes" : 27254904,
  444. "heap_committed" : "265.5mb",
  445. "heap_committed_in_bytes" : 278462464,
  446. "non_heap_used" : "30.3mb",
  447. "non_heap_used_in_bytes" : 31796400,
  448. "non_heap_committed" : "36.9mb",
  449. "non_heap_committed_in_bytes" : 38789120
  450. },
  451. "threads" : {
  452. "count" : 43,
  453. "peak_count" : 54
  454. },
  455. "gc" : {
  456. "collection_count" : 12,
  457. "collection_time" : "270 milliseconds",
  458. "collection_time_in_millis" : 270,
  459. "collectors" : {
  460. "ParNew" : {
  461. "collection_count" : 11,
  462. "collection_time" : "89 milliseconds",
  463. "collection_time_in_millis" : 89
  464. },
  465. "ConcurrentMarkSweep" : {
  466. "collection_count" : 1,
  467. "collection_time" : "181 milliseconds",
  468. "collection_time_in_millis" : 181
  469. }
  470. }
  471. }
  472. },
  473. "network" : {
  474. },
  475. "transport" : {
  476. "server_open" : 21
  477. },
  478. "http" : {
  479. "server_open" : 0
  480. }
  481. },
  482. "FP0mHgloR2alksR1yVFvuw" : {
  483. "name" : "es_db3",
  484. "indices" : {
  485. "size" : "1kb",
  486. "size_in_bytes" : 1093,
  487. "docs" : {
  488. "num_docs" : 1
  489. },
  490. "cache" : {
  491. "field_evictions" : 0,
  492. "field_size" : "0b",
  493. "field_size_in_bytes" : 0,
  494. "filter_count" : 0,
  495. "filter_evictions" : 0,
  496. "filter_size" : "0b",
  497. "filter_size_in_bytes" : 0
  498. },
  499. "merges" : {
  500. "current" : 0,
  501. "total" : 0,
  502. "total_time" : "0s",
  503. "total_time_in_millis" : 0
  504. }
  505. },
  506. "os" : {
  507. "timestamp" : 1313616315994,
  508. "uptime" : "-1 seconds",
  509. "uptime_in_millis" : -1000,
  510. "load_average" : [ ]
  511. },
  512. "process" : {
  513. "timestamp" : 1313616315994,
  514. "open_file_descriptors" : 185
  515. },
  516. "jvm" : {
  517. "timestamp" : 1313616315994,
  518. "uptime" : "56 minutes, 38 seconds and 492 milliseconds",
  519. "uptime_in_millis" : 3398492,
  520. "mem" : {
  521. "heap_used" : "13.8mb",
  522. "heap_used_in_bytes" : 14474688,
  523. "heap_committed" : "265.5mb",
  524. "heap_committed_in_bytes" : 278462464,
  525. "non_heap_used" : "29.7mb",
  526. "non_heap_used_in_bytes" : 31195192,
  527. "non_heap_committed" : "36.9mb",
  528. "non_heap_committed_in_bytes" : 38793216
  529. },
  530. "threads" : {
  531. "count" : 48,
  532. "peak_count" : 53
  533. },
  534. "gc" : {
  535. "collection_count" : 20,
  536. "collection_time" : "500 milliseconds",
  537. "collection_time_in_millis" : 500,
  538. "collectors" : {
  539. "ParNew" : {
  540. "collection_count" : 18,
  541. "collection_time" : "120 milliseconds",
  542. "collection_time_in_millis" : 120
  543. },
  544. "ConcurrentMarkSweep" : {
  545. "collection_count" : 2,
  546. "collection_time" : "330 milliseconds",
  547. "collection_time_in_millis" : 330
  548. }
  549. }
  550. }
  551. },
  552. "network" : {
  553. },
  554. "transport" : {
  555. "server_open" : 21
  556. },
  557. "http" : {
  558. "server_open" : 0
  559. }
  560. }
  561. }
  562. }
  563. EOS
  564. end