-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle k8s-prepended log messages in Popey job scan results (#1468)
* Handle k8s-prepended log messages in Popey job scan results * simplify clean_up_k8s_logs_from_job_output
- Loading branch information
Robert Szefler
authored
Jun 21, 2024
1 parent
57be0b5
commit 3d72712
Showing
2 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,41 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from playbooks.robusta_playbooks.popeye import clean_up_k8s_logs_from_job_output | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input,expected_output", | ||
[ | ||
("", ""), | ||
("{}", "{}"), | ||
("{}\nextra text", "{}\nextra text"), | ||
('{"popeye": []}', '{"popeye": []}'), | ||
('{"popeye": []}\n{}', '{"popeye": []}\n{}'), | ||
('{"invalid_json": {[{', '{"invalid_json": {[{'), | ||
(" \t\n", ""), | ||
('\nlog line 1\n\nweird log\n{"x": 3}', '{"x": 3}'), | ||
( | ||
"xxx Waited for 3.14159s due to client-side throttling, not priority and fairness, blah\n" | ||
"\n" | ||
'{"data": []}', | ||
'{"data": []}', | ||
), | ||
( | ||
"xxx Waited for 21.37s - request: some text here\n" "\n" '{"x": 123}', | ||
'{"x": 123}', | ||
), | ||
( | ||
"xxx Waited for 666s due to client-side throttling, not priority and fairness, blah\n" | ||
"\n" | ||
"aaa Waited for 777s - request: some text here\n" | ||
"\n" | ||
"bad logging message\n" | ||
'{"p": "q"}', | ||
'{"p": "q"}', | ||
), | ||
], | ||
) | ||
def test_clean_up_k8s_logs_from_job_output(input, expected_output): | ||
assert clean_up_k8s_logs_from_job_output(input) == expected_output |