-
Notifications
You must be signed in to change notification settings - Fork 2k
utils: fix SIMD boundary for JSON string encoding #12285
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c323e9e
utils: Fix the boundary length of SIMD offloading
cosmo0920 b39bc81
tests: internal: Add a test case for the boundary of SIMD op length
cosmo0920 8a5b638
tests: runtime: Add a test case for long payloads
cosmo0920 3710135
tests: integration: Add an integration test case for SIMD boundaries
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
29 changes: 29 additions & 0 deletions
29
tests/integration/scenarios/out_loki/config/out_loki_long_unicode.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,29 @@ | ||
| service: | ||
| flush: 1 | ||
| grace: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
| parsers_file: ${LOKI_PARSERS_FILE} | ||
|
|
||
| pipeline: | ||
| inputs: | ||
| - name: tail | ||
| tag: loki.integration | ||
| path: ${LOKI_INPUT_PATH} | ||
| parser: loki-integration-json | ||
| read_from_head: true | ||
| refresh_interval: 1 | ||
| buffer_chunk_size: 256k | ||
| buffer_max_size: 20m | ||
| mem_buf_limit: 512m | ||
|
|
||
| outputs: | ||
| - name: loki | ||
| match: loki.integration | ||
| host: 127.0.0.1 | ||
| port: ${TEST_SUITE_HTTP_PORT} | ||
| line_format: json | ||
| labels: job=integration-test | ||
| remove_keys: seq | ||
| retry_limit: no_limits |
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,3 @@ | ||
| [PARSER] | ||
| Name loki-integration-json | ||
| Format json |
133 changes: 133 additions & 0 deletions
133
tests/integration/scenarios/out_loki/tests/test_out_loki_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,133 @@ | ||
| import json | ||
|
cosmo0920 marked this conversation as resolved.
|
||
| import os | ||
| from pathlib import Path | ||
| import tempfile | ||
|
|
||
| import requests | ||
|
|
||
| from server.http_server import data_storage, http_server_run | ||
| from utils.memory_check import memory_check_enabled | ||
| from utils.test_service import FluentBitTestService | ||
|
|
||
|
|
||
| MESSAGE_SIZE = 40 * 1024 | ||
| RECORD_COUNT = 200 | ||
|
|
||
|
|
||
| def create_message(sequence): | ||
| prefix = f"<TEST {'®' * ((sequence % 15) + 1)}>" | ||
| suffix = "</TEST>" | ||
| token = f"{sequence}," | ||
| remaining = MESSAGE_SIZE - len(prefix.encode("utf-8")) - len(suffix) | ||
| repetitions = remaining // len(token) | ||
| padding = remaining - repetitions * len(token) | ||
|
|
||
| return prefix + token * repetitions + "-" * padding + suffix | ||
|
|
||
|
|
||
| def write_input(path): | ||
| expected_messages = [] | ||
|
|
||
| with path.open("w", encoding="utf-8") as input_file: | ||
| for sequence in range(RECORD_COUNT): | ||
| message = create_message(sequence) | ||
| expected_messages.append(message) | ||
| json.dump({"seq": sequence, "msg": message}, input_file, ensure_ascii=False) | ||
| input_file.write("\n") | ||
|
|
||
| return expected_messages | ||
|
|
||
|
|
||
| def count_loki_values(): | ||
| count = 0 | ||
|
|
||
| for payload in data_storage["payloads"]: | ||
| if not isinstance(payload, dict): | ||
| continue | ||
|
|
||
| for stream in payload.get("streams", []): | ||
| count += len(stream.get("values", [])) | ||
|
|
||
| return count | ||
|
|
||
|
|
||
| def collect_loki_records(): | ||
| records = [] | ||
|
|
||
| for payload in data_storage["payloads"]: | ||
| assert isinstance(payload, dict) | ||
|
|
||
| for stream in payload.get("streams", []): | ||
| for value in stream.get("values", []): | ||
| records.append(json.loads(value[1])) | ||
|
|
||
| return records | ||
|
|
||
|
|
||
| class Service: | ||
| def __init__(self, input_path): | ||
| test_directory = Path(__file__).resolve().parent | ||
| config_directory = test_directory.parent / "config" | ||
| self.service = FluentBitTestService( | ||
| str(config_directory / "out_loki_long_unicode.yaml"), | ||
| data_storage=data_storage, | ||
| data_keys=["payloads", "requests"], | ||
| extra_env={ | ||
| "LOKI_INPUT_PATH": str(input_path), | ||
| "LOKI_PARSERS_FILE": str(config_directory / "parsers.conf"), | ||
| }, | ||
| pre_start=self._start_receiver, | ||
| post_stop=self._stop_receiver, | ||
| ) | ||
|
|
||
| def _start_receiver(self, service): | ||
| http_server_run(service.test_suite_http_port) | ||
| self.service.wait_for_http_endpoint( | ||
| f"http://127.0.0.1:{service.test_suite_http_port}/ping", | ||
| timeout=10, | ||
| interval=0.5, | ||
| ) | ||
|
|
||
| def _stop_receiver(self, service): | ||
| try: | ||
| requests.post( | ||
| f"http://127.0.0.1:{service.test_suite_http_port}/shutdown", | ||
| timeout=2, | ||
| ) | ||
| except requests.RequestException: | ||
| pass | ||
|
|
||
| def start(self): | ||
| self.service.start() | ||
|
|
||
| def stop(self): | ||
| self.service.stop() | ||
|
|
||
| def wait_for_records(self): | ||
| timeout = 60 if memory_check_enabled() else 20 | ||
|
|
||
| self.service.wait_for_condition( | ||
| lambda: count_loki_values() >= RECORD_COUNT, | ||
| timeout=timeout, | ||
| interval=0.5, | ||
| description=f"{RECORD_COUNT} Loki values", | ||
| ) | ||
|
|
||
|
|
||
| def test_out_loki_preserves_long_unicode_json_strings(): | ||
| with tempfile.TemporaryDirectory(prefix="flb-out-loki-it-") as temp_directory: | ||
| input_path = Path(temp_directory) / "input.log" | ||
| expected_messages = write_input(input_path) | ||
| service = Service(input_path) | ||
|
|
||
| try: | ||
| service.start() | ||
| service.wait_for_records() | ||
| finally: | ||
| service.stop() | ||
|
|
||
| records = collect_loki_records() | ||
|
|
||
| assert len(records) == RECORD_COUNT | ||
| assert all(set(record) == {"msg"} for record in records) | ||
| assert sorted(record["msg"] for record in records) == sorted(expected_messages) | ||
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
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.