-
Notifications
You must be signed in to change notification settings - Fork 2k
in_storage_backlog: Fix persistent chunks issues without matching routes on hot reloading #12239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edsiper
merged 4 commits into
master
from
cosmo0920-fix-persistent-chunks-without-matching-routes-issue
Aug 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f98be25
in_storage_backlog: Handle stale chunks as another error code
cosmo0920 de69778
tests: runtime: Add a regression test case for stale chunks on backlog
cosmo0920 72cbf2f
tests: integration: Add test cases for storage backlog
cosmo0920 7430986
agents: Update descriptions about memory safety
cosmo0920 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/integration/scenarios/in_storage_backlog/config/reload_with_stale_route.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| service: | ||
| flush: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| hot_reload: on | ||
| hot_reload.timeout: 10 | ||
| storage.path: ${STORAGE_BACKLOG_PATH} | ||
|
|
||
| pipeline: | ||
| inputs: | ||
| - name: tail | ||
| tag: live | ||
| path: ${STORAGE_BACKLOG_MISSING_PATH} | ||
| storage.type: filesystem | ||
|
|
||
| outputs: | ||
| - name: null | ||
| match: "*" |
19 changes: 19 additions & 0 deletions
19
tests/integration/scenarios/in_storage_backlog/config/reload_without_stale_route.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| service: | ||
| flush: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| hot_reload: on | ||
| hot_reload.timeout: 10 | ||
| storage.path: ${STORAGE_BACKLOG_PATH} | ||
|
|
||
| pipeline: | ||
| inputs: | ||
| - name: tail | ||
| tag: live | ||
| path: ${STORAGE_BACKLOG_MISSING_PATH} | ||
| storage.type: filesystem | ||
|
|
||
| outputs: | ||
| - name: null | ||
| match: live |
18 changes: 18 additions & 0 deletions
18
tests/integration/scenarios/in_storage_backlog/config/seed_unroutable_chunk.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| service: | ||
| flush: 1 | ||
| grace: 0 | ||
| storage.path: ${STORAGE_BACKLOG_PATH} | ||
|
|
||
| pipeline: | ||
| inputs: | ||
| - name: dummy | ||
| tag: stale | ||
| samples: 1 | ||
| storage.type: filesystem | ||
|
|
||
| outputs: | ||
| - name: http | ||
| match: stale | ||
| host: 127.0.0.1 | ||
| port: 9 | ||
| retry_limit: no_limits |
174 changes: 174 additions & 0 deletions
174
tests/integration/scenarios/in_storage_backlog/tests/test_in_storage_backlog_001.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| import os | ||
| from pathlib import Path | ||
| import signal | ||
| import shutil | ||
| import subprocess | ||
| import time | ||
|
|
||
| import pytest | ||
|
|
||
| from utils.fluent_bit_manager import FluentBitManager | ||
|
|
||
|
|
||
| CONFIG_DIR = Path(__file__).resolve().parent.parent / "config" | ||
| SEED_CONFIG = CONFIG_DIR / "seed_unroutable_chunk.yaml" | ||
| RELOAD_WITHOUT_ROUTE = CONFIG_DIR / "reload_without_stale_route.yaml" | ||
| RELOAD_WITH_ROUTE = CONFIG_DIR / "reload_with_stale_route.yaml" | ||
| KEEP_ON_DISK_MESSAGE = "no matching route for dummy.0/" | ||
| REGISTER_MESSAGE = "register dummy.0/" | ||
| QUEUE_MESSAGE = "queueing dummy.0:" | ||
|
|
||
|
|
||
| def wait_for_persisted_chunk(storage_path, process, log_path, timeout=10): | ||
| deadline = time.time() + timeout | ||
|
|
||
| while time.time() < deadline: | ||
| chunks = list(storage_path.glob("*/*.flb")) | ||
| if chunks and chunks[0].stat().st_size > 0: | ||
| return chunks[0] | ||
|
|
||
| return_code = process.poll() | ||
| if return_code is not None: | ||
| if log_path.exists(): | ||
| log = log_path.read_text(encoding="utf-8", errors="replace") | ||
| else: | ||
| log = "seed log was not created" | ||
| raise RuntimeError( | ||
| f"seed Fluent Bit exited with code {return_code} before persisting a chunk:\n{log}" | ||
| ) | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| raise TimeoutError("timed out waiting for the seed filesystem chunk") | ||
|
|
||
|
|
||
| def wait_for_log_occurrences(log_path, text, expected, timeout=10): | ||
| deadline = time.time() + timeout | ||
|
|
||
| while time.time() < deadline: | ||
| if log_path.exists(): | ||
| log = log_path.read_text(encoding="utf-8", errors="replace") | ||
| if log.count(text) >= expected: | ||
| return | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| raise TimeoutError(f"timed out waiting for {expected} occurrences of {text!r}") | ||
|
|
||
|
|
||
| def wait_for_path_removal(path, timeout=10): | ||
| deadline = time.time() + timeout | ||
|
|
||
| while time.time() < deadline: | ||
| if not path.exists(): | ||
| return | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| raise TimeoutError(f"timed out waiting for {path} to be removed") | ||
|
|
||
|
|
||
| def seed_persisted_chunk(storage_path, seed_log_path): | ||
| binary_path = FluentBitManager(str(SEED_CONFIG)).binary_absolute_path | ||
| seed_process = subprocess.Popen( | ||
| [binary_path, "-c", str(SEED_CONFIG), "-l", str(seed_log_path)], | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.STDOUT, | ||
| env=os.environ.copy(), | ||
| ) | ||
|
|
||
| try: | ||
| return wait_for_persisted_chunk(storage_path, seed_process, seed_log_path) | ||
| finally: | ||
| if seed_process.poll() is None: | ||
| seed_process.kill() | ||
| seed_process.wait(timeout=10) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def seeded_chunk(tmp_path, monkeypatch): | ||
| storage_path = tmp_path / "storage" | ||
| storage_path.mkdir() | ||
| seed_log_path = tmp_path / "seed.log" | ||
| missing_path = tmp_path / "does-not-exist.log" | ||
|
|
||
| monkeypatch.setenv("STORAGE_BACKLOG_PATH", str(storage_path)) | ||
| monkeypatch.setenv("STORAGE_BACKLOG_MISSING_PATH", str(missing_path)) | ||
|
|
||
| persisted_chunk = seed_persisted_chunk(storage_path, seed_log_path) | ||
| assert persisted_chunk.exists() | ||
|
|
||
| return persisted_chunk | ||
|
|
||
|
|
||
| def test_routable_persisted_chunk_is_replayed_on_startup(seeded_chunk): | ||
| manager = FluentBitManager(str(RELOAD_WITH_ROUTE)) | ||
|
|
||
| try: | ||
| manager.start() | ||
|
cosmo0920 marked this conversation as resolved.
|
||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), REGISTER_MESSAGE, expected=1 | ||
| ) | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), QUEUE_MESSAGE, expected=1 | ||
| ) | ||
| wait_for_path_removal(seeded_chunk) | ||
| finally: | ||
| manager.stop() | ||
|
|
||
| assert not seeded_chunk.exists() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not hasattr(signal, "SIGHUP"), reason="SIGHUP is unavailable") | ||
| def test_unroutable_chunk_stays_on_disk_across_hot_reload(seeded_chunk): | ||
| manager = FluentBitManager(str(RELOAD_WITHOUT_ROUTE)) | ||
|
|
||
| try: | ||
| manager.start() | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), KEEP_ON_DISK_MESSAGE, expected=1 | ||
| ) | ||
| assert seeded_chunk.exists() | ||
|
|
||
| manager.send_sighup() | ||
| manager.wait_for_hot_reload_count(1, timeout=20) | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), KEEP_ON_DISK_MESSAGE, expected=2, timeout=20 | ||
| ) | ||
| assert seeded_chunk.exists() | ||
| finally: | ||
| manager.stop() | ||
|
|
||
| assert seeded_chunk.exists() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not hasattr(signal, "SIGHUP"), reason="SIGHUP is unavailable") | ||
| def test_restored_route_recovers_chunk_during_hot_reload(tmp_path, seeded_chunk): | ||
| runtime_config = tmp_path / "fluent-bit.yaml" | ||
| shutil.copyfile(RELOAD_WITHOUT_ROUTE, runtime_config) | ||
| manager = FluentBitManager(str(runtime_config)) | ||
|
|
||
| try: | ||
| manager.start() | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), KEEP_ON_DISK_MESSAGE, expected=1 | ||
| ) | ||
| assert seeded_chunk.exists() | ||
|
|
||
| pending_config = tmp_path / "fluent-bit.yaml.tmp" | ||
| shutil.copyfile(RELOAD_WITH_ROUTE, pending_config) | ||
| os.replace(pending_config, runtime_config) | ||
|
|
||
| manager.send_sighup() | ||
| manager.wait_for_hot_reload_count(1, timeout=20) | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), REGISTER_MESSAGE, expected=1, timeout=20 | ||
| ) | ||
| wait_for_log_occurrences( | ||
| Path(manager.log_file), QUEUE_MESSAGE, expected=1, timeout=20 | ||
| ) | ||
| wait_for_path_removal(seeded_chunk, timeout=20) | ||
| finally: | ||
| manager.stop() | ||
|
|
||
| assert not seeded_chunk.exists() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.