at 25.11-pre 4.0 kB view raw
1import ./make-test-python.nix ( 2 { lib, pkgs, ... }: 3 4 let 5 # Define an example Quickwit index schema, 6 # and some `exampleDocs` below, to test if ingesting 7 # and querying works as expected. 8 index_yaml = '' 9 version: 0.7 10 index_id: example_server_logs 11 doc_mapping: 12 mode: dynamic 13 field_mappings: 14 - name: datetime 15 type: datetime 16 fast: true 17 input_formats: 18 - iso8601 19 output_format: iso8601 20 fast_precision: seconds 21 fast: true 22 - name: git 23 type: text 24 tokenizer: raw 25 - name: hostname 26 type: text 27 tokenizer: raw 28 - name: level 29 type: text 30 tokenizer: raw 31 - name: message 32 type: text 33 - name: location 34 type: text 35 - name: source 36 type: text 37 timestamp_field: datetime 38 39 search_settings: 40 default_search_fields: [message] 41 42 indexing_settings: 43 commit_timeout_secs: 10 44 ''; 45 46 exampleDocs = '' 47 {"datetime":"2024-05-03T02:36:41.017674444Z","git":"e6e1f087ce12065e44ed3b87b50784e6f9bcc2f9","hostname":"machine-1","level":"Info","message":"Processing request done","location":"path/to/server.c:6442:32","source":""} 48 {"datetime":"2024-05-04T02:36:41.017674444Z","git":"e6e1f087ce12065e44ed3b87b50784e6f9bcc2f9","hostname":"machine-1","level":"Info","message":"Got exception processing request: HTTP 404","location":"path/to/server.c:6444:32","source":""} 49 {"datetime":"2024-05-05T02:36:41.017674444Z","git":"e6e1f087ce12065e44ed3b87b50784e6f9bcc2f9","hostname":"machine-1","level":"Info","message":"Got exception processing request: HTTP 404","location":"path/to/server.c:6444:32","source":""} 50 {"datetime":"2024-05-06T02:36:41.017674444Z","git":"e6e1f087ce12065e44ed3b87b50784e6f9bcc2f9","hostname":"machine-2","level":"Info","message":"Got exception processing request: HTTP 404","location":"path/to/server.c:6444:32","source":""} 51 ''; 52 in 53 { 54 name = "quickwit"; 55 meta.maintainers = [ pkgs.lib.maintainers.happysalada ]; 56 57 nodes = { 58 quickwit = 59 { config, pkgs, ... }: 60 { 61 services.quickwit.enable = true; 62 }; 63 }; 64 65 testScript = '' 66 quickwit.wait_for_unit("quickwit") 67 quickwit.wait_for_open_port(7280) 68 quickwit.wait_for_open_port(7281) 69 70 quickwit.wait_until_succeeds( 71 "journalctl -o cat -u quickwit.service | grep 'version: ${pkgs.quickwit.version}'" 72 ) 73 74 quickwit.wait_until_succeeds( 75 "journalctl -o cat -u quickwit.service | grep 'transitioned to ready state'" 76 ) 77 78 with subtest("verify UI installed"): 79 machine.succeed("curl -sSf http://127.0.0.1:7280/ui/") 80 81 with subtest("injest and query data"): 82 import json 83 84 # Test CLI ingestion 85 print(machine.succeed('${pkgs.quickwit}/bin/quickwit index create --index-config ${pkgs.writeText "index.yaml" index_yaml}')) 86 # Important to use `--wait`, otherwise the queries below race with index processing. 87 print(machine.succeed('${pkgs.quickwit}/bin/quickwit index ingest --index example_server_logs --input-path ${pkgs.writeText "exampleDocs.json" exampleDocs} --wait')) 88 89 # Test CLI query 90 cli_query_output = machine.succeed('${pkgs.quickwit}/bin/quickwit index search --index example_server_logs --query "exception"') 91 print(cli_query_output) 92 93 # Assert query result is as expected. 94 num_hits = len(json.loads(cli_query_output)["hits"]) 95 assert num_hits == 3, f"cli_query_output contains unexpected number of results: {num_hits}" 96 97 # Test API query 98 api_query_output = machine.succeed('curl --fail http://127.0.0.1:7280/api/v1/example_server_logs/search?query=exception') 99 print(api_query_output) 100 101 quickwit.log(quickwit.succeed( 102 "systemd-analyze security quickwit.service | grep -v ''" 103 )) 104 ''; 105 } 106)