|
| 1 | +import concurrent.futures |
| 2 | +import os |
| 3 | +import time |
| 4 | + |
| 5 | +from utils.http_matrix import run_curl_request |
| 6 | +from utils.test_service import FluentBitTestService |
| 7 | + |
| 8 | + |
| 9 | +class Service: |
| 10 | + """Run Fluent Bit with an exec input that curls the monitoring server.""" |
| 11 | + |
| 12 | + def __init__(self): |
| 13 | + config_dir = os.path.dirname(__file__) |
| 14 | + self.config_file = os.path.abspath( |
| 15 | + os.path.join(config_dir, "../config/internal_http_server_exec_deadlock.yaml") |
| 16 | + ) |
| 17 | + self.service = FluentBitTestService(self.config_file) |
| 18 | + |
| 19 | + def start(self): |
| 20 | + """Start Fluent Bit and record the monitoring base URL.""" |
| 21 | + try: |
| 22 | + self.service.start() |
| 23 | + except Exception: |
| 24 | + self.service.stop() |
| 25 | + raise |
| 26 | + |
| 27 | + self.flb = self.service.flb |
| 28 | + self.base_url = f"http://127.0.0.1:{self.flb.http_monitoring_port}" |
| 29 | + |
| 30 | + def stop(self): |
| 31 | + """Stop Fluent Bit and restore the test environment.""" |
| 32 | + self.service.stop() |
| 33 | + |
| 34 | + def request(self, path, *, method="GET", http_mode="http1.1"): |
| 35 | + """Issue a request against the internal monitoring server.""" |
| 36 | + return run_curl_request( |
| 37 | + f"{self.base_url}{path}", |
| 38 | + method=method, |
| 39 | + http_mode=http_mode, |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +def test_http_server_stays_responsive_after_exec_self_request(): |
| 44 | + """The monitoring server must not share the blocked exec collector loop.""" |
| 45 | + service = Service() |
| 46 | + service.start() |
| 47 | + |
| 48 | + try: |
| 49 | + result = service.request("/api/v1/uptime") |
| 50 | + assert result["status_code"] == 200 |
| 51 | + assert "uptime_sec" in result["body"] |
| 52 | + |
| 53 | + time.sleep(2) |
| 54 | + |
| 55 | + endpoints = [ |
| 56 | + ("/api/v1/uptime", "uptime_sec"), |
| 57 | + ("/api/v1/health", "ok"), |
| 58 | + ("/api/v1/metrics", "output"), |
| 59 | + ("/api/v1/metrics/prometheus", "fluentbit_uptime"), |
| 60 | + ("/api/v1/storage", "chunks"), |
| 61 | + ("/api/v2/metrics", "fluentbit_uptime"), |
| 62 | + ("/api/v2/metrics/prometheus", "fluentbit_uptime"), |
| 63 | + ] |
| 64 | + |
| 65 | + for path, pattern in endpoints: |
| 66 | + result = service.service.wait_for_condition( |
| 67 | + lambda: ( |
| 68 | + response |
| 69 | + if response["status_code"] == 200 and pattern in response["body"] |
| 70 | + else None |
| 71 | + ) if (response := service.request(path)) else None, |
| 72 | + timeout=10, |
| 73 | + interval=0.5, |
| 74 | + description=f"internal endpoint {path}", |
| 75 | + ) |
| 76 | + assert result["status_code"] == 200 |
| 77 | + assert pattern in result["body"] |
| 78 | + |
| 79 | + def fetch(endpoint): |
| 80 | + path, pattern = endpoint |
| 81 | + response = service.request(path) |
| 82 | + assert response["status_code"] == 200 |
| 83 | + assert pattern in response["body"] |
| 84 | + |
| 85 | + with concurrent.futures.ThreadPoolExecutor(max_workers=7) as executor: |
| 86 | + futures = [executor.submit(fetch, endpoint) for endpoint in endpoints * 4] |
| 87 | + for future in futures: |
| 88 | + future.result() |
| 89 | + finally: |
| 90 | + service.stop() |
0 commit comments