generated from dynatrace-oss/template-project
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from dynatrace-oss/32-enable-to-define-bulk-at…
…tribute-extraction-rules 32 enable to define bulk attribute extraction rules
- Loading branch information
Showing
4 changed files
with
122 additions
and
16 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
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
59 changes: 59 additions & 0 deletions
59
tests/unit/log/processing/rules/test_attribute_mapping_from_top_level_json.py
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,59 @@ | ||
import unittest | ||
|
||
from log.processing import LogProcessingRule | ||
|
||
|
||
class TestAttributeMappingFromJsonProcessingRule(unittest.TestCase): | ||
input_message = { | ||
'test_attribute_1': 'test_value_1', | ||
'test_attribute_2': 'test_value_2', | ||
'test_attribute_3': 'test_value_3', | ||
'test_attribute_4': 'test_value_4', | ||
} | ||
|
||
def test_include_parameter(self): | ||
processing_rule = create_log_processing_rule({ | ||
'include': ['test_attribute_1', 'test_attribute_3'], | ||
'postfix': '_mapped', | ||
'prefix': 'my_' | ||
}) | ||
|
||
self.assertEqual(processing_rule.get_extracted_log_attributes(self.input_message), { | ||
'my_test_attribute_1_mapped': 'test_value_1', | ||
'my_test_attribute_3_mapped': 'test_value_3' | ||
}) | ||
|
||
def test_exclude_parameter(self): | ||
processing_rule = create_log_processing_rule({ | ||
'exclude': ['test_attribute_1', 'test_attribute_3'], | ||
'postfix': '_mapped', | ||
'prefix': 'my_' | ||
}) | ||
|
||
self.assertEqual(processing_rule.get_extracted_log_attributes(self.input_message), { | ||
'my_test_attribute_2_mapped': 'test_value_2', | ||
'my_test_attribute_4_mapped': 'test_value_4' | ||
}) | ||
|
||
def test_rule_validation(self): | ||
with self.assertRaises(ValueError): | ||
create_log_processing_rule( | ||
{ | ||
'include': ['test_attribute_1', 'test_attribute_3'], | ||
'exclude': ['test_attribute_2', 'test_attribute_4'], | ||
'postfix': '_mapped', | ||
'prefix': 'my_' | ||
} | ||
) | ||
|
||
|
||
def create_log_processing_rule(attribute_mapping): | ||
return LogProcessingRule( | ||
'name', 'source', 'pattern', 'json', | ||
attribute_mapping_from_json_keys=attribute_mapping, | ||
skip_header_lines=0 | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |