github.com/netdata/go.d.plugin@v0.58.1/modules/elasticsearch/elasticsearch_test.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package elasticsearch 4 5 import ( 6 "net/http" 7 "net/http/httptest" 8 "os" 9 "testing" 10 11 "github.com/netdata/go.d.plugin/pkg/tlscfg" 12 "github.com/netdata/go.d.plugin/pkg/web" 13 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/require" 16 ) 17 18 var ( 19 v842NodesLocalStats, _ = os.ReadFile("testdata/v8.4.2/nodes_local_stats.json") 20 v842NodesStats, _ = os.ReadFile("testdata/v8.4.2/nodes_stats.json") 21 v842ClusterHealth, _ = os.ReadFile("testdata/v8.4.2/cluster_health.json") 22 v842ClusterStats, _ = os.ReadFile("testdata/v8.4.2/cluster_stats.json") 23 v842CatIndicesStats, _ = os.ReadFile("testdata/v8.4.2/cat_indices_stats.json") 24 v842Info, _ = os.ReadFile("testdata/v8.4.2/info.json") 25 ) 26 27 func Test_testDataIsCorrectlyReadAndValid(t *testing.T) { 28 for name, data := range map[string][]byte{ 29 "v842NodesLocalStats": v842NodesLocalStats, 30 "v842NodesStats": v842NodesStats, 31 "v842ClusterHealth": v842ClusterHealth, 32 "v842ClusterStats": v842ClusterStats, 33 "v842CatIndicesStats": v842CatIndicesStats, 34 "v842Info": v842Info, 35 } { 36 require.NotNilf(t, data, name) 37 } 38 } 39 40 func TestElasticsearch_Init(t *testing.T) { 41 tests := map[string]struct { 42 config Config 43 wantFail bool 44 }{ 45 "default": { 46 config: New().Config, 47 }, 48 "all stats": { 49 config: Config{ 50 HTTP: web.HTTP{ 51 Request: web.Request{URL: "http://127.0.0.1:38001"}, 52 }, 53 DoNodeStats: true, 54 DoClusterHealth: true, 55 DoClusterStats: true, 56 DoIndicesStats: true, 57 }, 58 }, 59 "only node_stats": { 60 config: Config{ 61 HTTP: web.HTTP{ 62 Request: web.Request{URL: "http://127.0.0.1:38001"}, 63 }, 64 DoNodeStats: true, 65 DoClusterHealth: false, 66 DoClusterStats: false, 67 DoIndicesStats: false, 68 }, 69 }, 70 "URL not set": { 71 wantFail: true, 72 config: Config{ 73 HTTP: web.HTTP{ 74 Request: web.Request{URL: ""}, 75 }}, 76 }, 77 "invalid TLSCA": { 78 wantFail: true, 79 config: Config{ 80 HTTP: web.HTTP{ 81 Client: web.Client{ 82 TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}, 83 }, 84 }}, 85 }, 86 "all API calls are disabled": { 87 wantFail: true, 88 config: Config{ 89 HTTP: web.HTTP{ 90 Request: web.Request{URL: "http://127.0.0.1:38001"}, 91 }, 92 DoNodeStats: false, 93 DoClusterHealth: false, 94 DoClusterStats: false, 95 DoIndicesStats: false, 96 }, 97 }, 98 } 99 100 for name, test := range tests { 101 t.Run(name, func(t *testing.T) { 102 es := New() 103 es.Config = test.config 104 105 if test.wantFail { 106 assert.False(t, es.Init()) 107 } else { 108 assert.True(t, es.Init()) 109 } 110 }) 111 } 112 } 113 114 func TestElasticsearch_Check(t *testing.T) { 115 tests := map[string]struct { 116 prepare func(*testing.T) (es *Elasticsearch, cleanup func()) 117 wantFail bool 118 }{ 119 "valid data": {prepare: prepareElasticsearchValidData}, 120 "invalid data": {prepare: prepareElasticsearchInvalidData, wantFail: true}, 121 "404": {prepare: prepareElasticsearch404, wantFail: true}, 122 "connection refused": {prepare: prepareElasticsearchConnectionRefused, wantFail: true}, 123 } 124 125 for name, test := range tests { 126 t.Run(name, func(t *testing.T) { 127 es, cleanup := test.prepare(t) 128 defer cleanup() 129 130 if test.wantFail { 131 assert.False(t, es.Check()) 132 } else { 133 assert.True(t, es.Check()) 134 } 135 }) 136 } 137 } 138 139 func TestElasticsearch_Charts(t *testing.T) { 140 assert.NotNil(t, New().Charts()) 141 } 142 143 func TestElasticsearch_Cleanup(t *testing.T) { 144 assert.NotPanics(t, New().Cleanup) 145 } 146 147 func TestElasticsearch_Collect(t *testing.T) { 148 tests := map[string]struct { 149 prepare func() *Elasticsearch 150 wantCollected map[string]int64 151 wantCharts int 152 }{ 153 "v842: all nodes stats": { 154 prepare: func() *Elasticsearch { 155 es := New() 156 es.ClusterMode = true 157 es.DoNodeStats = true 158 es.DoClusterHealth = false 159 es.DoClusterStats = false 160 es.DoIndicesStats = false 161 return es 162 }, 163 wantCharts: len(nodeChartsTmpl) * 3, 164 wantCollected: map[string]int64{ 165 "node_Klg1CjgMTouentQcJlRGuA_breakers_accounting_tripped": 0, 166 "node_Klg1CjgMTouentQcJlRGuA_breakers_fielddata_tripped": 0, 167 "node_Klg1CjgMTouentQcJlRGuA_breakers_in_flight_requests_tripped": 0, 168 "node_Klg1CjgMTouentQcJlRGuA_breakers_model_inference_tripped": 0, 169 "node_Klg1CjgMTouentQcJlRGuA_breakers_parent_tripped": 0, 170 "node_Klg1CjgMTouentQcJlRGuA_breakers_request_tripped": 0, 171 "node_Klg1CjgMTouentQcJlRGuA_http_current_open": 75, 172 "node_Klg1CjgMTouentQcJlRGuA_indices_fielddata_evictions": 0, 173 "node_Klg1CjgMTouentQcJlRGuA_indices_fielddata_memory_size_in_bytes": 600, 174 "node_Klg1CjgMTouentQcJlRGuA_indices_flush_total": 35130, 175 "node_Klg1CjgMTouentQcJlRGuA_indices_flush_total_time_in_millis": 22204637, 176 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_current": 0, 177 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_time_in_millis": 1100012973, 178 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_total": 3667364815, 179 "node_Klg1CjgMTouentQcJlRGuA_indices_refresh_total": 7720800, 180 "node_Klg1CjgMTouentQcJlRGuA_indices_refresh_total_time_in_millis": 94297737, 181 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_current": 0, 182 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_time_in_millis": 21316723, 183 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_total": 42642621, 184 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_current": 0, 185 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_time_in_millis": 51262303, 186 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_total": 166820275, 187 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_count": 320, 188 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_doc_values_memory_in_bytes": 0, 189 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_fixed_bit_set_memory_in_bytes": 1904, 190 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_index_writer_memory_in_bytes": 262022568, 191 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_memory_in_bytes": 0, 192 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_norms_memory_in_bytes": 0, 193 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_points_memory_in_bytes": 0, 194 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_stored_fields_memory_in_bytes": 0, 195 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_term_vectors_memory_in_bytes": 0, 196 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_terms_memory_in_bytes": 0, 197 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_version_map_memory_in_bytes": 49200018, 198 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_operations": 352376, 199 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_size_in_bytes": 447695989, 200 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_uncommitted_operations": 352376, 201 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_uncommitted_size_in_bytes": 447695989, 202 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_count": 94, 203 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_total_capacity_in_bytes": 4654848, 204 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_used_in_bytes": 4654850, 205 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_count": 858, 206 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_total_capacity_in_bytes": 103114998135, 207 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_used_in_bytes": 103114998135, 208 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_old_collection_count": 0, 209 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_old_collection_time_in_millis": 0, 210 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_young_collection_count": 78652, 211 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_young_collection_time_in_millis": 6014274, 212 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_committed_in_bytes": 7864320000, 213 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_used_in_bytes": 5059735552, 214 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_used_percent": 64, 215 "node_Klg1CjgMTouentQcJlRGuA_process_max_file_descriptors": 1048576, 216 "node_Klg1CjgMTouentQcJlRGuA_process_open_file_descriptors": 1156, 217 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_analyze_queue": 0, 218 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_analyze_rejected": 0, 219 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_started_queue": 0, 220 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_started_rejected": 0, 221 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_store_queue": 0, 222 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_store_rejected": 0, 223 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_flush_queue": 0, 224 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_flush_rejected": 0, 225 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_force_merge_queue": 0, 226 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_force_merge_rejected": 0, 227 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_generic_queue": 0, 228 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_generic_rejected": 0, 229 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_get_queue": 0, 230 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_get_rejected": 0, 231 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_listener_queue": 0, 232 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_listener_rejected": 0, 233 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_management_queue": 0, 234 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_management_rejected": 0, 235 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_refresh_queue": 0, 236 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_refresh_rejected": 0, 237 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_queue": 0, 238 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_rejected": 0, 239 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_throttled_queue": 0, 240 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_throttled_rejected": 0, 241 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_snapshot_queue": 0, 242 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_snapshot_rejected": 0, 243 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_warmer_queue": 0, 244 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_warmer_rejected": 0, 245 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_write_queue": 0, 246 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_write_rejected": 0, 247 "node_Klg1CjgMTouentQcJlRGuA_transport_rx_count": 1300324276, 248 "node_Klg1CjgMTouentQcJlRGuA_transport_rx_size_in_bytes": 1789333458217, 249 "node_Klg1CjgMTouentQcJlRGuA_transport_tx_count": 1300324275, 250 "node_Klg1CjgMTouentQcJlRGuA_transport_tx_size_in_bytes": 2927487680282, 251 "node_k_AifYMWQTykjUq3pgE_-w_breakers_accounting_tripped": 0, 252 "node_k_AifYMWQTykjUq3pgE_-w_breakers_fielddata_tripped": 0, 253 "node_k_AifYMWQTykjUq3pgE_-w_breakers_in_flight_requests_tripped": 0, 254 "node_k_AifYMWQTykjUq3pgE_-w_breakers_model_inference_tripped": 0, 255 "node_k_AifYMWQTykjUq3pgE_-w_breakers_parent_tripped": 0, 256 "node_k_AifYMWQTykjUq3pgE_-w_breakers_request_tripped": 0, 257 "node_k_AifYMWQTykjUq3pgE_-w_http_current_open": 14, 258 "node_k_AifYMWQTykjUq3pgE_-w_indices_fielddata_evictions": 0, 259 "node_k_AifYMWQTykjUq3pgE_-w_indices_fielddata_memory_size_in_bytes": 0, 260 "node_k_AifYMWQTykjUq3pgE_-w_indices_flush_total": 0, 261 "node_k_AifYMWQTykjUq3pgE_-w_indices_flush_total_time_in_millis": 0, 262 "node_k_AifYMWQTykjUq3pgE_-w_indices_indexing_index_current": 0, 263 "node_k_AifYMWQTykjUq3pgE_-w_indices_indexing_index_time_in_millis": 0, 264 "node_k_AifYMWQTykjUq3pgE_-w_indices_indexing_index_total": 0, 265 "node_k_AifYMWQTykjUq3pgE_-w_indices_refresh_total": 0, 266 "node_k_AifYMWQTykjUq3pgE_-w_indices_refresh_total_time_in_millis": 0, 267 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_fetch_current": 0, 268 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_fetch_time_in_millis": 0, 269 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_fetch_total": 0, 270 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_query_current": 0, 271 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_query_time_in_millis": 0, 272 "node_k_AifYMWQTykjUq3pgE_-w_indices_search_query_total": 0, 273 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_count": 0, 274 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_doc_values_memory_in_bytes": 0, 275 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_fixed_bit_set_memory_in_bytes": 0, 276 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_index_writer_memory_in_bytes": 0, 277 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_memory_in_bytes": 0, 278 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_norms_memory_in_bytes": 0, 279 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_points_memory_in_bytes": 0, 280 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_stored_fields_memory_in_bytes": 0, 281 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_term_vectors_memory_in_bytes": 0, 282 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_terms_memory_in_bytes": 0, 283 "node_k_AifYMWQTykjUq3pgE_-w_indices_segments_version_map_memory_in_bytes": 0, 284 "node_k_AifYMWQTykjUq3pgE_-w_indices_translog_operations": 0, 285 "node_k_AifYMWQTykjUq3pgE_-w_indices_translog_size_in_bytes": 0, 286 "node_k_AifYMWQTykjUq3pgE_-w_indices_translog_uncommitted_operations": 0, 287 "node_k_AifYMWQTykjUq3pgE_-w_indices_translog_uncommitted_size_in_bytes": 0, 288 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_direct_count": 19, 289 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_direct_total_capacity_in_bytes": 2142214, 290 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_direct_used_in_bytes": 2142216, 291 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_mapped_count": 0, 292 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_mapped_total_capacity_in_bytes": 0, 293 "node_k_AifYMWQTykjUq3pgE_-w_jvm_buffer_pools_mapped_used_in_bytes": 0, 294 "node_k_AifYMWQTykjUq3pgE_-w_jvm_gc_collectors_old_collection_count": 0, 295 "node_k_AifYMWQTykjUq3pgE_-w_jvm_gc_collectors_old_collection_time_in_millis": 0, 296 "node_k_AifYMWQTykjUq3pgE_-w_jvm_gc_collectors_young_collection_count": 342994, 297 "node_k_AifYMWQTykjUq3pgE_-w_jvm_gc_collectors_young_collection_time_in_millis": 768917, 298 "node_k_AifYMWQTykjUq3pgE_-w_jvm_mem_heap_committed_in_bytes": 281018368, 299 "node_k_AifYMWQTykjUq3pgE_-w_jvm_mem_heap_used_in_bytes": 178362704, 300 "node_k_AifYMWQTykjUq3pgE_-w_jvm_mem_heap_used_percent": 63, 301 "node_k_AifYMWQTykjUq3pgE_-w_process_max_file_descriptors": 1048576, 302 "node_k_AifYMWQTykjUq3pgE_-w_process_open_file_descriptors": 557, 303 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_analyze_queue": 0, 304 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_analyze_rejected": 0, 305 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_fetch_shard_started_queue": 0, 306 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_fetch_shard_started_rejected": 0, 307 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_fetch_shard_store_queue": 0, 308 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_fetch_shard_store_rejected": 0, 309 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_flush_queue": 0, 310 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_flush_rejected": 0, 311 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_force_merge_queue": 0, 312 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_force_merge_rejected": 0, 313 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_generic_queue": 0, 314 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_generic_rejected": 0, 315 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_get_queue": 0, 316 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_get_rejected": 0, 317 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_listener_queue": 0, 318 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_listener_rejected": 0, 319 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_management_queue": 0, 320 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_management_rejected": 0, 321 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_refresh_queue": 0, 322 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_refresh_rejected": 0, 323 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_search_queue": 0, 324 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_search_rejected": 0, 325 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_search_throttled_queue": 0, 326 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_search_throttled_rejected": 0, 327 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_snapshot_queue": 0, 328 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_snapshot_rejected": 0, 329 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_warmer_queue": 0, 330 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_warmer_rejected": 0, 331 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_write_queue": 0, 332 "node_k_AifYMWQTykjUq3pgE_-w_thread_pool_write_rejected": 0, 333 "node_k_AifYMWQTykjUq3pgE_-w_transport_rx_count": 107632996, 334 "node_k_AifYMWQTykjUq3pgE_-w_transport_rx_size_in_bytes": 180620082152, 335 "node_k_AifYMWQTykjUq3pgE_-w_transport_tx_count": 107633007, 336 "node_k_AifYMWQTykjUq3pgE_-w_transport_tx_size_in_bytes": 420999501235, 337 "node_tk_U7GMCRkCG4FoOvusrng_breakers_accounting_tripped": 0, 338 "node_tk_U7GMCRkCG4FoOvusrng_breakers_fielddata_tripped": 0, 339 "node_tk_U7GMCRkCG4FoOvusrng_breakers_in_flight_requests_tripped": 0, 340 "node_tk_U7GMCRkCG4FoOvusrng_breakers_model_inference_tripped": 0, 341 "node_tk_U7GMCRkCG4FoOvusrng_breakers_parent_tripped": 93, 342 "node_tk_U7GMCRkCG4FoOvusrng_breakers_request_tripped": 1, 343 "node_tk_U7GMCRkCG4FoOvusrng_http_current_open": 84, 344 "node_tk_U7GMCRkCG4FoOvusrng_indices_fielddata_evictions": 0, 345 "node_tk_U7GMCRkCG4FoOvusrng_indices_fielddata_memory_size_in_bytes": 0, 346 "node_tk_U7GMCRkCG4FoOvusrng_indices_flush_total": 67895, 347 "node_tk_U7GMCRkCG4FoOvusrng_indices_flush_total_time_in_millis": 81917283, 348 "node_tk_U7GMCRkCG4FoOvusrng_indices_indexing_index_current": 0, 349 "node_tk_U7GMCRkCG4FoOvusrng_indices_indexing_index_time_in_millis": 1244633519, 350 "node_tk_U7GMCRkCG4FoOvusrng_indices_indexing_index_total": 6550378755, 351 "node_tk_U7GMCRkCG4FoOvusrng_indices_refresh_total": 12359783, 352 "node_tk_U7GMCRkCG4FoOvusrng_indices_refresh_total_time_in_millis": 300152615, 353 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_fetch_current": 0, 354 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_fetch_time_in_millis": 24517851, 355 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_fetch_total": 25105951, 356 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_query_current": 0, 357 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_query_time_in_millis": 158980385, 358 "node_tk_U7GMCRkCG4FoOvusrng_indices_search_query_total": 157912598, 359 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_count": 291, 360 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_doc_values_memory_in_bytes": 0, 361 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_fixed_bit_set_memory_in_bytes": 55672, 362 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_index_writer_memory_in_bytes": 57432664, 363 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_memory_in_bytes": 0, 364 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_norms_memory_in_bytes": 0, 365 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_points_memory_in_bytes": 0, 366 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_stored_fields_memory_in_bytes": 0, 367 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_term_vectors_memory_in_bytes": 0, 368 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_terms_memory_in_bytes": 0, 369 "node_tk_U7GMCRkCG4FoOvusrng_indices_segments_version_map_memory_in_bytes": 568, 370 "node_tk_U7GMCRkCG4FoOvusrng_indices_translog_operations": 1449698, 371 "node_tk_U7GMCRkCG4FoOvusrng_indices_translog_size_in_bytes": 1214204014, 372 "node_tk_U7GMCRkCG4FoOvusrng_indices_translog_uncommitted_operations": 1449698, 373 "node_tk_U7GMCRkCG4FoOvusrng_indices_translog_uncommitted_size_in_bytes": 1214204014, 374 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_direct_count": 90, 375 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_direct_total_capacity_in_bytes": 4571711, 376 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_direct_used_in_bytes": 4571713, 377 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_mapped_count": 831, 378 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_mapped_total_capacity_in_bytes": 99844219805, 379 "node_tk_U7GMCRkCG4FoOvusrng_jvm_buffer_pools_mapped_used_in_bytes": 99844219805, 380 "node_tk_U7GMCRkCG4FoOvusrng_jvm_gc_collectors_old_collection_count": 1, 381 "node_tk_U7GMCRkCG4FoOvusrng_jvm_gc_collectors_old_collection_time_in_millis": 796, 382 "node_tk_U7GMCRkCG4FoOvusrng_jvm_gc_collectors_young_collection_count": 139959, 383 "node_tk_U7GMCRkCG4FoOvusrng_jvm_gc_collectors_young_collection_time_in_millis": 3581668, 384 "node_tk_U7GMCRkCG4FoOvusrng_jvm_mem_heap_committed_in_bytes": 7864320000, 385 "node_tk_U7GMCRkCG4FoOvusrng_jvm_mem_heap_used_in_bytes": 1884124192, 386 "node_tk_U7GMCRkCG4FoOvusrng_jvm_mem_heap_used_percent": 23, 387 "node_tk_U7GMCRkCG4FoOvusrng_process_max_file_descriptors": 1048576, 388 "node_tk_U7GMCRkCG4FoOvusrng_process_open_file_descriptors": 1180, 389 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_analyze_queue": 0, 390 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_analyze_rejected": 0, 391 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_fetch_shard_started_queue": 0, 392 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_fetch_shard_started_rejected": 0, 393 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_fetch_shard_store_queue": 0, 394 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_fetch_shard_store_rejected": 0, 395 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_flush_queue": 0, 396 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_flush_rejected": 0, 397 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_force_merge_queue": 0, 398 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_force_merge_rejected": 0, 399 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_generic_queue": 0, 400 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_generic_rejected": 0, 401 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_get_queue": 0, 402 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_get_rejected": 0, 403 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_listener_queue": 0, 404 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_listener_rejected": 0, 405 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_management_queue": 0, 406 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_management_rejected": 0, 407 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_refresh_queue": 0, 408 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_refresh_rejected": 0, 409 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_search_queue": 0, 410 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_search_rejected": 0, 411 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_search_throttled_queue": 0, 412 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_search_throttled_rejected": 0, 413 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_snapshot_queue": 0, 414 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_snapshot_rejected": 0, 415 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_warmer_queue": 0, 416 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_warmer_rejected": 0, 417 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_write_queue": 0, 418 "node_tk_U7GMCRkCG4FoOvusrng_thread_pool_write_rejected": 0, 419 "node_tk_U7GMCRkCG4FoOvusrng_transport_rx_count": 2167879292, 420 "node_tk_U7GMCRkCG4FoOvusrng_transport_rx_size_in_bytes": 4905919297323, 421 "node_tk_U7GMCRkCG4FoOvusrng_transport_tx_count": 2167879293, 422 "node_tk_U7GMCRkCG4FoOvusrng_transport_tx_size_in_bytes": 2964638852652, 423 }, 424 }, 425 "v842: local node stats": { 426 prepare: func() *Elasticsearch { 427 es := New() 428 es.DoNodeStats = true 429 es.DoClusterHealth = false 430 es.DoClusterStats = false 431 es.DoIndicesStats = false 432 return es 433 }, 434 wantCharts: len(nodeChartsTmpl), 435 wantCollected: map[string]int64{ 436 "node_Klg1CjgMTouentQcJlRGuA_breakers_accounting_tripped": 0, 437 "node_Klg1CjgMTouentQcJlRGuA_breakers_fielddata_tripped": 0, 438 "node_Klg1CjgMTouentQcJlRGuA_breakers_in_flight_requests_tripped": 0, 439 "node_Klg1CjgMTouentQcJlRGuA_breakers_model_inference_tripped": 0, 440 "node_Klg1CjgMTouentQcJlRGuA_breakers_parent_tripped": 0, 441 "node_Klg1CjgMTouentQcJlRGuA_breakers_request_tripped": 0, 442 "node_Klg1CjgMTouentQcJlRGuA_http_current_open": 73, 443 "node_Klg1CjgMTouentQcJlRGuA_indices_fielddata_evictions": 0, 444 "node_Klg1CjgMTouentQcJlRGuA_indices_fielddata_memory_size_in_bytes": 600, 445 "node_Klg1CjgMTouentQcJlRGuA_indices_flush_total": 35134, 446 "node_Klg1CjgMTouentQcJlRGuA_indices_flush_total_time_in_millis": 22213090, 447 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_current": 1, 448 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_time_in_millis": 1100149051, 449 "node_Klg1CjgMTouentQcJlRGuA_indices_indexing_index_total": 3667793202, 450 "node_Klg1CjgMTouentQcJlRGuA_indices_refresh_total": 7721472, 451 "node_Klg1CjgMTouentQcJlRGuA_indices_refresh_total_time_in_millis": 94304142, 452 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_current": 0, 453 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_time_in_millis": 21316820, 454 "node_Klg1CjgMTouentQcJlRGuA_indices_search_fetch_total": 42645288, 455 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_current": 0, 456 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_time_in_millis": 51265805, 457 "node_Klg1CjgMTouentQcJlRGuA_indices_search_query_total": 166823028, 458 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_count": 307, 459 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_doc_values_memory_in_bytes": 0, 460 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_fixed_bit_set_memory_in_bytes": 2008, 461 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_index_writer_memory_in_bytes": 240481008, 462 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_memory_in_bytes": 0, 463 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_norms_memory_in_bytes": 0, 464 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_points_memory_in_bytes": 0, 465 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_stored_fields_memory_in_bytes": 0, 466 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_term_vectors_memory_in_bytes": 0, 467 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_terms_memory_in_bytes": 0, 468 "node_Klg1CjgMTouentQcJlRGuA_indices_segments_version_map_memory_in_bytes": 44339216, 469 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_operations": 362831, 470 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_size_in_bytes": 453491882, 471 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_uncommitted_operations": 362831, 472 "node_Klg1CjgMTouentQcJlRGuA_indices_translog_uncommitted_size_in_bytes": 453491882, 473 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_count": 94, 474 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_total_capacity_in_bytes": 4654848, 475 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_direct_used_in_bytes": 4654850, 476 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_count": 844, 477 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_total_capacity_in_bytes": 103411995802, 478 "node_Klg1CjgMTouentQcJlRGuA_jvm_buffer_pools_mapped_used_in_bytes": 103411995802, 479 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_old_collection_count": 0, 480 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_old_collection_time_in_millis": 0, 481 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_young_collection_count": 78661, 482 "node_Klg1CjgMTouentQcJlRGuA_jvm_gc_collectors_young_collection_time_in_millis": 6014901, 483 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_committed_in_bytes": 7864320000, 484 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_used_in_bytes": 4337402488, 485 "node_Klg1CjgMTouentQcJlRGuA_jvm_mem_heap_used_percent": 55, 486 "node_Klg1CjgMTouentQcJlRGuA_process_max_file_descriptors": 1048576, 487 "node_Klg1CjgMTouentQcJlRGuA_process_open_file_descriptors": 1149, 488 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_analyze_queue": 0, 489 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_analyze_rejected": 0, 490 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_started_queue": 0, 491 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_started_rejected": 0, 492 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_store_queue": 0, 493 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_fetch_shard_store_rejected": 0, 494 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_flush_queue": 0, 495 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_flush_rejected": 0, 496 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_force_merge_queue": 0, 497 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_force_merge_rejected": 0, 498 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_generic_queue": 0, 499 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_generic_rejected": 0, 500 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_get_queue": 0, 501 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_get_rejected": 0, 502 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_listener_queue": 0, 503 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_listener_rejected": 0, 504 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_management_queue": 0, 505 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_management_rejected": 0, 506 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_refresh_queue": 0, 507 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_refresh_rejected": 0, 508 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_queue": 0, 509 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_rejected": 0, 510 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_throttled_queue": 0, 511 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_search_throttled_rejected": 0, 512 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_snapshot_queue": 0, 513 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_snapshot_rejected": 0, 514 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_warmer_queue": 0, 515 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_warmer_rejected": 0, 516 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_write_queue": 0, 517 "node_Klg1CjgMTouentQcJlRGuA_thread_pool_write_rejected": 0, 518 "node_Klg1CjgMTouentQcJlRGuA_transport_rx_count": 1300468666, 519 "node_Klg1CjgMTouentQcJlRGuA_transport_rx_size_in_bytes": 1789647854011, 520 "node_Klg1CjgMTouentQcJlRGuA_transport_tx_count": 1300468665, 521 "node_Klg1CjgMTouentQcJlRGuA_transport_tx_size_in_bytes": 2927853534431, 522 }, 523 }, 524 "v842: only cluster_health": { 525 prepare: func() *Elasticsearch { 526 es := New() 527 es.DoNodeStats = false 528 es.DoClusterHealth = true 529 es.DoClusterStats = false 530 es.DoIndicesStats = false 531 return es 532 }, 533 wantCharts: len(clusterHealthChartsTmpl), 534 wantCollected: map[string]int64{ 535 "cluster_active_primary_shards": 97, 536 "cluster_active_shards": 194, 537 "cluster_active_shards_percent_as_number": 100, 538 "cluster_delayed_unassigned_shards": 0, 539 "cluster_initializing_shards": 0, 540 "cluster_number_of_data_nodes": 2, 541 "cluster_number_of_in_flight_fetch": 0, 542 "cluster_number_of_nodes": 3, 543 "cluster_number_of_pending_tasks": 0, 544 "cluster_relocating_shards": 0, 545 "cluster_status_green": 1, 546 "cluster_status_red": 0, 547 "cluster_status_yellow": 0, 548 "cluster_unassigned_shards": 0, 549 }, 550 }, 551 "v842: only cluster_stats": { 552 prepare: func() *Elasticsearch { 553 es := New() 554 es.DoNodeStats = false 555 es.DoClusterHealth = false 556 es.DoClusterStats = true 557 es.DoIndicesStats = false 558 return es 559 }, 560 wantCharts: len(clusterStatsChartsTmpl), 561 wantCollected: map[string]int64{ 562 "cluster_indices_count": 97, 563 "cluster_indices_docs_count": 402750703, 564 "cluster_indices_query_cache_hit_count": 96838726, 565 "cluster_indices_query_cache_miss_count": 587768226, 566 "cluster_indices_shards_primaries": 97, 567 "cluster_indices_shards_replication": 1, 568 "cluster_indices_shards_total": 194, 569 "cluster_indices_store_size_in_bytes": 380826136962, 570 "cluster_nodes_count_coordinating_only": 0, 571 "cluster_nodes_count_data": 0, 572 "cluster_nodes_count_data_cold": 0, 573 "cluster_nodes_count_data_content": 2, 574 "cluster_nodes_count_data_frozen": 0, 575 "cluster_nodes_count_data_hot": 2, 576 "cluster_nodes_count_data_warm": 0, 577 "cluster_nodes_count_ingest": 2, 578 "cluster_nodes_count_master": 3, 579 "cluster_nodes_count_ml": 0, 580 "cluster_nodes_count_remote_cluster_client": 2, 581 "cluster_nodes_count_total": 3, 582 "cluster_nodes_count_transform": 2, 583 "cluster_nodes_count_voting_only": 1, 584 }, 585 }, 586 "v842: only indices_stats": { 587 prepare: func() *Elasticsearch { 588 es := New() 589 es.DoNodeStats = false 590 es.DoClusterHealth = false 591 es.DoClusterStats = false 592 es.DoIndicesStats = true 593 return es 594 }, 595 wantCharts: len(nodeIndexChartsTmpl) * 3, 596 wantCollected: map[string]int64{ 597 "node_index_my-index-000001_stats_docs_count": 1, 598 "node_index_my-index-000001_stats_health_green": 0, 599 "node_index_my-index-000001_stats_health_red": 0, 600 "node_index_my-index-000001_stats_health_yellow": 1, 601 "node_index_my-index-000001_stats_shards_count": 1, 602 "node_index_my-index-000001_stats_store_size_in_bytes": 208, 603 "node_index_my-index-000002_stats_docs_count": 1, 604 "node_index_my-index-000002_stats_health_green": 0, 605 "node_index_my-index-000002_stats_health_red": 0, 606 "node_index_my-index-000002_stats_health_yellow": 1, 607 "node_index_my-index-000002_stats_shards_count": 1, 608 "node_index_my-index-000002_stats_store_size_in_bytes": 208, 609 "node_index_my-index-000003_stats_docs_count": 1, 610 "node_index_my-index-000003_stats_health_green": 0, 611 "node_index_my-index-000003_stats_health_red": 0, 612 "node_index_my-index-000003_stats_health_yellow": 1, 613 "node_index_my-index-000003_stats_shards_count": 1, 614 "node_index_my-index-000003_stats_store_size_in_bytes": 208, 615 }, 616 }, 617 } 618 619 for name, test := range tests { 620 t.Run(name, func(t *testing.T) { 621 es, cleanup := prepareElasticsearch(t, test.prepare) 622 defer cleanup() 623 624 var mx map[string]int64 625 for i := 0; i < 10; i++ { 626 mx = es.Collect() 627 } 628 629 //m := mx 630 //l := make([]string, 0) 631 //for k := range m { 632 // l = append(l, k) 633 //} 634 //sort.Strings(l) 635 //for _, value := range l { 636 // fmt.Println(fmt.Sprintf("\"%s\": %d,", value, m[value])) 637 //} 638 //return 639 640 assert.Equal(t, test.wantCollected, mx) 641 assert.Len(t, *es.Charts(), test.wantCharts) 642 ensureCollectedHasAllChartsDimsVarsIDs(t, es, mx) 643 }) 644 } 645 } 646 647 func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, es *Elasticsearch, collected map[string]int64) { 648 for _, chart := range *es.Charts() { 649 if chart.Obsolete { 650 continue 651 } 652 for _, dim := range chart.Dims { 653 _, ok := collected[dim.ID] 654 assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID) 655 } 656 for _, v := range chart.Vars { 657 _, ok := collected[v.ID] 658 assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID) 659 } 660 } 661 } 662 663 func prepareElasticsearch(t *testing.T, createES func() *Elasticsearch) (es *Elasticsearch, cleanup func()) { 664 t.Helper() 665 srv := prepareElasticsearchEndpoint() 666 667 es = createES() 668 es.URL = srv.URL 669 require.True(t, es.Init()) 670 671 return es, srv.Close 672 } 673 674 func prepareElasticsearchValidData(t *testing.T) (es *Elasticsearch, cleanup func()) { 675 return prepareElasticsearch(t, New) 676 } 677 678 func prepareElasticsearchInvalidData(t *testing.T) (*Elasticsearch, func()) { 679 t.Helper() 680 srv := httptest.NewServer(http.HandlerFunc( 681 func(w http.ResponseWriter, r *http.Request) { 682 _, _ = w.Write([]byte("hello and\n goodbye")) 683 })) 684 es := New() 685 es.URL = srv.URL 686 require.True(t, es.Init()) 687 688 return es, srv.Close 689 } 690 691 func prepareElasticsearch404(t *testing.T) (*Elasticsearch, func()) { 692 t.Helper() 693 srv := httptest.NewServer(http.HandlerFunc( 694 func(w http.ResponseWriter, r *http.Request) { 695 w.WriteHeader(http.StatusNotFound) 696 })) 697 es := New() 698 es.URL = srv.URL 699 require.True(t, es.Init()) 700 701 return es, srv.Close 702 } 703 704 func prepareElasticsearchConnectionRefused(t *testing.T) (*Elasticsearch, func()) { 705 t.Helper() 706 es := New() 707 es.URL = "http://127.0.0.1:38001" 708 require.True(t, es.Init()) 709 710 return es, func() {} 711 } 712 713 func prepareElasticsearchEndpoint() *httptest.Server { 714 return httptest.NewServer(http.HandlerFunc( 715 func(w http.ResponseWriter, r *http.Request) { 716 switch r.URL.Path { 717 case urlPathNodesStats: 718 _, _ = w.Write(v842NodesStats) 719 case urlPathLocalNodeStats: 720 _, _ = w.Write(v842NodesLocalStats) 721 case urlPathClusterHealth: 722 _, _ = w.Write(v842ClusterHealth) 723 case urlPathClusterStats: 724 _, _ = w.Write(v842ClusterStats) 725 case urlPathIndicesStats: 726 _, _ = w.Write(v842CatIndicesStats) 727 case "/": 728 _, _ = w.Write(v842Info) 729 default: 730 w.WriteHeader(http.StatusNotFound) 731 } 732 })) 733 }