| 1 | package exporter |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/prometheus/client_golang/prometheus" |
| 10 | ) |
| 11 | |
| 12 | func testModuleMetrics(t *testing.T, addr string, wantedMetrics []string) { |
| 13 | t.Helper() |
| 14 | |
| 15 | for _, inclModules := range []bool{true, false} { |
| 16 | t.Run(fmt.Sprintf("inclModulesMetrics:%t", inclModules), func(t *testing.T) { |
| 17 | e, _ := NewRedisExporter(addr, Options{Namespace: "test", InclModulesMetrics: inclModules}) |
| 18 | |
| 19 | chM := make(chan prometheus.Metric) |
| 20 | go func() { |
| 21 | e.Collect(chM) |
| 22 | close(chM) |
| 23 | }() |
| 24 | |
| 25 | found := map[string]bool{} |
| 26 | for m := range chM { |
| 27 | desc := m.Desc().String() |
| 28 | for _, want := range wantedMetrics { |
| 29 | if strings.Contains(desc, want) { |
| 30 | found[want] = true |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | for _, want := range wantedMetrics { |
| 36 | if inclModules && !found[want] { |
| 37 | t.Errorf("%s was *not* found in Redis Modules metrics but expected", want) |
| 38 | } |
| 39 | if !inclModules && found[want] { |
| 40 | t.Errorf("%s was *found* in Redis Modules metrics but *not* expected", want) |
| 41 | } |
| 42 | } |
| 43 | }) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestModulesv80(t *testing.T) { |
| 48 | if os.Getenv("TEST_REDIS8_URI") == "" { |
| 49 | t.Skipf("TEST_REDIS8_URI not set - skipping") |
| 50 | } |
| 51 | |
| 52 | testModuleMetrics(t, os.Getenv("TEST_REDIS8_URI"), []string{ |
| 53 | "module_info", |
| 54 | "search_number_of_indexes", |
| 55 | "search_number_of_active_indexes", |
| 56 | "search_number_of_active_indexes_running_queries", |
| 57 | "search_number_of_active_indexes_indexing", |
| 58 | "search_total_active_write_threads", |
| 59 | "search_indexing_time_ms_total", |
| 60 | "search_total_num_docs_in_indexes", |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | func TestModulesValkey(t *testing.T) { |
| 65 | if os.Getenv("TEST_VALKEY8_BUNDLE_URI") == "" { |
| 66 | t.Skipf("TEST_VALKEY8_BUNDLE_URI not set - skipping") |
| 67 | } |
| 68 | |
| 69 | testModuleMetrics(t, os.Getenv("TEST_VALKEY8_BUNDLE_URI"), []string{ |
| 70 | "module_info", |
| 71 | "search_number_of_indexes", |
| 72 | "bf_bloom_total_memory_bytes", |
| 73 | "bf_bloom_num_objects", |
| 74 | "bf_bloom_num_filters_across_objects", |
| 75 | "bf_bloom_num_items_across_objects", |
| 76 | "bf_bloom_capacity_across_objects", |
| 77 | "json_total_memory_bytes", |
| 78 | "json_num_documents", |
| 79 | "search_used_memory_bytes", |
| 80 | "search_number_of_attributes", |
| 81 | "search_total_indexed_documents", |
| 82 | "search_query_queue_size", |
| 83 | "search_writer_queue_size", |
| 84 | "search_string_interning_store_size", |
| 85 | "search_vector_externing_hash_extern_errors", |
| 86 | "search_vector_externing_num_lru_entries", |
| 87 | "bf_bloom_defrag_hits_total", |
| 88 | "bf_bloom_defrag_misses_total", |
| 89 | "search_worker_pool_suspend_count", |
| 90 | "search_writer_resumed_count", |
| 91 | "search_reader_resumed_count", |
| 92 | "search_writer_suspension_expired_count", |
| 93 | "search_rdb_load_success_count", |
| 94 | "search_rdb_load_failure_count", |
| 95 | "search_rdb_save_success_count", |
| 96 | "search_rdb_save_failure_count", |
| 97 | "search_successful_requests_count", |
| 98 | "search_failure_requests_count", |
| 99 | "search_hybrid_requests_count", |
| 100 | "search_inline_filtering_requests_count", |
| 101 | "search_hnsw_add_exceptions_count", |
| 102 | "search_hnsw_remove_exceptions_count", |
| 103 | "search_hnsw_modify_exceptions_count", |
| 104 | "search_hnsw_search_exceptions_count", |
| 105 | "search_hnsw_create_exceptions_count", |
| 106 | "search_vector_externing_entry_count", |
| 107 | "search_vector_externing_generated_value_count", |
| 108 | "search_vector_externing_lru_promote_count", |
| 109 | "search_vector_externing_deferred_entry_count", |
| 110 | }) |
| 111 | } |